A conversational chat interface where users can interact with the Llama-3
language model, and the conversation history is logged in MongoDB
for future reference.
-
Language Model Integration: The app integrates the
Llama-3
language model (LLM) for natural language processing. The model is initialized with a specifiedOllama
model and a callback manager for handling streaming standard output. -
User Interface: The app's user interface is created using
Streamlit
. Users can input messages through the chat input interface. User messages are displayed in the chat, and the messages are added to the chat history. -
Chat Initialization: The app starts with an initial prompt in the chat in
Langchain
, displaying a greeting message. The chat history is initialized if it doesn't exist in the session state. -
MongoDB Integration: The app connects to
MongoDB
'sAtlas
server. It retrieves the collection name and displays chat messages from the database on app rerun. The messages are fetched and displayed in the chat history container. -
Response Processing: The app processes user input by obtaining a response from the Ollama language model. The response is then displayed in the chat interface, and the messages are added to the chat history.
-
Streaming Simulation: The app simulates the streaming of the AI's response with a spinner to indicate processing. It adds a delay to simulate a more dynamic chat experience.
-
MongoDB Logging: All user and AI messages are inserted into the
MongoDB
collection for logging and retrieval.
- Install requirements:
pip install -r requirements.txt
- Install and run Ollama: https://python.langchain.com/docs/integrations/llms/ollama
- Fetch a model via
ollama pull <model family>
e.g., for Llama 3:
ollama pull llama3
- Place your Environment variables in the
.env
file. - Run the app:
streamlit run app.py
- Visit http://localhost:8501 on your browser.
- LangChain: https://python.langchain.com/docs/get_started/introduction
- Ollama: https://ollama.ai/library/codellama
- MongoDB: https://www.mongodb.com
- Streamlit: https://streamlit.io