File size: 1,669 Bytes
9b5b26a
 
c19d193
7db033e
e7b3366
6aae614
9b5b26a
 
7db033e
9b5b26a
 
 
 
 
 
 
 
 
 
 
 
8c01ffb
e7b3366
7db033e
8c01ffb
8e47740
6aae614
ae7a494
e7b3366
 
e0309bf
8e47740
 
13d500a
8c01ffb
e7b3366
 
861422e
 
8e47740
7db033e
c9a7239
8c01ffb
8fe992b
8e47740
 
 
7db033e
8e47740
8c01ffb
 
c9a7239
8fe992b
 
8e47740
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
import datetime
import pytz
import yaml
import os
from smolagents import CodeAgent, HfApiModel, load_tool, tool
from tools.final_answer import FinalAnswerTool
from Gradio_UI import GradioUI

# 1. Define your custom logic tools
@tool
def get_current_time_in_timezone(timezone: str) -> str:
    """A tool that fetches the current local time in a specified timezone.
    Args:
        timezone: A string representing a valid timezone (e.g., 'America/New_York').
    """
    try:
        tz = pytz.timezone(timezone)
        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
        return f"The current local time in {timezone} is: {local_time}"
    except Exception as e:
        return f"Error fetching time for timezone '{timezone}': {str(e)}"

# 2. Load the Image Generation Tool
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)

# 3. Instantiate the Final Answer Tool
final_answer = FinalAnswerTool()

# 4. Configure the Model using the stable HfApiModel
model = HfApiModel(
    model_id='meta-llama/Llama-3.2-3B-Instruct', 
    max_tokens=2096,
    temperature=0.5,
)

# 5. Load Prompt Templates
# Ensure prompts.yaml is in your files!
with open("prompts.yaml", 'r') as stream:
    prompt_templates = yaml.safe_load(stream)

# 6. Initialize the Agent
# Initialize the Agent WITHOUT loading the local YAML
agent = CodeAgent(
    model=model,
    tools=[
        final_answer, 
        get_current_time_in_timezone, 
        image_generation_tool
    ], 
    max_steps=6,
    verbosity_level=1,
    # REMOVE the prompt_templates=prompt_templates line
)

# 7. Launch the User Interface
GradioUI(agent).launch()