Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,30 +16,31 @@ class BasicAgent:
|
|
| 16 |
self.app_id = os.getenv("WOLFARM_APP_ID")
|
| 17 |
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
-
|
|
|
|
| 20 |
if not self.app_id:
|
| 21 |
-
print("
|
| 22 |
-
return "Error
|
| 23 |
|
| 24 |
-
try
|
| 25 |
url = "http://api.wolframalpha.com/v1/result"
|
| 26 |
params = {
|
| 27 |
-
"i"
|
| 28 |
-
"appid"
|
| 29 |
}
|
| 30 |
-
response = requests.get(url, params
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if response.status_code == 200:
|
| 33 |
-
print("WolfarmAlpha Response Affirmative.")
|
| 34 |
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
else :
|
| 37 |
-
print(f"WolfarmAlpha Status Update {response.status_code}")
|
| 38 |
-
return f"Couldn't retreive a response from WolfarmAlpha. Status{response.status_code} "
|
| 39 |
-
|
| 40 |
except Exception as e:
|
| 41 |
-
|
| 42 |
-
return f"Error Retrieveing WolfarmAlpha API: {e}"
|
| 43 |
|
| 44 |
|
| 45 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 16 |
self.app_id = os.getenv("WOLFARM_APP_ID")
|
| 17 |
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 20 |
+
|
| 21 |
if not self.app_id:
|
| 22 |
+
print("❌ WolframAlpha App ID not found.")
|
| 23 |
+
return "Error: WolframAlpha App ID not set."
|
| 24 |
|
| 25 |
+
try:
|
| 26 |
url = "http://api.wolframalpha.com/v1/result"
|
| 27 |
params = {
|
| 28 |
+
"i": question,
|
| 29 |
+
"appid": self.app_id
|
| 30 |
}
|
| 31 |
+
response = requests.get(url, params=params, timeout=10)
|
| 32 |
+
|
| 33 |
+
print(f"🔁 Request URL: {response.url}")
|
| 34 |
|
| 35 |
if response.status_code == 200:
|
|
|
|
| 36 |
return response.text
|
| 37 |
+
elif response.status_code == 501:
|
| 38 |
+
return "Error: WolframAlpha API endpoint doesn't support this query type (501)."
|
| 39 |
+
else:
|
| 40 |
+
return f"Couldn't retrieve a response from WolframAlpha. Status {response.status_code}"
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
except Exception as e:
|
| 43 |
+
return f"Exception occurred: {str(e)}"
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|