How I Made a Bot to Plan My Trips Using Julep and Chainlit

As part of my generative AI series, this post will walk you through how I created an AI-powered travel agent using Julep and Chainlit. This bot can help you plan your next trip by suggesting destinations and activities and even generating an entire travel itinerary.

As a travel enthusiast, I’ve always wanted a personalized travel assistant that could help me discover new places and create custom itineraries. With the power of generative AI, I was able to bring this idea to life in just a few steps.

What You’re Gonna Use/Tech Stack

To build this trip planning bot, I used:

  • Julep: An open-source framework for creating AI agents
  • Chainlit: A tool for easily adding chat interfaces to your AI projects

But, What’s Julep?

Julep is an incredibly helpful framework that provides all the tools you need to create AI agents, manage user sessions, and store conversation memory. It allowed me to focus on designing my travel agent’s capabilities without getting bogged down in the infrastructure.

Don’t forget to ⭐ the Julep repo to show your support!

Step 1: Set Up Julep and Chainlit

First, install Julep and Chainlit in your Python environment:

pip install chainlit
pip install julep
Enter fullscreen mode
Exit fullscreen mode

Then, initialize the Julep client with your API key:

from julep import AsyncClient api_key = "<YOUR_API_KEY>" client = AsyncClient(api_key=api_key) 
Enter fullscreen mode
Exit fullscreen mode

Step 2: Create the Travel Agent

Next, use the Julep API to create your AI travel agent. Give it a name, description, and a set of instructions that define its capabilities:

 agent = await client.agents.create( name="Travel Agent", about="You are a travel agent with several your of experience. You are knowledgeable about different travel destinations and can provide recommendations based on user preferences. You are also able to suggest flights, hotels, and other travel accommodations for users. You are friendly, helpful, and eager to assist users with their travel needs.", model="gpt-4-turbo", instructions=[ "Ask the user where they would like to travel to.", 'Ask the user what their budget is', 'Ask the user what vibe they are looking for in a trip', 'Ask the user what kind of activities they enjoy', "Depending on the user's responses, suggest travel destinations as a numbered list", "Suggest activities, nearby attractions, landmarks, and restaurants in the destination as a numbered list", "Ask if they are planning to visit multiple destinations", "Ask for how many days the user is planning to stay", "Prepare an itinerary for the user", "Give useful phrases in the local language", ])
Enter fullscreen mode
Exit fullscreen mode

Step 3: Set Up User & Session

Create a user and a session to facilitate the conversation between the user and the travel agent:

user = await client.users.create(name="Philip", about="Traveler")
session = await client.sessions.create(agent_id=agent.id, user_id=user.id, situation="You are greeting a user that's planning to go on a trip.") 
Enter fullscreen mode
Exit fullscreen mode

Step 4: Set Up Chainlit Interface

Then, use Chainlit’s decorators to define the chat interface:

@cl.on_chat_start
async def start(): session_id = await setup_session() cl.user_session.set("session_id", session_id) response = await client.sessions.chat(session_id=session_id, messages=[{"content": "Greet the user", "role": "system"}], recall=True, remember=True, max_tokens=1000) await cl.Message(content=response.response[0][0].content).send() @cl.on_message
async def main(message: cl.Message): session_id = cl.user_session.get("session_id") response = await client.sessions.chat(session_id=session_id, messages=[{"content": message.content, "role": "user"}], recall=True, remember=True, max_tokens=1000) await cl.Message(content=response.response[0][0].content).send() 
Enter fullscreen mode
Exit fullscreen mode

Getting it to Plan

And that’s it! Run your Chainlit app and start chatting with your new AI travel agent. It will ask about your preferences, suggest destinations and activities, and generate a personalized itinerary for your dream trip.

Success

Use It to Plan Your Own Trip!

Want to try it out yourself? The full code for this project is available on my GitHub repo: https://github.com/philipbalbas/travel-agent

Feel free to clone it, customize the agent’s capabilities, and start planning your next adventure!

And once again, don’t forget to ⭐ Julep for making projects like this possible.

star!

Happy travels! 🌎✈️


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top