Spaces:
Sleeping
Sleeping
Gianluca Tessitore commited on
Commit ·
ea66e30
1
Parent(s): bfff34c
fix some issues
Browse files
app.py
CHANGED
|
@@ -82,7 +82,12 @@ def wikipedia_search(query: str) -> str:
|
|
| 82 |
"srlimit": 3, "srprop": "snippet",
|
| 83 |
}
|
| 84 |
resp = requests.get(search_url, params=params, timeout=10)
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
results = data.get("query", {}).get("search", [])
|
| 87 |
if not results:
|
| 88 |
return "No Wikipedia results found."
|
|
@@ -92,9 +97,12 @@ def wikipedia_search(query: str) -> str:
|
|
| 92 |
resp2 = requests.get(
|
| 93 |
f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded2}", timeout=10
|
| 94 |
)
|
| 95 |
-
if resp2.status_code == 200:
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
return "\n".join(r.get("snippet", "") for r in results)
|
| 99 |
except Exception as e:
|
| 100 |
return f"Wikipedia error: {e}"
|
|
@@ -232,7 +240,8 @@ Important rules:
|
|
| 232 |
- Numbers: exact format as requested (integer, decimal, etc.).
|
| 233 |
- Names: exact spelling as they appear in authoritative sources.
|
| 234 |
- Lists: comma-separated values unless another format is specified.
|
| 235 |
-
- Always use a tool to verify facts rather than relying on memory.
|
|
|
|
| 236 |
|
| 237 |
MODEL = "moonshotai/Kimi-K2.5:cheapest"
|
| 238 |
|
|
@@ -357,7 +366,7 @@ Important rules:
|
|
| 357 |
{"role": "user", "content": user_content},
|
| 358 |
]
|
| 359 |
|
| 360 |
-
for iteration in range(
|
| 361 |
t_llm = time.time()
|
| 362 |
response = None
|
| 363 |
for attempt in range(3):
|
|
@@ -595,7 +604,7 @@ if __name__ == "__main__":
|
|
| 595 |
|
| 596 |
if space_host_startup:
|
| 597 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 598 |
-
print(f" Runtime URL should be: https://{space_host_startup}
|
| 599 |
else:
|
| 600 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
| 601 |
|
|
|
|
| 82 |
"srlimit": 3, "srprop": "snippet",
|
| 83 |
}
|
| 84 |
resp = requests.get(search_url, params=params, timeout=10)
|
| 85 |
+
if not resp.content:
|
| 86 |
+
return "No Wikipedia results found."
|
| 87 |
+
try:
|
| 88 |
+
data = resp.json()
|
| 89 |
+
except Exception:
|
| 90 |
+
return "No Wikipedia results found."
|
| 91 |
results = data.get("query", {}).get("search", [])
|
| 92 |
if not results:
|
| 93 |
return "No Wikipedia results found."
|
|
|
|
| 97 |
resp2 = requests.get(
|
| 98 |
f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded2}", timeout=10
|
| 99 |
)
|
| 100 |
+
if resp2.status_code == 200 and resp2.content:
|
| 101 |
+
try:
|
| 102 |
+
d = resp2.json()
|
| 103 |
+
return f"{d.get('title', '')}: {d.get('extract', '')}"
|
| 104 |
+
except Exception:
|
| 105 |
+
pass
|
| 106 |
return "\n".join(r.get("snippet", "") for r in results)
|
| 107 |
except Exception as e:
|
| 108 |
return f"Wikipedia error: {e}"
|
|
|
|
| 240 |
- Numbers: exact format as requested (integer, decimal, etc.).
|
| 241 |
- Names: exact spelling as they appear in authoritative sources.
|
| 242 |
- Lists: comma-separated values unless another format is specified.
|
| 243 |
+
- Always use a tool to verify facts rather than relying on memory.
|
| 244 |
+
- YouTube URLs cannot be visited directly; use web_search to find information about YouTube video content instead."""
|
| 245 |
|
| 246 |
MODEL = "moonshotai/Kimi-K2.5:cheapest"
|
| 247 |
|
|
|
|
| 366 |
{"role": "user", "content": user_content},
|
| 367 |
]
|
| 368 |
|
| 369 |
+
for iteration in range(20):
|
| 370 |
t_llm = time.time()
|
| 371 |
response = None
|
| 372 |
for attempt in range(3):
|
|
|
|
| 604 |
|
| 605 |
if space_host_startup:
|
| 606 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
| 607 |
+
print(f" Runtime URL should be: https://{space_host_startup}")
|
| 608 |
else:
|
| 609 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
| 610 |
|