Added new demo
This commit is contained in:
parent
8a8fd61955
commit
f1b56370a6
3 changed files with 105 additions and 0 deletions
66
ai_travel_agent/local_travel_agent.py
Normal file
66
ai_travel_agent/local_travel_agent.py
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
from textwrap import dedent
|
||||||
|
from phi.assistant import Assistant
|
||||||
|
from phi.tools.serpapi_tools import SerpApiTools
|
||||||
|
import streamlit as st
|
||||||
|
from phi.llm.ollama import Ollama
|
||||||
|
|
||||||
|
# Set up the Streamlit app
|
||||||
|
st.title("AI Travel Planner using Llama-3 ✈️")
|
||||||
|
st.caption("Plan your next adventure with AI Travel Planner by researching and planning a personalized itinerary on autopilot using local Llama-3")
|
||||||
|
|
||||||
|
# Get SerpAPI key from the user
|
||||||
|
serp_api_key = st.text_input("Enter Serp API Key for Search functionality", type="password")
|
||||||
|
|
||||||
|
if serp_api_key:
|
||||||
|
researcher = Assistant(
|
||||||
|
name="Researcher",
|
||||||
|
role="Searches for travel destinations, activities, and accommodations based on user preferences",
|
||||||
|
llm=Ollama(model="llama3:instruct", max_tokens=1024),
|
||||||
|
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=Ollama(model="llama3:instruct", max_tokens=1024),
|
||||||
|
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)
|
||||||
37
local_chatgpt_with_memory/local_chatgpt_memory.py
Normal file
37
local_chatgpt_with_memory/local_chatgpt_memory.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import streamlit as st
|
||||||
|
from openai import OpenAI
|
||||||
|
|
||||||
|
# Set up the Streamlit App
|
||||||
|
st.title("Local ChatGPT with Memory 🦙")
|
||||||
|
st.caption("Chat with locally hosted memory-enabled Llama-3 using the LM Studio 💯")
|
||||||
|
|
||||||
|
# Point to the local server setup using LM Studio
|
||||||
|
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
|
||||||
|
|
||||||
|
# Initialize the chat history
|
||||||
|
if "messages" not in st.session_state:
|
||||||
|
st.session_state.messages = []
|
||||||
|
|
||||||
|
# Display the chat history
|
||||||
|
for message in st.session_state.messages:
|
||||||
|
with st.chat_message(message["role"]):
|
||||||
|
st.markdown(message["content"])
|
||||||
|
|
||||||
|
# Accept user input
|
||||||
|
if prompt := st.chat_input("What is up?"):
|
||||||
|
st.session_state.messages.append({"role": "system", "content": "When the input starts with /add, don't follow up with a prompt."})
|
||||||
|
# Add user message to chat history
|
||||||
|
st.session_state.messages.append({"role": "user", "content": prompt})
|
||||||
|
# Display user message in chat message container
|
||||||
|
with st.chat_message("user"):
|
||||||
|
st.markdown(prompt)
|
||||||
|
# Generate response
|
||||||
|
response = client.chat.completions.create(
|
||||||
|
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
|
||||||
|
messages=st.session_state.messages, temperature=0.7
|
||||||
|
)
|
||||||
|
# Add assistant response to chat history
|
||||||
|
st.session_state.messages.append({"role": "assistant", "content": response.choices[0].message.content})
|
||||||
|
# Display assistant response in chat message container
|
||||||
|
with st.chat_message("assistant"):
|
||||||
|
st.markdown(response.choices[0].message.content)
|
||||||
2
local_chatgpt_with_memory/requirements.txt
Normal file
2
local_chatgpt_with_memory/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
streamlit
|
||||||
|
openai
|
||||||
Loading…
Reference in a new issue