File size: 1,863 Bytes
7a43cb5
fe8bf03
7a43cb5
7dc53ba
fe8bf03
70cddf8
7a43cb5
28fd9eb
7a43cb5
972fb5d
8c01ffb
e515432
 
 
 
 
fe8bf03
 
 
 
 
e515432
fe8bf03
 
2b723f9
 
6a8db2f
2b723f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fe8bf03
 
 
 
7dc53ba
fe8bf03
22f9799
fe8bf03
 
 
 
 
 
 
 
 
9b5b26a
fe8bf03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool
import yaml
from tools.final_answer import FinalAnswerTool
from tools.weather import get_weather
from Gradio_UI import GradioUI
import os

# Initialize tools
final_answer = FinalAnswerTool()
duck_duck_go_search = DuckDuckGoSearchTool()

# Get the Hugging Face token from environment variable
hf_token = os.getenv('HUGGINGFACE_TOKEN')
if not hf_token:
    raise ValueError("Please set the HUGGINGFACE_TOKEN environment variable")

model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
    custom_role_conversions=None,
    token=hf_token,
)

# Define prompt templates directly in the code
prompt_templates = {
    "system_prompt": """You are a helpful AI assistant that can use tools to solve problems.
You have access to the following tools:
{{tools}}

When you want to use a tool, use this format:
```python
get_weather(location="New York")
```
or
```python
duck_duck_go_search(query="latest news about artificial intelligence")
```

When you have a final answer, use:
```python
final_answer("Your detailed response here")
```""",
    "user": "{{query}}",
    "tool_response": """The result of your tool call was:
{{observation}}

What would you like to do next?""",
    "final_answer": {
        "pre_messages": "Please provide your final answer.",
        "post_messages": "Let me know if you have any other questions!"
    }
}

# We're creating our CodeAgent with multiple tools
agent = CodeAgent(
    model=model,
    tools=[
        get_weather,  # Pass the function directly
        final_answer,
        duck_duck_go_search,
    ],
    max_steps=6,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name=None,
    description=None,
    prompt_templates=prompt_templates
)

GradioUI(agent).launch()