Skip to content

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.

Terminal window
pip install "dyui[openai]"
ollama pull llama3.2

DyUI connects to http://localhost:11434/v1. Set OLLAMA_BASE_URL (or pass base_url=) for another host.

  • 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 dyui fence 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.

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 part
local_ollama.py
"""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_message
async 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
  1. Save it as local_ollama.py in a new, empty file, or download it.

  2. Start Ollama and pull the model: ollama pull llama3.2.

  3. Run it:

    Terminal window
    pip install "dyui[openai]"
    dyui run local_ollama.py
  4. Open http://localhost:8000. Use another model with DYUI_MODEL=ollama/<model> in a .env file.

DyUI Docs assistant

Answers come from the DyUI docs. gpt-oss-120b via Groq. Press Escape or the close button to return to the page.