KenStock commited on
Commit
77c6f8e
·
1 Parent(s): ae7a494

Add websearch and visit webpage tools to the agent

Browse files
Files changed (3) hide show
  1. .gitignore +2 -0
  2. app.py +21 -6
  3. tools/visit_webpage.py +1 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__
2
+ .gradio
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -32,18 +33,27 @@ def get_current_time_in_timezone(timezone: str) -> str:
32
  return f"The current local time in {timezone} is: {local_time}"
33
  except Exception as e:
34
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
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'
41
 
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
 
49
 
@@ -55,7 +65,12 @@ 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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from tools.visit_webpage import VisitWebpageTool
8
 
9
  from Gradio_UI import GradioUI
10
 
 
33
  return f"The current local time in {timezone} is: {local_time}"
34
  except Exception as e:
35
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
36
+
37
+ @tool
38
+ def get_current_gluffy_age() -> int :
39
+ """A tool that fetches the current age of Gluffy.
40
+ Args: None
41
+ """
42
+ return 21
43
 
44
+ # Predifined tools
45
  final_answer = FinalAnswerTool()
46
+ visit_webpage = VisitWebpageTool()
47
+ web_search = DuckDuckGoSearchTool()
48
 
49
  # 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:
50
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
51
 
52
  model = HfApiModel(
53
+ max_tokens=2096,
54
+ temperature=0.5,
55
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
56
+ custom_role_conversions=None,
57
  )
58
 
59
 
 
65
 
66
  agent = CodeAgent(
67
  model=model,
68
+ tools=[
69
+ visit_webpage,
70
+ web_search,
71
+ get_current_gluffy_age,
72
+ get_current_time_in_timezone,
73
+ final_answer], ## add your tools here (don't remove final answer)
74
  max_steps=6,
75
  verbosity_level=1,
76
  grammar=None,
tools/visit_webpage.py CHANGED
@@ -1,5 +1,6 @@
1
  from typing import Any, Optional
2
  from smolagents.tools import Tool
 
3
  import requests
4
  import markdownify
5
  import smolagents
 
1
  from typing import Any, Optional
2
  from smolagents.tools import Tool
3
+ import re
4
  import requests
5
  import markdownify
6
  import smolagents