web search: switch to jina s.jina.ai — no rate limit issues
Browse files
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 |
-
"""
|
|
|
|
| 38 |
try:
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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}")
|