Ollama & local models
Use ollama/<model> to run a bot entirely on your machine. Ollama exposes an OpenAI-compatible API, so DyUI talks to it through the openai SDK, and no API key is needed. Every argument of dyui.llm.stream is on Models & providers.
pip install "dyui[openai]"ollama pull llama3.2DyUI connects to http://localhost:11434/v1. Set OLLAMA_BASE_URL (or pass base_url=) for another host.
Tips for small models
Section titled “Tips for small models”- Keep the catalog short. A smaller catalog is easier to follow:
components=app.catalog.only("table", "stat", "callout", "quick_replies"). - Use fence mode. Most local models handle the
dyuifence well. Tool calling varies by model. - Invalid output is safe. A malformed component becomes a quiet “couldn’t display” chip, and the rest of the answer is kept.
Other local servers
Section titled “Other local servers”Anything that speaks the OpenAI chat completions API works (LM Studio, vLLM, llama.cpp server). Use the openai/ prefix with your server’s URL, and any non-empty key. Inside your handler:
async for part in dyui.llm.stream("openai/local-model", chat.history, components=app.catalog, base_url="http://localhost:1234/v1", api_key="not-needed"): yield partComplete example
Section titled “Complete example”"""A fully local bot. Start Ollama first: ollama pull llama3.2 (serves on localhost:11434)."""import os
import dyui
MODEL = os.getenv("DYUI_MODEL", "ollama/llama3.2")
app = dyui.App(title="Local Bot", description="Runs on your machine via Ollama.", persist=True)
@app.on_messageasync def reply(msg: dyui.Message, chat: dyui.Chat): # Small local models do best with a narrow catalog, which also keeps the prompt short. catalog = app.catalog.only("table", "stat", "callout", "quick_replies") async for part in dyui.llm.stream(MODEL, chat.history, system="You are a helpful assistant.", components=catalog): yield part-
Save it as
local_ollama.pyin a new, empty file, or download it. -
Start Ollama and pull the model:
ollama pull llama3.2. -
Run it:
Terminal window pip install "dyui[openai]"dyui run local_ollama.py -
Open http://localhost:8000. Use another model with
DYUI_MODEL=ollama/<model>in a.envfile.
See also
Section titled “See also”- Models & providers: every argument and provider.