arenukvern commited on
Commit
8fd5ca8
·
1 Parent(s): 608c807

feat: image gen tool

Browse files
Files changed (3) hide show
  1. .gitignore +4 -1
  2. app.py +15 -8
  3. tools/web_search.py +8 -2
.gitignore CHANGED
@@ -1 +1,4 @@
1
- makefile
 
 
 
 
1
+ makefile
2
+ __pycache__
3
+ tools/__pycache__
4
+ .gradio
app.py CHANGED
@@ -4,22 +4,24 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
 
8
  from Gradio_UI import GradioUI
9
 
 
 
 
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- def my_custom_tool(
14
- arg1: str, arg2: int
15
  ) -> str: # it's import to specify the return type
16
- # Keep this format for the description / args / args description but feel free to modify the tool
17
- """A tool that does nothing yet
18
  Args:
19
- arg1: the first argument
20
- arg2: the second argument
21
  """
22
- return "What magic will you build ?"
23
 
24
 
25
  @tool
@@ -40,6 +42,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
40
 
41
  final_answer = FinalAnswerTool()
42
 
 
43
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
44
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
45
 
@@ -62,6 +65,10 @@ agent = CodeAgent(
62
  tools=[
63
  final_answer,
64
  get_current_time_in_timezone,
 
 
 
 
65
  ], ## add your tools here (don't remove final answer)
66
  max_steps=6,
67
  verbosity_level=1,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from tools.visit_webpage import VisitWebpageTool
8
+ from tools.web_search import DuckDuckGoSearchTool
9
  from Gradio_UI import GradioUI
10
 
11
+ search_tool = DuckDuckGoSearchTool()
12
+ visit_webpage_tool = VisitWebpageTool()
13
+
14
 
15
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
16
  @tool
17
+ def get_design_specs_for_year(
18
+ year: str,
19
  ) -> str: # it's import to specify the return type
20
+ """A tool that
 
21
  Args:
22
+ year: the year of the design specs
 
23
  """
24
+ return search_tool(f"What is the relevant design specs for {year}?")
25
 
26
 
27
  @tool
 
42
 
43
  final_answer = FinalAnswerTool()
44
 
45
+
46
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
47
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
48
 
 
65
  tools=[
66
  final_answer,
67
  get_current_time_in_timezone,
68
+ search_tool,
69
+ visit_webpage_tool,
70
+ get_design_specs_for_year,
71
+ image_generation_tool,
72
  ], ## add your tools here (don't remove final answer)
73
  max_steps=6,
74
  verbosity_level=1,
tools/web_search.py CHANGED
@@ -2,10 +2,13 @@ from typing import Any, Optional
2
  from smolagents.tools import Tool
3
  import duckduckgo_search
4
 
 
5
  class DuckDuckGoSearchTool(Tool):
6
  name = "web_search"
7
  description = "Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results."
8
- inputs = {'query': {'type': 'string', 'description': 'The search query to perform.'}}
 
 
9
  output_type = "string"
10
 
11
  def __init__(self, max_results=10, **kwargs):
@@ -23,5 +26,8 @@ class DuckDuckGoSearchTool(Tool):
23
  results = self.ddgs.text(query, max_results=self.max_results)
24
  if len(results) == 0:
25
  raise Exception("No results found! Try a less restrictive/shorter query.")
26
- postprocessed_results = [f"[{result['title']}]({result['href']})\n{result['body']}" for result in results]
 
 
 
27
  return "## Search Results\n\n" + "\n\n".join(postprocessed_results)
 
2
  from smolagents.tools import Tool
3
  import duckduckgo_search
4
 
5
+
6
  class DuckDuckGoSearchTool(Tool):
7
  name = "web_search"
8
  description = "Performs a duckduckgo web search based on your query (think a Google search) then returns the top search results."
9
+ inputs = {
10
+ "query": {"type": "string", "description": "The search query to perform."}
11
+ }
12
  output_type = "string"
13
 
14
  def __init__(self, max_results=10, **kwargs):
 
26
  results = self.ddgs.text(query, max_results=self.max_results)
27
  if len(results) == 0:
28
  raise Exception("No results found! Try a less restrictive/shorter query.")
29
+ postprocessed_results = [
30
+ f"[{result['title']}]({result['href']})\n{result['body']}"
31
+ for result in results
32
+ ]
33
  return "## Search Results\n\n" + "\n\n".join(postprocessed_results)