egor-fedosov commited on
Commit
edc5f9e
·
verified ·
1 Parent(s): 20e0222

Create agent.py

Browse files
Files changed (1) hide show
  1. agent.py +56 -0
agent.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import (
2
+ CodeAgent,
3
+ InferenceClientModel,
4
+ DuckDuckGoSearchTool,
5
+ VisitWebpageTool,
6
+ )
7
+
8
+
9
+ class BasicAgent:
10
+ def __init__(self):
11
+ model = InferenceClientModel()
12
+
13
+ self.agent = CodeAgent(
14
+ tools=[
15
+ DuckDuckGoSearchTool(max_results=10),
16
+ VisitWebpageTool(),
17
+ ],
18
+ model=model,
19
+ max_steps=15,
20
+ planning_interval=4,
21
+ )
22
+
23
+ def __call__(self, question: str) -> str:
24
+ prompt = f"""
25
+ Solve the following GAIA benchmark question accurately.
26
+
27
+ Use web search and webpage browsing whenever useful.
28
+ Reason carefully and verify facts when possible.
29
+
30
+ Your response will be checked using EXACT MATCH.
31
+
32
+ Return ONLY the final answer.
33
+ Do not provide an explanation.
34
+ Do not write "FINAL ANSWER".
35
+ Do not add introductory or concluding text.
36
+
37
+ If the answer is a list, follow the exact formatting requested
38
+ by the question.
39
+
40
+ Question:
41
+ {question}
42
+ """
43
+
44
+ result = self.agent.run(prompt)
45
+ return str(result).strip()
46
+
47
+
48
+ if __name__ == "__main__":
49
+ agent = BasicAgent()
50
+
51
+ test_question = (
52
+ '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,'
53
+ 'ecnetnes siht dnatsrednu uoy fI'
54
+ )
55
+
56
+ print(agent(test_question))