danielkorat commited on
Commit
44fad3a
·
verified ·
1 Parent(s): 9fabd03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -73,7 +73,6 @@ def wolfram_alpha(query: str)-> str:
73
  url = f"http://api.wolframalpha.com/v2/query?appid={api_key}&input={formatted_query}&output=json&format=plaintext"
74
  for key in WOLFRAM_RESPONSE_KEYS:
75
  url += f"&includepodid={key}"
76
- print(f"\nWolfram URL:\n{url}")
77
 
78
  try:
79
  response = requests.get(url)
@@ -83,20 +82,15 @@ def wolfram_alpha(query: str)-> str:
83
  print(f"{query_result=}")
84
 
85
  if query_result is None or query_result.get("error", False): # Check if there's an error in the response
86
- print("Error 1")
87
  return f"Error: {query_result['error'].get('msg', 'Unable to fetch Wolfram response.')}"
88
 
89
- if (pods := query_result.get("pods")) is None:
90
- print("Error 2")
91
- print(f"{pods}=")
92
- return "Wolfram did not provide an answer."
93
 
94
- print(f"{pods[0]}=")
95
  return "; ".join(res.get("plaintext") for res in pods[0].get("subpods"))
96
 
97
- except Exception as err: #requests.exceptions.RequestException as e:
98
- print(Exception, err)
99
- # return f"Error fetching Wolfram response: {str(e)}"
100
 
101
 
102
  class GoogleSearchTool(Tool):
@@ -464,7 +458,7 @@ class GradioUI:
464
  session_state = gr.State({}) # Initialize empty state for each session
465
  stored_messages = gr.State([])
466
  chatbot = gr.Chatbot(
467
- label="open-Deep-Research",
468
  type="messages",
469
  avatar_images=(
470
  None,
 
73
  url = f"http://api.wolframalpha.com/v2/query?appid={api_key}&input={formatted_query}&output=json&format=plaintext"
74
  for key in WOLFRAM_RESPONSE_KEYS:
75
  url += f"&includepodid={key}"
 
76
 
77
  try:
78
  response = requests.get(url)
 
82
  print(f"{query_result=}")
83
 
84
  if query_result is None or query_result.get("error", False): # Check if there's an error in the response
 
85
  return f"Error: {query_result['error'].get('msg', 'Unable to fetch Wolfram response.')}"
86
 
87
+ if (pods := query_result.get("pods")) is None: # Check if the response is missing an answer
88
+ return "Wolfram did not provide an answer (no result pods)."
 
 
89
 
 
90
  return "; ".join(res.get("plaintext") for res in pods[0].get("subpods"))
91
 
92
+ except requests.exceptions.RequestException as e:
93
+ print(requests.exceptions.RequestException, e)
 
94
 
95
 
96
  class GoogleSearchTool(Tool):
 
458
  session_state = gr.State({}) # Initialize empty state for each session
459
  stored_messages = gr.State([])
460
  chatbot = gr.Chatbot(
461
+ label="AI Agent",
462
  type="messages",
463
  avatar_images=(
464
  None,