Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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:
|