Bastati commited on
Commit
bdcf069
·
verified ·
1 Parent(s): ae7a494

Upload app.py

Browse files

Made my own changes by fixing the visit_webpage and adding it as function also added the calls for the provided models

Files changed (1) hide show
  1. app.py +28 -7
app.py CHANGED
@@ -4,19 +4,36 @@ 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:
@@ -35,6 +52,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
 
38
 
39
  # 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:
40
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -42,7 +61,7 @@ final_answer = FinalAnswerTool()
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
@@ -50,12 +69,14 @@ custom_role_conversions=None,
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 tools.visit_webpage import VisitWebpageTool
8
+ from tools.web_search import DuckDuckGoSearchTool
9
+ from requests.exceptions import RequestException
10
 
11
  from Gradio_UI import GradioUI
12
 
13
+
14
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  @tool
16
+ def visit_webpage(url:str)-> str: #it's import to specify the return type
17
  #Keep this format for the description / args / args description but feel free to modify the tool
18
+ """Visits a webpage at the given url and reads its content as a string. Use this to browse webpages.
19
  Args:
20
+ url: the url of the web page
21
+
22
  """
23
+ try:
24
+ # Send a GET request to the URL with a 20-second timeout
25
+ response = requests.get(url, timeout=20)
26
+ response.raise_for_status() # Raise an exception for bad status codes
27
+
28
+
29
+ return response.text
30
+
31
+ except requests.exceptions.Timeout:
32
+ return "The request timed out. Please try again later or check the URL."
33
+ except RequestException as e:
34
+ return f"Error fetching the webpage: {str(e)}"
35
+ except Exception as e:
36
+ return f"An unexpected error occurred: {str(e)}"
37
 
38
  @tool
39
  def get_current_time_in_timezone(timezone: str) -> str:
 
52
 
53
 
54
  final_answer = FinalAnswerTool()
55
+ # visit_webpage = VisitWebpageTool()
56
+ web_search = DuckDuckGoSearchTool()
57
 
58
  # 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:
59
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
61
  model = HfApiModel(
62
  max_tokens=2096,
63
  temperature=0.5,
64
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',# it is possible that this model may be overloaded
65
  custom_role_conversions=None,
66
  )
67
 
 
69
  # Import tool from Hub
70
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
71
 
72
+
73
  with open("prompts.yaml", 'r') as stream:
74
  prompt_templates = yaml.safe_load(stream)
75
 
76
  agent = CodeAgent(
77
  model=model,
78
+ tools=[final_answer,get_current_time_in_timezone,web_search,
79
+ visit_webpage,image_generation_tool], ## add your tools here (don't remove final answer)
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,