Update app.py
Browse files
app.py
CHANGED
|
@@ -33,8 +33,22 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
|
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -55,7 +69,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
# Create a new custom tool
|
| 37 |
+
@tool
|
| 38 |
+
def get_country_info(country: str) -> str:
|
| 39 |
+
"""Fetches basic information about a country using REST Countries API.
|
| 40 |
+
Args:
|
| 41 |
+
country: Name of the country (e.g., 'Italy').
|
| 42 |
+
"""
|
| 43 |
+
try:
|
| 44 |
+
response = requests.get(f"https://restcountries.com/v3.1/name/{country}")
|
| 45 |
+
data = response.json()[0]
|
| 46 |
+
return f"{data['name']['common']} is in {data['region']}. Capital: {data['capital'][0]}. Population: {data['population']}."
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Failed to fetch country info: {str(e)}"
|
| 49 |
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
+
duckduckgo_tool = DuckDuckGoSearchTool()
|
| 52 |
|
| 53 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 54 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 69 |
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
| 72 |
+
tools=[final_answer, duckduckgo_tool, get_country_info, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 73 |
max_steps=6,
|
| 74 |
verbosity_level=1,
|
| 75 |
grammar=None,
|