Streamlit Ollama Agent
A reusable Python package that provides a Streamlit-based chat interface for Ollama models using PydanticAI. This package makes it easy to create chat applications with streaming responses and conversation history.
Features
- 🚀 Easy-to-use Streamlit chat interface
- 📝 Streaming responses with real-time updates
- 💬 Conversation history support
- 🔄 Compatible with any Ollama model
- 🛠 Built on PydanticAI for robust type safety
- ⚡ Dual streaming modes: OpenAI compatibility or direct Ollama
Installation
# From PyPI (once published)
pip install streamlit-ollama-agent
Quick Start
- Make sure you have Ollama running locally:
ollama run llama2 # or your preferred model
- Create a new Python file (e.g.,
chat_app.py):
import streamlit as st
from streamlit_ollama_agent import OllamaAgent
# Initialize the agent (using OpenAI compatibility mode)
agent = OllamaAgent(
model_name="llama2", # or your preferred model
base_url="http://localhost:11434/v1"
)
# Or use direct Ollama streaming
agent = OllamaAgent(
model_name="llama2",
use_direct_streaming=True # Bypass OpenAI compatibility for direct Ollama streaming
)
# Create your chat interface
st.title("Chat with Ollama")
# Use the built-in Streamlit app
from streamlit_ollama_agent import create_chat_app
create_chat_app(agent)
- Run your app:
streamlit run chat_app.py
Advanced Usage
Streaming Modes
The package supports two streaming modes:
- OpenAI Compatibility Mode (default):
- Uses OpenAI's API format
- Compatible with other OpenAI-like APIs
- More standardized approach
agent = OllamaAgent(
model_name="llama2",
base_url="http://localhost:11434/v1", # Ollama's OpenAI-compatible endpoint
api_key="ollama" # Not required for Ollama
)
- Direct Ollama Streaming:
- Connects directly to Ollama's native API
- Potentially faster
- Access to Ollama-specific features
agent = OllamaAgent(
model_name="llama2",
use_direct_streaming=True
)
Custom Chat Interface
You can create your own custom chat interface using the OllamaAgent directly:
import asyncio
from streamlit_ollama_agent import OllamaAgent
agent = OllamaAgent()
async def get_response(prompt, history=None):
async for chunk in agent.stream_response(prompt, history):
# Handle each chunk of the response
yield chunk
Configuration Options
agent = OllamaAgent(
model_name="your-model", # Choose your Ollama model
base_url="your-url", # Custom Ollama API URL (OpenAI mode)
api_key="your-key", # If needed (OpenAI mode)
use_direct_streaming=False # Choose streaming mode
)
Project Structure
streamlit-ollama-agent/
├── streamlit_ollama_agent/
│ ├── __init__.py
│ ├── agent.py # OllamaAgent implementation
│ └── app.py # Streamlit app implementation
├── setup.py
├── README.md
└── requirements.txt
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for streamlit-ollama-agent 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_ollama_agent-0.1.1.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_ollama_agent-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.3 kB
Release files / streamlit_ollama_agent-0.1.1.tar.gz
| Download URL | streamlit_ollama_agent-0.1.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65c0a8eabcb2de5c1b88327ce91e659ba28b070f4ca377f8cdb54acffec561e8
|
|
BLAKE2b-256 checksum How to use checksums |
bff49432001e0a209d8a335cb33314e0fe02b34120a0fbf22c3c972dbff454be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / streamlit_ollama_agent-0.1.1-py3-none-any.whl
| Download URL | streamlit_ollama_agent-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
185ffc91f81dec538e9082b248f1f633eb9a4dc65329a210c485aae7223e9e76
|
|
BLAKE2b-256 checksum How to use checksums |
10a214f961f4dabcd4e6b2272a3c38a2a87b3f77177c2a80d8b2dbbb7e9185d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|