Skip to content

Template for a simple chatbot using OpenAI-like API and a Streamlit UI

License

Notifications You must be signed in to change notification settings

phospho-app/template-chatbot-streamlit-openai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Template chatbot Streamlit OpenAI

Template for a simple LLM chatbot using a Streamlit UI, and OpenAI or Mistral as a provider.

The chatbot is a quirky Santa Claus, which uses token streaming, random introductions, user feedback, and logging to phospho.

Demo: --> Click here to chat now with Santa Claus!

Santa Claus chatbot

Architecture

  • streamlit_app.py: Streamlit user interface. Edit this to change the look and feel of the app.
  • agent.py: Chatbot logic and system prompts. Edit this to change the behaviour of the chatbot.

Run locally

  1. Get your OpenAI API key here
  2. Setup your phospho project here
  3. Git clone the project
git clone git@github.com:phospho-app/template-chatbot-streamlit-openai.git
  1. Create a secrets.toml file in the .streamlit folder.
OPENAI_API_KEY="xxx"
MISTRAL_API_KEY="xxx" # Optional, if you set provider to "mistral" in `main.py`
PHOSPHO_PROJECT_ID="xxx"
PHOSPHO_API_KEY="xxx"
  1. Install requirements. You need Python >=3.9
# Optional: create a virtual env
python -m venv .env
# To activate the virtual env on MacOS and Linux:
source .env/bin/activate
# To activate the virtual env on Windows:
source .env/Scripts/activate

# Install requirements
pip install -r requirements.txt
  1. Run!
streamlit run streamlit_app.py

Deploy on Streamlit Community Cloud

The easiest way to deploy the chatbot on internet is with Streamlit Community Cloud.

  1. Fork this repository while connected to your github account. The Fork button is on the top right.

  2. Login or register to Streamlit share with the same github account

  3. On Streamlit share, click on "New App".

streamlit deploy new app

  1. In the form, select your fork of the phospho repo. If you don't see the repo in the list, you can paste the URL.

  2. In the main file path, enter streamlit_app.py

Form streamlit deploy

  1. Click on Advanced Settings, and add the content of the secrets.toml file:
OPENAI_API_KEY="xxx"
PHOSPHO_PROJECT_ID="xxx"
PHOSPHO_API_KEY="xxx"

Add secrets to the Advanced Settings

  1. Hit Save, and click deploy. Streamlit will now deploy your app on internet. Once it's done, click on the Share button on the top-right to share your Santa Claus chatbot.

Share your app

Have a chat with your agent!

Analyze the logs

After talking to your agent, go to the phospho dashboard to see the logs.

Learn more about your app on the phospho dashboard

Run a clustering or create custom analytics to detect specific patterns in conversations.

Get in touch

An issue? Special request? Feel free to reach out to contact@phospho.ai for technical questions, job opportunities, and anything else.

About

Template for a simple chatbot using OpenAI-like API and a Streamlit UI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages