Update app.py
Browse files
app.py
CHANGED
|
@@ -23,11 +23,10 @@ def my_custom_tool(arg1:int, arg2:int)-> str: #it's import to specify the return
|
|
| 23 |
return f"the result is {a}"
|
| 24 |
|
| 25 |
@tool
|
| 26 |
-
def
|
| 27 |
-
"""
|
| 28 |
Args:
|
| 29 |
-
|
| 30 |
-
as string for the specified time zone retrieved from get_current_time_in_timezone.
|
| 31 |
"""
|
| 32 |
try:
|
| 33 |
# Format date as YYYY-MM-DD (API only supports "today" or "random")
|
|
@@ -39,10 +38,31 @@ def todays_useless_fact(result: str) -> str:
|
|
| 39 |
|
| 40 |
|
| 41 |
# API doesn't actually support querying by date, so we just show today's
|
| 42 |
-
response =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
if response.status_code == 200:
|
| 44 |
data = response.json()
|
| 45 |
-
return f"{result}. Here's a useless
|
| 46 |
else:
|
| 47 |
return f"Failed to fetch fact: {response.status_code}"
|
| 48 |
except Exception as e:
|
|
@@ -103,7 +123,7 @@ agent = CodeAgent(
|
|
| 103 |
final_answer,
|
| 104 |
get_current_time_in_timezone,
|
| 105 |
image_generation_tool,
|
| 106 |
-
|
| 107 |
], ## add your tools here (don't remove final answer)
|
| 108 |
max_steps=6,
|
| 109 |
verbosity_level=1,
|
|
|
|
| 23 |
return f"the result is {a}"
|
| 24 |
|
| 25 |
@tool
|
| 26 |
+
def hello_world(country: str) -> str:
|
| 27 |
+
"""Greets the given country.
|
| 28 |
Args:
|
| 29 |
+
country: A string including the name of the given country.
|
|
|
|
| 30 |
"""
|
| 31 |
try:
|
| 32 |
# Format date as YYYY-MM-DD (API only supports "today" or "random")
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# API doesn't actually support querying by date, so we just show today's
|
| 41 |
+
response = f"Hello to {country}"
|
| 42 |
+
return response
|
| 43 |
+
except Exception as e:
|
| 44 |
+
return f"Error occurred: {str(e)}"
|
| 45 |
+
|
| 46 |
+
@tool
|
| 47 |
+
def get_joke(result: str) -> str:
|
| 48 |
+
"""Fetches a joke from the Chuck Norris API.
|
| 49 |
+
Args:
|
| 50 |
+
result: A string including the date/time output string from get_current_time_in_timezone.
|
| 51 |
+
"""
|
| 52 |
+
try:
|
| 53 |
+
# Format date as YYYY-MM-DD (API only supports "today" or "random")
|
| 54 |
+
#if isinstance(input_time, str):
|
| 55 |
+
# try:
|
| 56 |
+
# input_time = datetime.fromisoformat(input_time)
|
| 57 |
+
# except ValueError:
|
| 58 |
+
# return "Invalid datetime format. Please use ISO format: YYYY-MM-DDTHH:MM:SS"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# API doesn't actually support querying by date, so we just show today's
|
| 62 |
+
response = requests.get("https://api.chucknorris.io/jokes/random")
|
| 63 |
if response.status_code == 200:
|
| 64 |
data = response.json()
|
| 65 |
+
return f"{result}. Here's a useless joke: {data.get('value', 'No joke found.')}"
|
| 66 |
else:
|
| 67 |
return f"Failed to fetch fact: {response.status_code}"
|
| 68 |
except Exception as e:
|
|
|
|
| 123 |
final_answer,
|
| 124 |
get_current_time_in_timezone,
|
| 125 |
image_generation_tool,
|
| 126 |
+
hello_world, get_joke # Include this!
|
| 127 |
], ## add your tools here (don't remove final answer)
|
| 128 |
max_steps=6,
|
| 129 |
verbosity_level=1,
|