A simple, intuitive web-based chat interface for interacting with local language models through the Ollama API. This project provides a lightweight FastAPI backend and a clean, responsive vanilla JavaScript frontend, making it an excellent starting point for building custom AI chat applications.
- Real-time Interaction: Supports both real-time streaming and standard non-streaming chat responses.
- Configurable AI Parameters: Easily configure the model, temperature, and streaming options directly from the web interface.
- Persistent Chat History: Conversations are automatically saved to a local
chatlog.jsonfile, maintaining state between sessions. - Clean & Modern UI: A minimalist, dark-themed user interface built with vanilla HTML, CSS, and JavaScript.
- Robust Backend: Built with FastAPI, providing a high-performance, asynchronous API.
- Comprehensive Test Suite: Includes a full suite of unit tests written with
pytestto ensure reliability. - Easy Setup: Uses Poetry for dependency management, allowing for a quick and straightforward setup process.
- Backend: Python 3.13+, FastAPI, Uvicorn, httpx
- Frontend: HTML5, CSS3, Vanilla JavaScript
- LLM Service: Ollama
- Dependency Management: Poetry
- Testing: pytest, pytest-asyncio, pytest-mock
Before you begin, ensure you have the following installed:
- Python (version 3.13 or higher)
- Poetry (see installation instructions)
- Ollama: The application must be installed and running on your local machine.
- An Ollama Model: You need to have at least one model pulled from the Ollama library. For example:
ollama pull llama3
Follow these steps to get the project running locally.
-
Clone the Repository
git clone https://github.com/your-username/your-repo-name.git cd your-repo-name -
Install Dependencies Use Poetry to install all the required Python packages from the
pyproject.tomlfile.poetry install
-
Run the Application Start the FastAPI server using Uvicorn. The
--reloadflag enables hot-reloading for development.poetry run uvicorn src.main:app --reload
The application will be available at
http://127.0.0.1:8000.
- Open your web browser and navigate to
http://localhost:8000/frontend. - In the settings panel, you can:
- Select the Ollama model you wish to use.
- Adjust the temperature slider to control the AI's creativity.
- Enable or disable streaming responses with the "Stream" checkbox.
- Type your message in the input box and press "Send" to start chatting!
This project includes a comprehensive suite of unit tests to ensure the API is working as expected. To run the tests, execute the following command from the project root:
poetry run pytest.
├── src/
│ ├── main.py # FastAPI application, API endpoints, and business logic
│ └── frontend/
│ ├── index.html # The main HTML file for the UI
│ └── script.js # JavaScript for frontend logic and API communication
├── tests/
│ └── test_main.py # Unit tests for the FastAPI application
├── pyproject.toml # Project metadata and dependencies for Poetry
├── poetry.lock # Exact versions of dependencies
└── README.md # This file
This project is licensed under the MIT License.
