Update app.py
#663
by krishnanshus04 - opened
app.py
CHANGED
|
@@ -9,14 +9,61 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +102,11 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_weather(city: str) -> str:
|
| 13 |
+
"""Get the current weather of the city.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
city: Name of the city (e.g., 'Delhi')
|
|
|
|
| 16 |
"""
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
url = f"https://wttr.in/{city}?format=3"
|
| 20 |
+
response = requests.get(url)
|
| 21 |
+
return response.text.strip()
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"Error while fetching weather: {str(e)}"
|
| 24 |
+
|
| 25 |
+
def web_search(query: str) -> str:
|
| 26 |
+
"""Search information on the internet.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
query: Search query
|
| 30 |
+
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
url = f"https://api.duckduckgo.com/"
|
| 35 |
+
|
| 36 |
+
params = {
|
| 37 |
+
"q":query,
|
| 38 |
+
"format":"json",
|
| 39 |
+
"no_html":1,
|
| 40 |
+
"skip_disambig":1
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
response = requests.get(url, params = params, timeout=5)
|
| 44 |
+
data = response.json();
|
| 45 |
+
|
| 46 |
+
if data.get("AbstractText"):
|
| 47 |
+
return data["AbstractText"]
|
| 48 |
+
|
| 49 |
+
related_topics = data.get("RelatedTopics", [])
|
| 50 |
+
|
| 51 |
+
if related_topics:
|
| 52 |
+
result = []
|
| 53 |
+
|
| 54 |
+
for topics in related_topics[:5]:
|
| 55 |
+
if isinstance(topic, dict) and topic.get("Text"):
|
| 56 |
+
result.append(topic["Text"])
|
| 57 |
+
|
| 58 |
+
if result:
|
| 59 |
+
return "\n".join(result)
|
| 60 |
+
|
| 61 |
+
return f"No relavent result found for this '{query}'."
|
| 62 |
+
|
| 63 |
+
except Exception as e:
|
| 64 |
+
return f"Error performing web search: {str(e)}"
|
| 65 |
+
|
| 66 |
+
|
| 67 |
|
| 68 |
@tool
|
| 69 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 102 |
|
| 103 |
agent = CodeAgent(
|
| 104 |
model=model,
|
| 105 |
+
tools=[
|
| 106 |
+
final_answer,
|
| 107 |
+
get_weather,
|
| 108 |
+
web_search
|
| 109 |
+
], ## add your tools here (don't remove final answer)
|
| 110 |
max_steps=6,
|
| 111 |
verbosity_level=1,
|
| 112 |
grammar=None,
|