Nav772 commited on
Commit
7bd952b
·
verified ·
1 Parent(s): 7cf7a4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
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
- print(f"Agent received question (first 50 chars): {question[:50]}...")
 
20
  if not self.app_id:
21
- print("WolfarmAlpha ID not found.")
22
- return "Error : WolfarmAlpha ID not set."
23
 
24
- try :
25
  url = "http://api.wolframalpha.com/v1/result"
26
  params = {
27
- "i" : question,
28
- "appid" : self.app_id
29
  }
30
- response = requests.get(url, params = params, timeout=10)
 
 
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
- print(f"Execption calling WolfarmAlpha: {e}")
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):