metadata
title: langchain-streamlit-demo
emoji: 🦜
colorFrom: green
colorTo: red
sdk: docker
app_port: 7860
pinned: true
tags:
- langchain
- streamlit
- docker
langchain-streamlit-demo
This project shows how to build a simple chatbot UI with Streamlit and LangChain.
This README
was written by Claude 2, an LLM from Anthropic.
Features
- Chat interface for talking to AI assistant
- Supports models from
- OpenAI
gpt-3.5-turbo
gpt-4
- Anthropic
claude-instant-v1
claude-2
- Anyscale Endpoints
meta-llama/Llama-2-7b-chat-hf
meta-llama/Llama-2-13b-chat-hf
meta-llama/Llama-2-70b-chat-hf
- OpenAI
- Streaming output of assistant responses
- Leverages LangChain for dialogue and memory management
- Integrates with LangSmith for tracing conversations
- Allows giving feedback on assistant's responses
- Tries reading API keys and default values from environment variables
Usage
Run on HuggingFace Spaces
With Docker (pull from Docker Hub)
- Optional: Create a
.env
file based on.env-example
- Run in terminal:
docker run -p 7860:7860 joshuasundance/langchain-streamlit-demo:latest
or
docker run -p 7860:7860 --env-file .env joshuasundance/langchain-streamlit-demo:latest
- Open http://localhost:7860 in your browser
Docker Compose
- Clone the repo. Navigate to cloned repo directory
- Optional: Create a
.env
file based on.env-example
- Run in terminal:
docker compose up
or
docker compose up --env-file env
- Run in terminal:
docker compose up
- Open http://localhost:7860 in your browser
Kubernetes
- Clone the repo. Navigate to cloned repo directory
- Create a
.env
file based on.env-example
- Run in terminal:
cd kubernetes && kubectl apply -f resources.yaml
- Get the IP address for your new service:
kubectl get service langchain-streamlit-demo
Configuration
- Select a model from the dropdown
- Optional: Create a
.env
file based on.env-example
, or- Enter an API key for the relevant provider
- Optionally enter a LangSmith API key to enable conversation tracing
- Customize the assistant prompt and temperature
Code Overview
langchain-streamlit-demo/app.py
- Main Streamlit app definitionlangchain-streamlit-demo/llm_stuff.py
- LangChain helper functionsDockerfile
,docker-compose.yml
: Docker deploymentkubernetes/
: Kubernetes deployment files.github/workflows/
: CI/CD workflows
Deployment
The app is packaged as a Docker image for easy deployment. It is published to Docker Hub and Hugging Face Spaces:
CI/CD workflows in .github/workflows
handle building and publishing the image.
Links
TODO
- More customization / parameterization in sidebar