trippyrocks commited on
Commit
9513289
·
verified ·
1 Parent(s): db3dd09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -49
app.py CHANGED
@@ -18,56 +18,20 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
21
- def duckduckgo_search(query: str) -> str:
22
- """
23
- A simple search tool that queries DuckDuckGo's Instant Answer API and returns a result snippet.
24
-
25
- Args:
26
- query (str): The search query string.
27
-
28
- Returns:
29
- str: A summary from DuckDuckGo or an error message.
30
- """
31
- try:
32
- url = "https://api.duckduckgo.com/"
33
- params = {
34
- "q": query,
35
- "format": "json",
36
- "no_html": 1,
37
- "skip_disambig": 1,
38
- }
39
- response = requests.get(url, params=params)
40
- if response.status_code != 200:
41
- return f"Error: Received status code {response.status_code} from DuckDuckGo."
42
-
43
  data = response.json()
44
-
45
- # Use the AbstractText if available as a summary.
46
- abstract_text = data.get("AbstractText", "")
47
- if abstract_text:
48
- return f"Result: {abstract_text}"
49
-
50
- # If no abstract is provided, try returning the first related topic's text.
51
- related_topics = data.get("RelatedTopics", [])
52
- for topic in related_topics:
53
- # Some topics might be nested; check both levels.
54
- if isinstance(topic, dict):
55
- if "Text" in topic:
56
- return f"Result: {topic['Text']}"
57
- if "Topics" in topic:
58
- for subtopic in topic["Topics"]:
59
- if "Text" in subtopic:
60
- return f"Result: {subtopic['Text']}"
61
-
62
- return "No results found."
63
-
64
- except Exception as e:
65
- return f"Error performing search: {str(e)}"
66
-
67
- # Example usage:
68
- if __name__ == "__main__":
69
- search_query = "Python programming"
70
- print(duckduckgo_search(search_query))
71
 
72
  @tool
73
  def get_current_time_in_timezone(timezone: str) -> str:
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ def get_capital(state):
22
+ import requests
23
+ api_url = f"http://api.duckduckgo.com/"
24
+ response = requests.get(api_url)
25
+ if response.status_code == 200:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  data = response.json()
27
+ return data.get("capital", "No capital information available")
28
+ else:
29
+ return "Error: Unable to fetch capital data."
30
+
31
+ # Execute the function and prepare the final answer
32
+ result = get_weather("New York")
33
+ final_answer = f"The current weather in New York is: {result}"
34
+ print(final_answer)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  @tool
37
  def get_current_time_in_timezone(timezone: str) -> str: