naman1102 commited on
Commit
46aadea
·
1 Parent(s): cc0b0be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -5
app.py CHANGED
@@ -38,17 +38,56 @@ JINA_API_KEY = os.getenv("JINA_API_KEY")
38
 
39
  def jina_search_tool(query: str, api_key: str, max_results: int = 5) -> List[str]:
40
  """Return *max_results* clean markdown snippets for *query* using s.jina.ai."""
 
 
 
 
41
  endpoint = f"https://s.jina.ai/{query.replace(' ', '+')}"
 
 
42
  headers = {
43
  "Authorization": f"Bearer {api_key}",
44
  "Accept": "application/json",
45
  "User-Agent": "Mozilla/5.0",
46
  }
47
- resp = requests.get(endpoint, headers=headers, timeout=15)
48
- if resp.status_code != 200:
49
- raise RuntimeError(f"Jina search failed with status {resp.status_code}: {resp.text[:200]}")
50
- data = resp.json()
51
- return [item.get("content", "") for item in data.get("results", [])][:max_results]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # -------------------------
54
  # Logging helper
 
38
 
39
  def jina_search_tool(query: str, api_key: str, max_results: int = 5) -> List[str]:
40
  """Return *max_results* clean markdown snippets for *query* using s.jina.ai."""
41
+ print("\n=== Jina Search Debug ===")
42
+ print(f"Query: {query}")
43
+ print(f"Max Results: {max_results}")
44
+
45
  endpoint = f"https://s.jina.ai/{query.replace(' ', '+')}"
46
+ print(f"Endpoint: {endpoint}")
47
+
48
  headers = {
49
  "Authorization": f"Bearer {api_key}",
50
  "Accept": "application/json",
51
  "User-Agent": "Mozilla/5.0",
52
  }
53
+ print("Headers:", {k: v[:10] + "..." if k == "Authorization" else v for k, v in headers.items()})
54
+
55
+ try:
56
+ print("\nSending request to Jina API...")
57
+ resp = requests.get(endpoint, headers=headers, timeout=15)
58
+ print(f"Response Status: {resp.status_code}")
59
+
60
+ if resp.status_code != 200:
61
+ print(f"Error Response: {resp.text[:500]}")
62
+ raise RuntimeError(f"Jina search failed with status {resp.status_code}: {resp.text[:200]}")
63
+
64
+ data = resp.json()
65
+ print("\nResponse Data Structure:")
66
+ print(f"Keys in response: {list(data.keys())}")
67
+ print(f"Number of results: {len(data.get('results', []))}")
68
+
69
+ results = [item.get("content", "") for item in data.get("results", [])][:max_results]
70
+ print(f"\nRetrieved {len(results)} results")
71
+
72
+ if not results:
73
+ print("WARNING: No results found in the response")
74
+ print("Full response data:", json.dumps(data, indent=2)[:1000])
75
+
76
+ return results
77
+
78
+ except requests.exceptions.Timeout:
79
+ print("ERROR: Request timed out after 15 seconds")
80
+ raise
81
+ except requests.exceptions.RequestException as e:
82
+ print(f"ERROR: Network/Request error: {str(e)}")
83
+ raise
84
+ except json.JSONDecodeError as e:
85
+ print(f"ERROR: Failed to parse JSON response: {str(e)}")
86
+ print(f"Raw response: {resp.text[:500]}")
87
+ raise
88
+ except Exception as e:
89
+ print(f"ERROR: Unexpected error: {str(e)}")
90
+ raise
91
 
92
  # -------------------------
93
  # Logging helper