Abraham E. Tavarez commited on
Commit
9cb9227
·
1 Parent(s): 233fe2e

code agent test

Browse files
Files changed (4) hide show
  1. agent.py +6 -1
  2. app.py +2 -2
  3. requirements.txt +2 -1
  4. tools/wikipedia_summarize.py +21 -0
agent.py CHANGED
@@ -3,6 +3,7 @@ from smolagents import (
3
  HfApiModel,
4
  CodeAgent,
5
  load_tool,
 
6
  InferenceClientModel,
7
  ToolCallingAgent,
8
  FinalAnswerTool,
@@ -22,11 +23,15 @@ load_dotenv()
22
  login(os.environ["HF_API_KEY"])
23
 
24
  # Tools
 
 
 
25
  tools = [
26
  DuckDuckGoSearchTool(),
27
  VisitWebpageTool(),
28
  PythonInterpreterTool(),
29
  FinalAnswerTool(),
 
30
  ]
31
 
32
  question = QUESTIONS[0]
@@ -51,10 +56,10 @@ codeAgent = CodeAgent(
51
 
52
  codeAgent.logger.console.width = 66
53
 
54
- # answer = codeAgent.run(question)
55
  # answer = codeAgent.run(
56
  # "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters."
57
  # )
 
58
  # print(answer)
59
 
60
 
 
3
  HfApiModel,
4
  CodeAgent,
5
  load_tool,
6
+ Tool,
7
  InferenceClientModel,
8
  ToolCallingAgent,
9
  FinalAnswerTool,
 
23
  login(os.environ["HF_API_KEY"])
24
 
25
  # Tools
26
+
27
+ # wikipedia = Tool.from_langchain(load_tool("wikipedia", trust_remote_code=True))
28
+
29
  tools = [
30
  DuckDuckGoSearchTool(),
31
  VisitWebpageTool(),
32
  PythonInterpreterTool(),
33
  FinalAnswerTool(),
34
+ # wikipedia
35
  ]
36
 
37
  question = QUESTIONS[0]
 
56
 
57
  codeAgent.logger.console.width = 66
58
 
 
59
  # answer = codeAgent.run(
60
  # "Who are the pitchers with the number before and after Taishō Tamai's number as of July 2023? Give them to me in the form Pitcher Before, Pitcher After, use their last names only, in Roman characters."
61
  # )
62
+ # answer = codeAgent.run("search wikipedia for: what the name of the main character of the fast and furious movie")
63
  # print(answer)
64
 
65
 
app.py CHANGED
@@ -15,8 +15,8 @@ class BasicAgent:
15
  def __init__(self):
16
  print("BasicAgent initialized.")
17
  def __call__(self, question: str) -> str:
18
- # return codeAgent.run(question)
19
- return toolCallingAgent.run(question)
20
  # print(f"Agent received question (first 50 chars): {question[:50]}...")
21
  # fixed_answer = "This is a default answer."
22
  # print(f"Agent returning fixed answer: {fixed_answer}")
 
15
  def __init__(self):
16
  print("BasicAgent initialized.")
17
  def __call__(self, question: str) -> str:
18
+ return codeAgent.run(question)
19
+ # return toolCallingAgent.run(question)
20
  # print(f"Agent received question (first 50 chars): {question[:50]}...")
21
  # fixed_answer = "This is a default answer."
22
  # print(f"Agent returning fixed answer: {fixed_answer}")
requirements.txt CHANGED
@@ -5,4 +5,5 @@ dotenv
5
  duckduckgo-search
6
  markdownify
7
  pandas
8
- numpy
 
 
5
  duckduckgo-search
6
  markdownify
7
  pandas
8
+ numpy
9
+ langchain
tools/wikipedia_summarize.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import tool
2
+ import requests
3
+
4
+ @tool
5
+ def wiki_summarize(topic: str) -> str:
6
+ """Get the first paragraph summary for a Wikipedia topic.
7
+ rgs:
8
+ topic: The Wikipedia page title to summarize.
9
+ Returns:
10
+ A short summary of the page.
11
+
12
+ """
13
+ url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{topic}"
14
+ resp = requests.get(url)
15
+ if resp.status_code == 200:
16
+ data = resp.json()
17
+ return data.get("extract", "No summary available.")
18
+ else:
19
+ return f"Error fetching Wikipedia summary (status {resp.status_code})."
20
+
21
+ # wiki_summarize_tool = wiki_summarize.push_to_hub()