main.py
1 import argparse 2 from dotenv import load_dotenv 3 from tools import ( 4 llm_call, 5 weather_tool, 6 currency_converter_tool, 7 flight_price_estimator_tool, 8 ) 9 from agents import ItineraryAgent 10 from config import initialize_tracing 11 12 import sys 13 import os 14 sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../..'))) 15 16 from ragaai_catalyst import trace_agent, current_span 17 18 load_dotenv() 19 20 tracer = initialize_tracing() 21 22 @trace_agent(name="travel_agent") 23 def travel_agent(model_name: str = "gpt-4o-mini", provider: str = "openai"): 24 current_span().add_metrics( 25 name="travel_planning_session", 26 score=0.9, 27 reasoning="Main travel planning session", 28 cost=0.05, 29 latency=1.0, 30 ) 31 32 print("Welcome to the Personalized Travel Planner!\n") 33 34 # Get user input 35 # user_input = input("Please describe your ideal vacation: ") 36 user_input = "karela, 10 days, 1000$, nature" 37 38 # Extract preferences 39 preferences_prompt = f""" 40 Extract key travel preferences from the following user input: 41 "{user_input}" 42 43 Please provide the extracted information in this format: 44 Destination: 45 Activities: 46 Budget: 47 Duration (in days): 48 """ 49 extracted_preferences = llm_call(preferences_prompt, name="extract_preferences", model_name=model_name, provider=provider) 50 print("\nExtracted Preferences:") 51 print(extracted_preferences) 52 53 # Parse extracted preferences 54 preferences = {} 55 for line in extracted_preferences.split("\n"): 56 if ":" in line: 57 key, value = line.split(":", 1) 58 preferences[key.strip()] = value.strip() 59 60 # Validate extracted preferences 61 required_keys = ["Destination", "Activities", "Budget", "Duration (in days)"] 62 if not all(key in preferences for key in required_keys): 63 print("\nCould not extract all required preferences. Please try again.") 64 return 65 66 # Fetch additional information 67 weather = weather_tool(preferences["Destination"]) 68 print(f"\nWeather in {preferences['Destination']}: {weather}") 69 70 # Get departure city 71 # print("Please enter your departure city: ") 72 # origin = input() 73 origin = "delhi" 74 flight_price = flight_price_estimator_tool(origin, preferences["Destination"]) 75 print(flight_price) 76 77 # Plan itinerary 78 itinerary_agent = ItineraryAgent() 79 itinerary = itinerary_agent.plan_itinerary( 80 { 81 "destination": preferences["Destination"], 82 "origin": origin, 83 "budget": float(preferences["Budget"].replace("$", "")), 84 "budget_currency": "USD", 85 }, 86 int(preferences["Duration (in days)"]), 87 ) 88 print("\nPlanned Itinerary:") 89 print(itinerary) 90 91 budget_amount = float(preferences["Budget"].replace("$", "").replace(",", "")) 92 converted_budget = currency_converter_tool(budget_amount, "USD", "INR") 93 if converted_budget: 94 print(f"\nBudget in INR: {converted_budget:.2f} INR") 95 else: 96 print("\nCurrency conversion not available.") 97 98 summary_prompt = f""" 99 Summarize the following travel plan: 100 101 Destination: {preferences['Destination']} 102 Activities: {preferences['Activities']} 103 Budget: {preferences['Budget']} 104 Duration: {preferences['Duration (in days)']} days 105 Itinerary: {itinerary} 106 Weather: {weather} 107 Flight Price: {flight_price} 108 109 Travel Summary: 110 """ 111 travel_summary = llm_call(summary_prompt, name="generate_summary", model_name=model_name, provider=provider) 112 print("\nTravel Summary:") 113 print(travel_summary) 114 115 if __name__ == "__main__": 116 # Parse command-line arguments 117 parser = argparse.ArgumentParser(description="Run the travel agent.") 118 parser.add_argument("--model", type=str, default="gpt-4o-mini", help="The model to use (e.g., gpt-4o-mini).") 119 parser.add_argument("--provider", type=str, default="openai", help="The LLM provider (e.g., openai).") 120 args = parser.parse_args() 121 122 123 with tracer: 124 travel_agent(model_name=args.model, provider=args.provider) 125