Nottybro commited on
Commit
6e2cade
·
verified ·
1 Parent(s): 11aa43c

web search: switch to jina s.jina.ai — no rate limit issues

Browse files
Files changed (1) hide show
  1. acra.py +18 -5
acra.py CHANGED
@@ -34,16 +34,29 @@ def adaptive_chunk(text, max_tok=512):
34
  return chunks or [text]
35
 
36
  def web_search(query: str, max_results: int = 5) -> List[dict]:
37
- """Real web search using DuckDuckGoreturns actual news and live results."""
 
38
  try:
39
- with DDGS() as ddgs:
40
- results = list(ddgs.text(query, max_results=max_results))
41
- return [{"title": r.get("title",""), "snippet": r.get("body",""),
42
- "url": r.get("href","")} for r in results if r.get("body")]
 
 
 
 
 
 
 
 
 
 
 
43
  except Exception as e:
44
  print(f"Web search error: {e}")
45
  return []
46
 
 
47
  def decompose(query):
48
  r = client.models.generate_content(model=GEN_MODEL,
49
  contents=f"Decompose into 2-4 simpler sub-queries. Numbered list only.\n\nQuery: {query}")
 
34
  return chunks or [text]
35
 
36
  def web_search(query: str, max_results: int = 5) -> List[dict]:
37
+ """Web search via Jina AI no API key, works from cloud, LLM-ready output."""
38
+ import httpx
39
  try:
40
+ url = f"https://s.jina.ai/?q={httpx.URL(query)}"
41
+ r = httpx.get(url,
42
+ headers={"Accept": "application/json",
43
+ "X-Respond-With": "no-content"},
44
+ timeout=15.0)
45
+ if r.status_code != 200:
46
+ print(f"Jina search returned {r.status_code}")
47
+ return []
48
+ data = r.json()
49
+ results = data.get("data", [])
50
+ return [{"title": item.get("title", ""),
51
+ "snippet": item.get("description", item.get("content",""))[:500],
52
+ "url": item.get("url", "")}
53
+ for item in results[:max_results]
54
+ if item.get("description") or item.get("content")]
55
  except Exception as e:
56
  print(f"Web search error: {e}")
57
  return []
58
 
59
+
60
  def decompose(query):
61
  r = client.models.generate_content(model=GEN_MODEL,
62
  contents=f"Decompose into 2-4 simpler sub-queries. Numbered list only.\n\nQuery: {query}")