File size: 1,796 Bytes
9e137f5
c19d193
8f5e5c3
 
6aae614
9e137f5
 
 
 
 
 
 
 
 
9b5b26a
 
8f5e5c3
 
 
9e137f5
e121372
9e137f5
 
 
 
13d500a
8c01ffb
9e137f5
861422e
 
9e137f5
 
 
 
 
 
 
9b5b26a
9e137f5
8c01ffb
8fe992b
8f5e5c3
 
 
 
 
 
 
81bd92e
9e137f5
 
 
8f5e5c3
8c01ffb
 
 
 
 
 
861422e
8fe992b
 
9e137f5
8c01ffb
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
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool
import yaml
import os
from dotenv import load_dotenv
from tools.final_answer import FinalAnswerTool
from tools.weather_tool import get_weather
from tools.currency_tool import convert_currency
from tools.news_tool import get_news_headlines
from tools.wikipedia_tool import get_wikipedia_summary
from tools.math_tool import solve_math_expression
from tools.password_tool import generate_password
from tools.time_tool import get_current_time_in_timezone
from tools.web_search import DuckDuckGoSearchTool
from tools.visit_webpage import VisitWebpageTool
from Gradio_UI import GradioUI

# Load environment variables
load_dotenv()

# Initialize the model
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,
    model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',
    custom_role_conversions=None,
)

# Load prompt templates
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# Initialize final answer tool
final_answer = FinalAnswerTool()

# Initialize web tools
web_search_tool = DuckDuckGoSearchTool(max_results=5)
visit_webpage_tool = VisitWebpageTool()
    
# Initialize the agent with all tools
agent = CodeAgent(
    model=model,
    tools=[
        final_answer,
        get_weather,
        convert_currency,
        get_news_headlines,
        get_wikipedia_summary,
        solve_math_expression,
        generate_password,
        get_current_time_in_timezone,
        web_search_tool,
        visit_webpage_tool
    ],
    max_steps=6,
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name=None,
    description=None,
    prompt_templates=prompt_templates
)

# Launch the Gradio interface
GradioUI(agent).launch()