NorthernStar commited on
Commit
cc19c2a
·
1 Parent(s): ae7a494

updated app.py with new tool function for image, search and jockes

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -33,6 +33,29 @@ 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
 
@@ -55,7 +78,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
+ @tool
37
+ def fetch_random_joke() -> str:
38
+ """A tool that fetches a random joke from an online API.
39
+ """
40
+ try:
41
+ response = requests.get("https://official-joke-api.appspot.com/random_joke")
42
+ if response.status_code == 200:
43
+ joke = response.json()
44
+ return f"{joke['setup']} - {joke['punchline']}"
45
+ else:
46
+ return "Failed to fetch a joke."
47
+ except Exception as e:
48
+ return f"Error fetching joke: {str(e)}"
49
+
50
+ @tool
51
+ def search_duckduckgo(query: str) -> str:
52
+ """A tool that performs a search using DuckDuckGo and returns the results.
53
+ Args:
54
+ query: The search query string.
55
+ """
56
+ search_tool = DuckDuckGoSearchTool()
57
+ results = search_tool.search(query)
58
+ return results
59
 
60
  final_answer = FinalAnswerTool()
61
 
 
78
 
79
  agent = CodeAgent(
80
  model=model,
81
+ tools=[final_answer, image_generation_tool, get_current_time_in_timezone, fetch_random_joke, search_duckduckgo], # add your tools here (don't remove final answer)
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,