Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded tool get_random_fact
app.py
CHANGED
|
@@ -18,6 +18,26 @@ 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 |
@tool
|
| 22 |
def get_joke() -> str:
|
| 23 |
"""
|
|
@@ -83,7 +103,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 83 |
|
| 84 |
agent = CodeAgent(
|
| 85 |
model=model,
|
| 86 |
-
tools=[get_joke, final_answer], ## add your tools here (don't remove final answer)
|
| 87 |
max_steps=6,
|
| 88 |
verbosity_level=1,
|
| 89 |
grammar=None,
|
|
|
|
| 18 |
"""
|
| 19 |
return "What magic will you build ?"
|
| 20 |
|
| 21 |
+
@tool
|
| 22 |
+
def get_random_fact() -> str:
|
| 23 |
+
"""
|
| 24 |
+
Fetches a random fact from the "uselessfacts.jsph.pl" API.
|
| 25 |
+
Returns:
|
| 26 |
+
str: A string containing the random fact or an error message if the request fails.
|
| 27 |
+
"""
|
| 28 |
+
url = "https://uselessfacts.jsph.pl/random.json?language=en"
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
response = requests.get(url)
|
| 32 |
+
response.raise_for_status()
|
| 33 |
+
|
| 34 |
+
data = response.json()
|
| 35 |
+
|
| 36 |
+
return f"Random Fact: {data['text']}"
|
| 37 |
+
|
| 38 |
+
except requests.exceptions.RequestException as e:
|
| 39 |
+
return f"Error fetching random fact: {str(e)}"
|
| 40 |
+
|
| 41 |
@tool
|
| 42 |
def get_joke() -> str:
|
| 43 |
"""
|
|
|
|
| 103 |
|
| 104 |
agent = CodeAgent(
|
| 105 |
model=model,
|
| 106 |
+
tools=[get_random_fact, get_joke, final_answer], ## add your tools here (don't remove final answer)
|
| 107 |
max_steps=6,
|
| 108 |
verbosity_level=1,
|
| 109 |
grammar=None,
|