Add Brave LLM Context endpoint as opt-in web search mode

Brave's /res/v1/llm/context returns pre-extracted text chunks
optimized for LLM consumption instead of URLs + short snippets.
Enable with BRAVE_LLM_CONTEXT=1 env var; same API key and pricing.

- Add _search_llm_context() and _normalize_llm_context() to brave_search.py
- Wire opt-in flag through _search_web() in last30days.py
- Update module docstring (free tier eliminated Feb 2026)
- Add 23 tests covering normalization, filtering, date parsing
This commit is contained in:
Jeffrey Sperling
2026-03-11 17:46:34 -07:00
parent 4fde52459d
commit 859f6c5829
3 changed files with 318 additions and 3 deletions
+3 -1
View File
@@ -632,8 +632,10 @@ def _search_web(
topic, from_date, to_date, config["PARALLEL_API_KEY"], depth=depth,
)
elif backend == "brave":
use_llm_ctx = os.environ.get("BRAVE_LLM_CONTEXT", "").strip() == "1"
raw_results = brave_search.search_web(
topic, from_date, to_date, config["BRAVE_API_KEY"], depth=depth,
topic, from_date, to_date, config["BRAVE_API_KEY"],
depth=depth, use_llm_context=use_llm_ctx,
)
elif backend == "openrouter":
raw_results = openrouter_search.search_web(