RobotJelly commited on
Commit
92661a8
·
verified ·
1 Parent(s): e1e539f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -4,24 +4,28 @@ 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, img: bool)-> 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 uses 'DuckDuckGoSearchTool' tool to answer any query.
15
  Args:
16
- arg1: query1 in string to be searched via search tool.
17
- img: whether arg1 query to be used for generating image.
18
  """
19
- if img:
20
- img = image_generation_tool(arg1)
21
- return img
22
- else:
23
- answer = DuckDuckGoSearchTool(arg1)
24
- return str(answer)
 
 
 
25
 
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -60,7 +64,7 @@ with open("prompts.yaml", 'r') as stream:
60
 
61
  agent = CodeAgent(
62
  model=model,
63
- tools=[final_answer], ## add your tools here (don't remove final answer)
64
  max_steps=6,
65
  verbosity_level=1,
66
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from PIL.Image import Image
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
+ def my_custom_tool(arg1:str, img: bool)-> str|Image: #it's import to specify the return type
14
  #Keep this format for the description / args / args description but feel free to modify the tool
15
  """A tool that uses 'DuckDuckGoSearchTool' tool to answer any query.
16
  Args:
17
+ arg1: string query to be used to search answer via given search tool.
18
+ img: boolean value in TRUE/FALSE if TRUE then use 'arg1' as prompt for generating image.
19
  """
20
+ try:
21
+ if img:
22
+ img = image_generation_tool(arg1)
23
+ return img
24
+ else:
25
+ answer = DuckDuckGoSearchTool(arg1)
26
+ return str(answer)
27
+ except Exception as e:
28
+ return f"error occurred in my_custom_tool...{str(e)}"
29
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
 
64
 
65
  agent = CodeAgent(
66
  model=model,
67
+ tools=[final_answer,my_custom_tool,get_current_time_in_timezone], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,