Skip to content

Repository files navigation

Chatbot Workspace

This project contains two related chatbot apps built on top of Ollama and Streamlit:

  • A simple persona-based chat app using a Flask API and a Streamlit frontend
  • A RAG-powered chatbot studio that can ingest documents, build embeddings, and answer questions from retrieved context

The code in this folder is implemented across several Python files and follows a lightweight local-first architecture.

Project structure

  • base_api.py — Minimal Flask API for chatting with Ollama using personas
  • base_chatbot.py — Streamlit UI for the basic chatbot
  • rag_core.py — Core business logic for chatbot creation, indexing, document parsing, embeddings, and retrieval
  • rag_api.py — Flask API for the RAG chatbot application
  • rag_chatbot.py — Streamlit frontend for the RAG chatbot studio
  • personas.json — Persona definitions used by the base chat app
  • data/ — Stores chatbot metadata, uploaded files, conversation logs, and vector indexes

1) Basic chat app

The basic setup is a simple local chat interface:

  • base_api.py exposes a Flask API on port 5005
  • base_chatbot.py connects to that API from Streamlit
  • It uses Ollama for model inference and personas.json for system prompts

Features

  • Health check endpoint for Ollama connectivity
  • Persona listing endpoint
  • Streaming chat responses from Ollama
  • Persona-aware system prompt injection
  • Simple chat UI with model and temperature controls

Base API endpoints

base_api.py includes:

  • GET /status
    Returns whether Ollama is reachable and the available models.

  • GET /personas
    Returns the list of personas from personas.json.

  • POST /chat
    Accepts a request body like:

{
  "model": "llama3",
  "persona_id": "general",
  "messages": [{ "role": "user", "content": "Hello" }],
  "temperature": 0.7
}

The server prepends the selected persona's system prompt before sending the conversation to Ollama.

Run the basic app

  1. Start Ollama:
ollama serve
  1. Pull the model you want to use, for example:
ollama pull llama3
  1. Start the API:
python base_api.py
  1. Run the UI:
streamlit run base_chatbot.py

2) RAG chatbot studio

The RAG implementation is more advanced and is centered around rag_core.py.

It supports:

  • chatbot creation
  • uploading a source file
  • parsing and chunking supported document types
  • generating embeddings with Ollama embedding models
  • storing a vector-style index on disk
  • retrieving the most relevant chunks at query time
  • composing a final answer using an LLM and the retrieved context
  • persisting chat history and source references

Core responsibilities in rag_core.py

  • Creates and lists chatbot definitions
  • Validates uploaded knowledge files
  • Reads supported file types such as PDF, DOCX, TXT, MD, CSV, TSV, XLSX, JSON, HTML, and XML
  • Splits text into overlapping chunks
  • Uses LangChain-compatible document objects and embedding models
  • Stores document and embedding payloads under data/vectorstores/
  • Maintains conversations in data/conversations/
  • Uses Ollama for both embeddings and LLM completion

Supported ingestion formats

The ingestion logic recognizes many common file types, including:

  • text: .txt, .md, .py, .js, .ts, .tsx, .jsx, .json, .jsonl
  • markup: .html, .htm, .xml
  • tables: .csv, .tsv, .xlsx, .xls, .xlsm, .xltx, .xltm
  • documents: .pdf, .doc, .docx, .rtf, .odt

Default model configuration

The service defaults to:

  • LLM: tinyllama
  • Embedding model: mxbai-embed-large

These values are defined in rag_core.py and can be overridden when creating a chatbot.

RAG API endpoints

rag_api.py exposes these endpoints:

  • GET /health
    Simple health check

  • GET /status/services
    Returns FastAPI/Flask status and Ollama reachability

  • GET /chatbots
    Lists all saved chatbots

  • GET /chatbots/<chatbot_id>
    Fetches one chatbot's metadata

  • POST /chatbots/stream-create
    Creates a chatbot and streams progress events as SSE

  • POST /chatbots/<chatbot_id>/index
    Ensures the embedding index is built

  • GET /chatbots/<chatbot_id>/conversation
    Returns the conversation history

  • POST /chatbots/<chatbot_id>/messages
    Saves a message with optional sources

  • POST /chatbots/<chatbot_id>/chat
    Sends a question to the chatbot and returns the answer plus sources

RAG flow

The workflow is:

  1. Upload or select a source file
  2. Parse and extract text content
  3. Chunk the text into smaller segments
  4. Embed each chunk with Ollama embeddings
  5. Store the documents and embeddings on disk
  6. At query time, retrieve the most relevant chunks
  7. Pass those chunks as context to the Ollama LLM
  8. Save the user and assistant messages with source references

3) Streamlit frontend for the RAG app

rag_chatbot.py provides the UI:

  • Home page shows all available chatbots
  • Create page lets you upload a knowledge source and configure models
  • Chat page lets you ask questions against a selected chatbot
  • Source references are shown in expandable sections with metadata

It talks to the Flask API on http://127.0.0.1:8000 by default.

Run the RAG app

  1. Start Ollama:
ollama serve
  1. Pull the necessary models:
ollama pull tinyllama
ollama pull mxbai-embed-large
  1. Start the RAG API:
python rag_api.py
  1. Start the UI:
streamlit run rag_chatbot.py

4) Data folders

The workspace includes a data/ folder with:

  • chatbots.json — metadata for saved chatbots
  • conversations/ — per-chatbot conversation logs
  • uploads/ — uploaded knowledge files
  • vectorstores/ — embedding/index payloads stored as JSON

These files are created and updated at runtime by rag_core.py.


5) Prerequisites

Install the Python dependencies required by the project, including:

pip install flask requests streamlit pydantic ollama langchain-core langchain-ollama

Depending on the file types you want to ingest, you may also need:

pip install pandas python-docx pdfplumber beautifulsoup4

For spreadsheet, docx, PDF, and HTML parsing, the optional packages above are used by the ingestion layer.


6) Typical usage

There are two common workflows in this repo:

Simple local chatbot

python base_api.py
streamlit run base_chatbot.py

Use this for direct persona-based chat against Ollama.

Knowledge Q&A chatbot

python rag_api.py
streamlit run rag_chatbot.py

Use this to create a bot from a file, build its index, and ask questions using retrieved document context.


7) Notes

  • The project is designed for local development and uses local Ollama models.
  • rag_core.py is the core engine and is what powers both indexing and retrieval.
  • The app stores state in the local filesystem rather than a database.
  • This repo is a lightweight prototype for experimenting with local LLMs and retrieval-augmented chat workflows.

About

(❌) two related chatbot apps built on top of Ollama and Streamlit

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages