ollama-orchestra
Production helpers for running Ollama under concurrent load.
Ollama is excellent for local models, but production pipelines quickly hit coordination problems: one GPU should usually receive one request at a time, multi-GPU ingestion needs endpoint rotation, embedding endpoints need fallback, and reasoning models may burn their token budget before producing visible content.
ollama-orchestra packages those patterns into small async utilities.
Install
uv add ollama-orchestra
Concurrency control
from ollama_orchestra import OllamaSemaphorePool, RoundRobinOllama
pool = OllamaSemaphorePool(local_hosts={"gpu-a.local", "gpu-b.local"})
rr = RoundRobinOllama(["http://gpu-a.local:11434", "http://gpu-b.local:11434"])
url = await rr.next_url()
async with pool.semaphore(url):
# Call your Ollama client here. Local Ollama endpoints default to 1 slot.
...
Ports 11434 are treated as local Ollama endpoints by default. Other URLs default to higher concurrency for OpenAI-compatible gateways or cloud APIs.
Reasoning models gotcha
Some Ollama reasoning models can spend the whole num_predict budget inside hidden reasoning and return an empty visible message with done_reason: "length".
Ollama expects think: false at the top level of the request body, not inside options.
from ollama_orchestra import chat
result = await chat(
"http://localhost:11434",
"your-model",
[{"role": "user", "content": "Summarize this log"}],
think=False,
num_predict=256,
)
The helper also strips leftover <think>, <reasoning>, <thought>, and simple Markdown fences from returned content by default.
For streaming responses, use stream_chat():
from ollama_orchestra import stream_chat
async for chunk in stream_chat(
"http://localhost:11434",
"your-model",
[{"role": "user", "content": "Summarize this log"}],
think=False,
):
print(chunk)
Embeddings with fallback
from ollama_orchestra import EmbeddingService
service = EmbeddingService(
model="your-embedding-model",
urls=["http://gpu-a.local:11434", "http://gpu-b.local:11434"],
)
vector = await service.embed_text("Long text is chunked and mean-pooled automatically.")
await service.close()
Features:
- endpoint fallback
- endpoint scoring based on success, failure, and latency
- per-endpoint circuit breakers
- temporary quarantine for failing endpoints
- optional alert callback
- long-text chunking and mean pooling
Orchestrated Chat
To route chat and reasoning requests across multiple endpoints with concurrency controls and endpoint scoring, use OrchestratedChat:
from ollama_orchestra import OrchestratedChat
service = OrchestratedChat(
model="your-reasoning-model",
urls=["http://gpu-a.local:11434", "http://gpu-b.local:11434"],
)
response = await service.chat([{"role": "user", "content": "Explain this alert"}], think=False)
Features:
- endpoint fallback and scoring
- concurrency pool integration (
OllamaSemaphorePool) - circuit breakers and quarantine
- reasoning stripping (
<think>blocks are stripped by default)
Use endpoint_status() to inspect the current routing scores and quarantine state:
for endpoint in service.endpoint_status():
print(endpoint["url"], endpoint["score"], endpoint["quarantined"])
Health and prewarm
from ollama_orchestra import check_server_health, prewarm_all_servers
healthy = await check_server_health("http://localhost:11434")
status = await prewarm_all_servers(["http://localhost:11434"], model="your-model")
Documentation and examples
docs/reasoning-models.mdexplains Ollama's top-levelthink: falsegotcha.docs/production-patterns.mddocuments concurrency, round-robin, prewarm, and fallback patterns.examples/reasoning_chat.pycalls Ollama chat with reasoning disabled.examples/multi_endpoint_embeddings.pydemonstrates embedding fallback across endpoints.examples/semaphore_pool.pydemonstrates per-endpoint concurrency control.
Roadmap
- Adaptive concurrency based on latency and endpoint health.
- Streaming chat helper.
- Additional gateway-compatible health checks.
Metrics hooks
Both semaphore and embedding workflows accept optional callbacks for lightweight instrumentation:
events = []
pool = OllamaSemaphorePool(metrics_cb=events.append)
service = EmbeddingService("your-embedding-model", ["http://localhost:11434"], metrics_cb=events.append)
Events are dictionaries with an event key, such as semaphore_acquired, embedding_failure, or embedding_endpoint_quarantined.
Development
uv sync --dev
uv run ruff check .
uv run pytest
uv run python scripts/smoke.py
uv build
License
MIT
Metadata
Release files for ollama-orchestra 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ollama_orchestra-0.1.8.tar.gz | 26.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ollama_orchestra-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.1 kB
Release files / ollama_orchestra-0.1.8.tar.gz
| Download URL | ollama_orchestra-0.1.8.tar.gz |
|---|---|
| Size | 26.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00d2a1451c95435afba70277a5a39ea34c570d1f297a8690c3ba4f2fcd4d451b
|
|
BLAKE2b-256 checksum How to use checksums |
c283970d4ad6c1e731622a9e2b74677c6746d8c3d0e7166fc3a67300c707bcac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 3, 2026.
Transparency logRelease files / ollama_orchestra-0.1.8-py3-none-any.whl
| Download URL | ollama_orchestra-0.1.8-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
37e007187e1bae89e97149e1b72d88be85ed9e7d9520ce14655c4a3c85da31fe
|
|
BLAKE2b-256 checksum How to use checksums |
24bad675ac3709a3fcc82780fe9f2bc260b0c0088df71a37799efb5aec093ab9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 3, 2026.
Transparency log