hasanfaesal commited on
Commit
82ba3ea
·
verified ·
1 Parent(s): ae7a494

tools added: ddg_search, generate_image, current_time

Browse files
Files changed (1) hide show
  1. app.py +46 -7
app.py CHANGED
@@ -8,15 +8,54 @@ from tools.final_answer import FinalAnswerTool
8
  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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
 
 
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +94,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,
 
8
  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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
+ # #Keep this format for the description / args / args description but feel free to modify the tool
14
+ # """A tool that does nothing yet
15
+ # Args:
16
+ # arg1: the first argument
17
+ # arg2: the second argument
18
+ # """
19
+ # return "What magic will you build ?"
20
+
21
+ @tool
22
+ def duckduckgo_search(query: str) -> str:
23
+ """A tool that searches DuckDuckGo for the given query and returns the top 3 URLs.
24
+
25
+ Args:
26
+ query: A string representing the search query.
27
+ Returns:
28
+ A string containing the top 3 URLs separated by newline characters.
29
+ """
30
+ # Use the DuckDuckGoSearchTool to perform the search.
31
+ # this tool returns a list of dictionaries each with a 'url' key.
32
+ results = DuckDuckGoSearchTool(query=query)
33
+
34
+ # Extract the top 3 results.
35
+ top_results = results[:3]
36
+ urls = [result.get("url", "URL not found") for result in top_results]
37
+
38
+ return "\n".join(urls)
39
+
40
  @tool
41
+ def generate_image(prompt: str) -> str:
42
+ """A tool that generates an image based on a text prompt.
43
+
44
  Args:
45
+ prompt: A text description for the image to generate.
46
+
47
+ Returns:
48
+ A string containing the URL of the generated image, or an error message if generation fails.
49
  """
50
+ try:
51
+ # Call the preloaded image_generation_tool with the provided prompt.
52
+ result = image_generation_tool(prompt=prompt)
53
+ # Assume the tool returns a dictionary with an 'image_url' key.
54
+ image_url = result.get("image_url", "No image URL returned")
55
+ return image_url
56
+ except Exception as e:
57
+ return f"Error generating image: {str(e)}"
58
+
59
 
60
  @tool
61
  def get_current_time_in_timezone(timezone: str) -> str:
 
94
 
95
  agent = CodeAgent(
96
  model=model,
97
+ tools=[final_answer, duckduckgo_search, generate_image, get_current_time_in_timezone],
98
  max_steps=6,
99
  verbosity_level=1,
100
  grammar=None,