File size: 4,863 Bytes
1b4e330
02e041d
1b4e330
02e041d
73f5348
9b5b26a
c19d193
02e041d
1b4e330
 
6aae614
1b4e330
 
 
 
 
 
 
9b5b26a
 
02e041d
 
1b4e330
02e041d
1b4e330
 
 
 
 
 
 
 
 
02e041d
b5e4e57
 
 
 
02e041d
8c01ffb
b5e4e57
 
 
 
 
 
 
02e041d
1b4e330
 
 
 
 
 
 
02e041d
 
 
1b4e330
02e041d
 
 
1b4e330
 
c8c0e0f
1b4e330
 
 
 
 
02e041d
c8c0e0f
 
 
 
 
 
02e041d
1b4e330
02e041d
 
 
 
c8c0e0f
 
02e041d
 
 
 
 
 
73f5348
 
 
 
 
 
 
02e041d
8c01ffb
8fe992b
02e041d
 
1b4e330
 
73f5348
1b4e330
 
 
 
 
02e041d
 
8c01ffb
 
 
1b4e330
02e041d
b71898b
8fe992b
 
02e041d
1b4e330
 
 
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Journi - Your AI Travel Companion
# This agent helps travelers with destination information, local time, weather forecasts,
# currency conversion, language translation, and destination previews.

from smolagents import CodeAgent, HfApiModel, load_tool, Tool, tool
import datetime
import yaml
import os

# Import all the tool classes from their respective files
from tools.final_answer import FinalAnswerTool
from tools.web_search import DuckDuckGoSearchTool
from tools.visit_webpage import VisitWebpageTool
from tools.get_local_time import GetLocalTimeTool
from tools.get_weather_forecast import GetWeatherForecastTool
from tools.convert_currency import ConvertCurrencyTool
from tools.translate_phrase import TranslatePhraseTool
from tools.get_visa_requirements import GetVisaRequirementsTool
from Gradio_UI import GradioUI

# ==================== AGENT SETUP ====================

# Initialize all tool instances
final_answer = FinalAnswerTool()
web_search = DuckDuckGoSearchTool(max_results=5)  # Limit results for better readability
visit_webpage = VisitWebpageTool()
get_local_time = GetLocalTimeTool()
get_weather_forecast = GetWeatherForecastTool()
convert_currency = ConvertCurrencyTool()
translate_phrase = TranslatePhraseTool()
get_visa_requirements = GetVisaRequirementsTool()

# Model initialization
model = HfApiModel(
    max_tokens=2096,
    temperature=0.5,  # Balanced between creativity and accuracy
    model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud',  # Use the AWS endpoint
    custom_role_conversions=None,
)

# model = HfApiModel(
# max_tokens=2096,
# temperature=0.5,
# model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
# custom_role_conversions=None,
# )

# Load prompts
try:
    with open("prompts.yaml", 'r') as stream:
        prompt_templates = yaml.safe_load(stream)
except FileNotFoundError:
    # Create a basic template if file doesn't exist
    prompt_templates = {}
    print("Warning: prompts.yaml not found. Using default prompt templates.")

# Add travel companion specific instructions to the prompt templates
travel_agent_prompt = """
You are Journi, an AI travel companion designed to help travelers plan and navigate their journeys.
Your goal is to provide helpful, accurate information about destinations, local customs, and practical travel advice.

You have access to these capabilities:
1. Search for travel information online
2. Visit webpages to get detailed information
3. Generate images of destinations using the image_generator tool
4. Check local time at travel destinations
5. Provide weather forecasts for trip planning
6. Convert currencies for travel budgeting
7. Translate common travel phrases
8. Check visa requirements

When users request an image of a destination, ALWAYS use the image_generator tool:
```python
destination_image = image_generator(prompt="Detailed description of the destination")
final_answer(destination_image)

Always pass the generated image directly to final_answer, DO NOT use external URLs.
When users ask about a destination, try to provide comprehensive information by combining multiple tools.
For example, if someone asks about Tokyo, consider providing the local time, weather, and a descriptive preview.
Always be enthusiastic about travel while remaining practical and informative.
Suggest off-the-beaten-path experiences when appropriate, but prioritize the specific information requested.
"""



# Add the travel agent prompt to the existing templates
if "system_prompt" in prompt_templates:
    prompt_templates["system_prompt"] = travel_agent_prompt + "\n\n" + prompt_templates.get("system_prompt", "")
else:
    prompt_templates["system_prompt"] = travel_agent_prompt

# Import the image generation tool directly from the Space
image_generation_tool = Tool.from_space(
    "black-forest-labs/FLUX.1-schnell",
    name="image_generator",
    description="Generate an image from a text prompt. The prompt should be detailed to create high-quality images."
)

# Agent setup with all travel tools
agent = CodeAgent(
    model=model,
    tools=[
        final_answer,
        web_search,
        visit_webpage,
        image_generation_tool,
        get_local_time,
        get_weather_forecast,
        convert_currency,
        translate_phrase,
        get_visa_requirements,
    ],
    max_steps=8,                      # Increased to allow for more tool usage in a single query
    verbosity_level=1,
    grammar=None,
    planning_interval=None,
    name="Journi",
    description="Your AI travel companion",
    prompt_templates=prompt_templates
)

# Launch the UI
if __name__ == "__main__":
    print("✈️ Launching Journi - Your AI Travel Companion")
    print("Ask me about any destination, local time, weather, currency conversion, or travel phrases!")
    GradioUI(agent).launch()