windlass.providers.llm.ollama¶
ollama
¶
Ollama adapter for locally hosted models.
Ollama needs no extra install: it speaks HTTP and Windlass already depends on
httpx. Start the daemon, pull a model, and point Windlass at it::
ollama pull llama3.2
python -c "from windlass import Windlass; print(Windlass.llm('ollama').complete('hi'))"
That makes Ollama the zero-cost, zero-key way to run the whole framework against
a real model — useful for local development and for CI that wants more than the
fake provider.
Example
from windlass import Windlass # doctest: +SKIP Windlass.llm("ollama", model="llama3.2").complete("hi").content # doctest: +SKIP
OllamaLLM
¶
OllamaLLM(
model: str = "",
*,
base_url: str | None = None,
keep_alive: str | None = None,
options: dict[str, Any] | None = None,
**config: Any
)
Bases: LLM
Chat completions against a local Ollama daemon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model tag, e.g. |
''
|
base_url
|
str | None
|
Daemon address. Defaults to |
None
|
keep_alive
|
str | None
|
How long the daemon keeps the model resident, e.g. |
None
|
options
|
dict[str, Any] | None
|
Raw Ollama options ( |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
ProviderError
|
When the daemon is unreachable. The message explains how to start it. |
Performance
The first call after a cold start pays model-load time — often several
seconds. Set keep_alive to keep the model warm between requests.
Source code in src\windlass\providers\llm\ollama.py
default_model
classmethod
¶
native
¶
agenerate
async
¶
agenerate(
messages: list[Message], *, tools: list[dict[str, Any]] | None = None, **kwargs: Any
) -> Completion
Request one chat completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The conversation. |
required |
tools
|
list[dict[str, Any]] | None
|
OpenAI-format tool definitions. Support depends on the model. |
None
|
**kwargs
|
Any
|
Request overrides. |
{}
|
Returns:
| Type | Description |
|---|---|
Completion
|
The completion. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
When the daemon is unreachable or returns an error. |
ProviderTimeoutError
|
When the request exceeds the timeout. |
Source code in src\windlass\providers\llm\ollama.py
astream_generate
async
¶
astream_generate(
messages: list[Message], *, tools: list[dict[str, Any]] | None = None, **kwargs: Any
) -> AsyncIterator[StreamEvent]
Stream a chat completion.
Ollama streams newline-delimited JSON objects rather than SSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list[Message]
|
The conversation. |
required |
tools
|
list[dict[str, Any]] | None
|
OpenAI-format tool definitions. |
None
|
**kwargs
|
Any
|
Request overrides. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamEvent]
|
Text deltas, then tool calls, then |
Source code in src\windlass\providers\llm\ollama.py
alist_models
async
¶
Return the model tags the daemon has pulled.
Returns:
| Type | Description |
|---|---|
list[str]
|
Model tags, e.g. |
Raises:
| Type | Description |
|---|---|
ProviderError
|
When the daemon is unreachable. |