{ "cells": [ { "cell_type": "markdown", "id": "ca4e5d8b-b481-4de4-b067-1bee870b9604", "metadata": {}, "source": [ "# Travel Idea application using langchain prompts" ] }, { "cell_type": "code", "execution_count": 2, "id": "2e31211f-3b4d-4a29-add2-4ba139bf7588", "metadata": {}, "outputs": [], "source": [ "from langchain.chat_models import ChatOpenAI" ] }, { "cell_type": "code", "execution_count": 3, "id": "2c188c1f-666e-473e-8679-89d1098124a1", "metadata": {}, "outputs": [], "source": [ "from langchain.prompts import ChatPromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate" ] }, { "cell_type": "code", "execution_count": 10, "id": "4dab0984-4b17-4f83-83c3-d789cf0fad08", "metadata": {}, "outputs": [], "source": [ "def travel_idea(interest: str, budget: str):\n", " \"\"\"\n", " Takes interest for a travel idea and suggests a plan based on the budget\n", "\n", " :param interest: what is the interest for a travel idea\n", " :type interest: str\n", " :param budget: what is the budget for travel plan\n", " :type budget: str\n", " :return: returns a travel idea for a given interest and budget\n", " :rtype: str\n", " \"\"\"\n", " \n", " system_template = \"You are a travel agent that helps people plan trips about {interest} on a budget of {budget}\"\n", " system_message_prompt = SystemMessagePromptTemplate.from_template(system_template)\n", "\n", " human_template = \"Please give an example itinery\"\n", " human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)\n", "\n", " chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])\n", "\n", " request = chat_prompt.format_prompt(interest=interest, budget=budget).to_messages()\n", "\n", " chat = ChatOpenAI()\n", " result = chat(request)\n", " return result.content" ] }, { "cell_type": "code", "execution_count": 11, "id": "006f4fdc-fd56-4443-ae5b-8dbf33f6286b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Certainly! Here's an example itinerary for a skiing trip on a budget of $1000:\n", "\n", "Day 1: \n", "- Fly into Denver, Colorado.\n", "- Take a shuttle to your accommodation in a nearby ski town like Breckenridge or Winter Park.\n", "- Check-in and get settled.\n", "- Rest and relax after your journey.\n", "\n", "Day 2: \n", "- Rent ski equipment from a local rental shop (around $30 per day).\n", "- Spend the day skiing at one of the nearby resorts.\n", "- Pack a lunch to save money on food or grab an affordable meal at the resort cafeteria.\n", "- After skiing, explore the town and enjoy a budget-friendly dinner at a local eatery.\n", "\n", "Day 3: \n", "- Another day of skiing at a different resort.\n", "- Consider purchasing a multi-day lift ticket for savings.\n", "- Pack another lunch or try a budget-friendly restaurant near the resort.\n", "- In the evening, unwind at your accommodation or take advantage of any free activities or entertainment in the town.\n", "\n", "Day 4: \n", "- Take a break from skiing and explore the surrounding area.\n", "- Visit a nearby attraction like Rocky Mountain National Park or take a scenic drive through the mountains.\n", "- Enjoy a picnic lunch to keep costs down.\n", "- Return to your accommodation and relax.\n", "\n", "Day 5: \n", "- Spend the morning skiing at your favorite resort.\n", "- Return the ski equipment in the afternoon.\n", "- Treat yourself to a nice dinner at a local restaurant to celebrate the end of your trip.\n", "\n", "Day 6: \n", "- Check out of your accommodation and take a shuttle back to Denver.\n", "- Explore the city and visit some of the free or low-cost attractions like the Denver Museum of Nature & Science or the Denver Art Museum.\n", "- Have a final budget-friendly meal before heading to the airport.\n", "\n", "Day 7: \n", "- Fly back home with happy memories of your skiing trip.\n", "\n", "Remember, this itinerary can be adjusted to fit your specific needs and preferences. Prices may vary depending on the season and location, so it's always a good idea to research and compare costs before making any bookings.\n" ] } ], "source": [ "print(travel_idea(\"skiing\", \"$1000\"))" ] }, { "cell_type": "code", "execution_count": null, "id": "6ecd0a2e-a3b8-433f-b50c-7564858e5593", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }