chezhian commited on
Commit
36ac503
·
verified ·
1 Parent(s): bb2f929

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +53 -14
agent.py CHANGED
@@ -1,31 +1,70 @@
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
2
-
3
- # Initialize a model (use your preferred model_id)
4
- model = InferenceClientModel(model_id="meta-llama/Llama-2-7b-chat-hf") # Or another model
5
-
6
- # Define custom tools if needed (optional)
7
  from smolagents import tool
 
 
 
 
8
 
 
9
  @tool
10
  def add(a: int, b: int) -> int:
11
- """Add two numbers."""
 
 
 
 
 
12
  return a + b
13
 
14
  @tool
15
  def multiply(a: int, b: int) -> int:
16
- """Multiply two numbers."""
 
 
 
 
 
17
  return a * b
18
 
19
- # Create the agent with web search and custom tools
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  agent = CodeAgent(
21
- tools=[DuckDuckGoSearchTool(), add, multiply],
22
  model=model,
23
  )
24
 
25
  def answer_question(question: str) -> str:
26
- """Run the agent on a question and return the answer."""
27
  result = agent.run(question)
28
- # Format as per system_prompt.txt
29
- if "FINAL ANSWER:" not in result:
30
- result = f"FINAL ANSWER: {result}"
31
- return result
 
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
 
 
 
 
 
2
  from smolagents import tool
3
+ import os
4
+
5
+ # Initialize model
6
+ model = InferenceClientModel(model_id="meta-llama/Llama-2-70b-chat-hf")
7
 
8
+ # Custom tools with corrected docstrings
9
  @tool
10
  def add(a: int, b: int) -> int:
11
+ """Add two numbers.
12
+
13
+ Args:
14
+ a: The first number to add
15
+ b: The second number to add
16
+ """
17
  return a + b
18
 
19
  @tool
20
  def multiply(a: int, b: int) -> int:
21
+ """Multiply two numbers.
22
+
23
+ Args:
24
+ a: The first number to multiply
25
+ b: The second number to multiply
26
+ """
27
  return a * b
28
 
29
+ @tool
30
+ def subtract(a: int, b: int) -> int:
31
+ """Subtract two numbers.
32
+
33
+ Args:
34
+ a: The number to subtract from
35
+ b: The number to subtract
36
+ """
37
+ return a - b
38
+
39
+ @tool
40
+ def divide(a: int, b: int) -> int:
41
+ """Divide two numbers.
42
+
43
+ Args:
44
+ a: The number to divide
45
+ b: The divisor
46
+ """
47
+ if b == 0:
48
+ raise ValueError("Cannot divide by zero.")
49
+ return a / b
50
+
51
+ @tool
52
+ def modulus(a: int, b: int) -> int:
53
+ """Get the modulus of two numbers.
54
+
55
+ Args:
56
+ a: The number to get modulus of
57
+ b: The modulus divisor
58
+ """
59
+ return a % b
60
+
61
+ # Create agent with tools
62
  agent = CodeAgent(
63
+ tools=[DuckDuckGoSearchTool(), add, multiply, subtract, divide, modulus],
64
  model=model,
65
  )
66
 
67
  def answer_question(question: str) -> str:
68
+ """Run agent on question and format output"""
69
  result = agent.run(question)
70
+ return f"FINAL ANSWER: {result}" if "FINAL ANSWER:" not in result else result