title: ChatBotDocker
emoji: 🐳
colorFrom: purple
colorTo: gray
sdk: docker
app_port: 7860
ChatBot
A full-stack chatbot which uses a LLM as its core and gradio
as UI. Demo: https://huggingface.co/spaces/nblong/chatbot
TechStack
Tech:
- LangChain/LangGraph: Call LLM and define the workflow of agent
- ChromaDB: Store embedded vector
- GitHub Action: Use for CI
- DockerHub and HuggingFace (HF) Space: Use for CD
CI/CD flow: On every push to
main
branch, GitHubAction starts CI process. If CI process is successful, it starts 2 actions parallel- Build image and push to DockerHub
- Push code to HF Space. HF Space utilizes
Dockerfile
to build and run image
Dependency stuff
- Since there are a lot dependencies and resolving their version takes lots of time, I use
pip-compile
to resolve them before pushing everything to GitHub.pip-compile
takerequirements.in
as input and return arequirements.txt
. Just specify needed packages inrequirements.in
(without version) andpip-compile requirements.in
Run locally
Pull image from DockerHub
Config file
.env
as follows to run the image:GOOGLE_API_KEY=<key> TAVILY_API_KEY=<key> PYTHONPATH=/app/src # so you can run code from `/app/src`
Note that
.env
file can containsingle/double quote
but only use fordocker compose up
(which means that you have to config acompose.yml
). Otherwise, you should not usequote
since we can run as follows:docker run --env-file .env --name ctn_chatbot -p 5555:7860 baolongnguyenmac/chatbot
In case you want to run via
compose.yml
, config the compose file as follows:services: chatbot: image: baolongnguyenmac/chatbot container_name: ctn_chatbot env_file: - .env ports: - 5555:7860
- Then
docker compose up
- Then
Demo link at local:
localhost:5555
CI using GitHub Action
Create 2 secrets to store these keys in GitHub Secret. In the workflow file
./.github/workflows/main.yml
, specify the environment byruns-on: ubuntu-latest env: GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} TAVILY_API_KEY: ${{ secrets.TAVILY_API_KEY }}
Storing secret to GitHub Secret or Hugging Face Secret means that these secrets will be exported to system variable at runtime
CD to DockerHub
- Create a PAT so GitHubAction can push image to DockerHub
- Save this token to GitHub Secret and specify username of DockerHub account
- Setup
main.yml
(build_and_push_docker
)
CD to HF Space
- Create a Space (specify to use Docker)
- Add the content in the file
.env
to Secret and Variable in the space. These secrets and variables will be exported to be system variable at runtime - Setup
main.yml
(push_HF_space
)