DanielRZapataS commited on
Commit
7514555
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files

add agents tools

Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -4,19 +4,17 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
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:
@@ -48,14 +46,37 @@ custom_role_conversions=None,
48
 
49
 
50
  # Import tool from Hub
 
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  with open("prompts.yaml", 'r') as stream:
54
  prompt_templates = yaml.safe_load(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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
 
 
8
  @tool
9
+ def search(query: str)-> str:
10
+ """A web search tool that returns the first search result from DuckDuckGo.
 
11
  Args:
12
+ query: The search query.
 
13
  """
14
+ try:
15
+ return DuckDuckGoSearchTool().forward(query)
16
+ except Exception as e:
17
+ return f"Error searching web: {str(e)}"
18
 
19
  @tool
20
  def get_current_time_in_timezone(timezone: str) -> str:
 
46
 
47
 
48
  # Import tool from Hub
49
+ ## text-to-image tool
50
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
51
+ ## document-qa tool
52
+ # document_qa_tool = load_tool("agents-course/document-qa", trust_remote_code=True)
53
+
54
+ @tool
55
+ def generate_image(prompt: str) -> str:
56
+ """A tool that generates an image based on a text prompt.
57
+ Args:
58
+ prompt: The text prompt to generate an image
59
+ """
60
+ return image_generation_tool.forward(prompt)
61
+
62
+ @tool
63
+ def document_qa(document: str, question: str) -> str:
64
+ """A tool that answers a question based on a document.
65
+ Args:
66
+ document: The document to search in.
67
+ question: The question to answer.
68
+ """
69
+
70
+
71
+ return
72
+
73
 
74
  with open("prompts.yaml", 'r') as stream:
75
  prompt_templates = yaml.safe_load(stream)
76
 
77
  agent = CodeAgent(
78
  model=model,
79
+ tools=[final_answer, search, get_current_time_in_timezone, generate_image], ## add your tools here (don't remove final answer)
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,