Skip to main content

Production helpers for running Ollama under concurrent load across local and remote endpoints.

Project description

ollama-orchestra

CI PyPI License: MIT Python

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.

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 (stripping `<think>` blocks by default)
+
 ## Health and prewarm

```python
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.md explains Ollama's top-level think: false gotcha.
  • docs/production-patterns.md documents concurrency, round-robin, prewarm, and fallback patterns.
  • examples/reasoning_chat.py calls Ollama chat with reasoning disabled.
  • examples/multi_endpoint_embeddings.py demonstrates embedding fallback across endpoints.
  • examples/semaphore_pool.py demonstrates 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ollama_orchestra-0.1.6.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ollama_orchestra-0.1.6-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file ollama_orchestra-0.1.6.tar.gz.

File metadata

  • Download URL: ollama_orchestra-0.1.6.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ollama_orchestra-0.1.6.tar.gz
Algorithm Hash digest
SHA256 d6c53301b5fe4c39f38df02ccb0ffdee6e504bfca72d3b6e3f66636aa586df16
MD5 9db381f50a06dba3de4477df4229d342
BLAKE2b-256 a4ce42e394c288ebdc7f5372342d1a46efea2e44bee620b78c21ad6ed2980bbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_orchestra-0.1.6.tar.gz:

Publisher: publish.yml on BenjaminJornet/ollama-orchestra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ollama_orchestra-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for ollama_orchestra-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 55147a4cacf52273899799da36a49af1a39a358eb306ec32219219ce8b1af7ad
MD5 a31ddd539a19b2b89872d8947042d36f
BLAKE2b-256 53e3e6491fb4bea590f994da5208dd886009bb17396a489a9b16a86253318bb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ollama_orchestra-0.1.6-py3-none-any.whl:

Publisher: publish.yml on BenjaminJornet/ollama-orchestra

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page