|
|
|
|
|
|
|
|
|
from smolagents import CodeAgent, HfApiModel, load_tool |
|
import datetime |
|
import yaml |
|
import os |
|
|
|
|
|
from tools.final_answer import FinalAnswerTool |
|
from tools.web_search import DuckDuckGoSearchTool |
|
from tools.visit_webpage import VisitWebpageTool |
|
from tools.generate_destination_preview import GenerateDestinationPreviewTool |
|
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 |
|
|
|
|
|
|
|
|
|
final_answer = FinalAnswerTool() |
|
web_search = DuckDuckGoSearchTool(max_results=5) |
|
visit_webpage = VisitWebpageTool() |
|
generate_destination_preview = GenerateDestinationPreviewTool() |
|
get_local_time = GetLocalTimeTool() |
|
get_weather_forecast = GetWeatherForecastTool() |
|
convert_currency = ConvertCurrencyTool() |
|
translate_phrase = TranslatePhraseTool() |
|
get_visa_requirements = GetVisaRequirementsTool() |
|
|
|
|
|
model = HfApiModel( |
|
max_tokens=2096, |
|
temperature=0.5, |
|
model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud', |
|
custom_role_conversions=None, |
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
with open("prompts.yaml", 'r') as stream: |
|
prompt_templates = yaml.safe_load(stream) |
|
except FileNotFoundError: |
|
|
|
prompt_templates = {} |
|
print("Warning: prompts.yaml not found. Using default 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. Provide vivid descriptions of travel destinations |
|
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 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. |
|
""" |
|
|
|
|
|
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 |
|
|
|
|
|
agent = CodeAgent( |
|
model=model, |
|
tools=[ |
|
final_answer, |
|
web_search, |
|
visit_webpage, |
|
generate_destination_preview, |
|
get_local_time, |
|
get_weather_forecast, |
|
convert_currency, |
|
translate_phrase, |
|
get_visa_requirements, |
|
], |
|
max_steps=8, |
|
verbosity_level=1, |
|
grammar=None, |
|
planning_interval=None, |
|
name="Journi", |
|
description="Your AI travel companion", |
|
prompt_templates=prompt_templates |
|
) |
|
|
|
|
|
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() |