danielkorat commited on
Commit
ef0061c
·
verified ·
1 Parent(s): 731773e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -59,9 +59,9 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
59
  @tool
60
  def wolfram_alpha(query: str)-> str:
61
  """
62
- A wrapper arounf Wolfram Alpha, nn intelligent tool that answers questions about Math, Geography,
63
- Demographics, American Sports and stadiums, Music, Science, Technology, Culture, Society
64
- and Everyday Life. Input should be a search query."
65
  Args:
66
  query: The search query.
67
  Returns:
@@ -78,19 +78,18 @@ def wolfram_alpha(query: str)-> str:
78
  response = requests.get(url)
79
  response.raise_for_status() # Raise an exception for HTTP errors
80
 
81
- data = response.json()
82
-
83
- if data.get("queryresult").get("error"): # Check if there's an error in the response
84
- return f"Error: {data['queryresult']['error'].get('msg', 'Unable to fetch Wolfram response.')}"
 
85
 
86
- response = ""
87
- for result in data.get("queryresult").get("pods")[0].get("subpods"):
88
- response += f"{result.get('plaintext')}; "
89
- return response
90
 
91
  except requests.exceptions.RequestException as e:
92
  return f"Error fetching Wolfram response: {str(e)}"
93
 
 
94
  class GoogleSearchTool(Tool):
95
  name = "web_search"
96
  description = """Performs a google web search for your query then returns a string of the top search results."""
 
59
  @tool
60
  def wolfram_alpha(query: str)-> str:
61
  """
62
+ A wrapper around Wolfram Alpha, an intelligent tool that answers questions about Math, Geography,
63
+ Demographics, American Sports and american sports venues, Music, Science, Technology, Culture, Society
64
+ and Everyday Life. Input should be a textual search query."
65
  Args:
66
  query: The search query.
67
  Returns:
 
78
  response = requests.get(url)
79
  response.raise_for_status() # Raise an exception for HTTP errors
80
 
81
+ if query_result := response.json().get("queryresult") is None or query_result.get("error"): # Check if there's an error in the response
82
+ return f"Error: {query_result['error'].get('msg', 'Unable to fetch Wolfram response.')}"
83
+
84
+ if pods := query_result.get("pods") is None:
85
+ return "Wolfram did not provide an answer."
86
 
87
+ return "; ".join(res.get("plaintext") for res in pods[0].get("subpods"))
 
 
 
88
 
89
  except requests.exceptions.RequestException as e:
90
  return f"Error fetching Wolfram response: {str(e)}"
91
 
92
+
93
  class GoogleSearchTool(Tool):
94
  name = "web_search"
95
  description = """Performs a google web search for your query then returns a string of the top search results."""