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