forked from Shubhamsaboo/awesome-llm-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravel_agent.py
69 lines (63 loc) · 3.58 KB
/
travel_agent.py
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
from textwrap import dedent
from phi.assistant import Assistant
from phi.tools.serpapi_tools import SerpApiTools
import streamlit as st
from phi.llm.openai import OpenAIChat
# Set up the Streamlit app
st.title("AI Travel Planner ✈️")
st.caption("Plan your next adventure with AI Travel Planner by researching and planning a personalized itinerary on autopilot using GPT-4o")
# Get OpenAI API key from user
openai_api_key = st.text_input("Enter OpenAI API Key to access GPT-4o", type="password")
# Get SerpAPI key from the user
serp_api_key = st.text_input("Enter Serp API Key for Search functionality", type="password")
if openai_api_key and serp_api_key:
researcher = Assistant(
name="Researcher",
role="Searches for travel destinations, activities, and accommodations based on user preferences",
llm=OpenAIChat(model="gpt-4o", api_key=openai_api_key),
description=dedent(
"""\
You are a world-class travel researcher. Given a travel destination and the number of days the user wants to travel for,
generate a list of search terms for finding relevant travel activities and accommodations.
Then search the web for each term, analyze the results, and return the 10 most relevant results.
"""
),
instructions=[
"Given a travel destination and the number of days the user wants to travel for, first generate a list of 3 search terms related to that destination and the number of days.",
"For each search term, `search_google` and analyze the results."
"From the results of all searches, return the 10 most relevant results to the user's preferences.",
"Remember: the quality of the results is important.",
],
tools=[SerpApiTools(api_key=serp_api_key)],
add_datetime_to_instructions=True,
)
planner = Assistant(
name="Planner",
role="Generates a draft itinerary based on user preferences and research results",
llm=OpenAIChat(model="gpt-4o", api_key=openai_api_key),
description=dedent(
"""\
You are a senior travel planner. Given a travel destination, the number of days the user wants to travel for, and a list of research results,
your goal is to generate a draft itinerary that meets the user's needs and preferences.
"""
),
instructions=[
"Given a travel destination, the number of days the user wants to travel for, and a list of research results, generate a draft itinerary that includes suggested activities and accommodations.",
"Ensure the itinerary is well-structured, informative, and engaging.",
"Ensure you provide a nuanced and balanced itinerary, quoting facts where possible.",
"Remember: the quality of the itinerary is important.",
"Focus on clarity, coherence, and overall quality.",
"Never make up facts or plagiarize. Always provide proper attribution.",
],
add_datetime_to_instructions=True,
add_chat_history_to_prompt=True,
num_history_messages=3,
)
# Input fields for the user's destination and the number of days they want to travel for
destination = st.text_input("Where do you want to go?")
num_days = st.number_input("How many days do you want to travel for?", min_value=1, max_value=30, value=7)
if st.button("Generate Itinerary"):
with st.spinner("Processing..."):
# Get the response from the assistant
response = planner.run(f"{destination} for {num_days} days", stream=False)
st.write(response)