Akj2023's picture
Improve UI | Add chains for itinerary with map JSON
d137f7e
from langchain.prompts import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
)
class ItineraryTemplate:
def __init__(self):
self.system_template = """
You are a sophisticated AI travel guide. Your job is to create engaging and practical travel plans for users.
The user's travel details and preferences will be presented in a structured format, starting with four hashtags. Your task is to convert these details into a detailed travel itinerary that includes waypoints, activities, and suggestions tailored to the user's interests and constraints.
Focus on providing specific addresses or locations for each suggested activity.
Take into account the user's available time, budget, preferred transportation mode, accommodation type, and desired daily schedule intensity. Aim to construct an itinerary that is enjoyable, feasible, and aligns with the user's expectations.
Present the itinerary in a bulleted list format with clear indications of the start and end points, as well as the recommended mode of transit between locations.
If the user has not specified certain details, use your judgment to select appropriate options, ensuring to provide specific addresses. Your response should be the itinerary list exclusively.
"""
self.human_template = """
#### User's Travel Details ####
- Starting Location: {start_location}
- Destination: {end_location}
- Travel Dates: {start_date} to {end_date}
- Attractions of Interest: {attractions}
- Travel Budget Range: {budget}
- Preferred Transportation: {transportation}
- Accommodation Type: {accommodation}
- Desired Daily Schedule Intensity: {schedule}
"""
# Assuming SystemMessagePromptTemplate and HumanMessagePromptTemplate are classes
# defined elsewhere in your codebase that format these messages.
self.system_message_prompt = SystemMessagePromptTemplate.from_template(
self.system_template
)
self.human_message_prompt = HumanMessagePromptTemplate.from_template(
self.human_template,
input_variables=["start_location", "end_location", "start_date", "end_date",
"attractions", "budget", "transportation", "accommodation",
"schedule"]
)
self.chat_prompt = ChatPromptTemplate.from_messages(
[self.system_message_prompt, self.human_message_prompt]
)
def generate_prompt(self, user_details):
"""
Fill in the human template with the actual details from the user's input.
"""
filled_human_template = self.human_message_prompt.format(
start_location=user_details['start_location'],
end_location=user_details['end_location'],
start_date=user_details['start_date'].strftime('%Y-%m-%d'),
end_date=user_details['end_date'].strftime('%Y-%m-%d'),
attractions=", ".join(user_details['attractions']),
budget=f"{user_details['budget'][0]} to {user_details['budget'][1]}",
transportation=user_details['transportation'],
accommodation=user_details['accommodation'],
schedule=user_details['schedule']
)
return f"{self.system_message_prompt}\n{filled_human_template}"