Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: fill the context bar for Ollama connections (#13106)

Nilaydbf0db10db99
diff --git a/studio/backend/core/inference/external_provider.py b/studio/backend/core/inference/external_provider.py
index 9de1262a8b6..ff77691174c 100644
--- a/studio/backend/core/inference/external_provider.py
+++ b/studio/backend/core/inference/external_provider.py
@@ -38,21 +38,20 @@ from models.providers import (
validate_provider_reasoning_contract,
)
-# Local servers, not hosted APIs: each applies the model's own chat template on the way in, so a prompt built here is
-# templated just like an in-process one (#7066). "custom" is a user-supplied OpenAI-compatible base_url, i.e. how a
-# self-hosted vLLM or llama.cpp registers without its preset. Unknown endpoint means assume a template applies:
-# sweeping a hosted API costs a space in delimiter-like text, not sweeping a local one costs a forged turn.
+# custom endpoints are treated as local because skipping their chat template can forge a turn (#7066).
_TEMPLATE_APPLYING_PROVIDERS = frozenset({"vllm", "llama_cpp", "ollama", "custom", "lemonade"})
# only vLLM and llama.cpp document both continuation flags on /v1/chat/completions.
_CONTINUATION_FLAG_PROVIDERS = frozenset({"vllm", "llama_cpp"})
# custom may reject include_usage; OpenAI Responses supplies usage, while listed streams require it.
-_USAGE_STREAM_OPTION_PROVIDERS = frozenset({"vllm", "llama_cpp", "openrouter", "kimi", "lemonade"})
+_USAGE_STREAM_OPTION_PROVIDERS = frozenset(
+ {"vllm", "llama_cpp", "ollama", "openrouter", "kimi", "lemonade"}
+)
# launch-time windows are absent from catalogues; custom covers unregistered self-hosted servers.
_SERVED_WINDOW_PROVIDERS = frozenset({"vllm", "llama_cpp", "custom"})
-# refresh quickly enough to detect a server restart within one or two turns.
+# refresh within one or two turns to detect server restarts.
_SERVED_WINDOW_TTL_S = 60.0
_SERVED_WINDOW_TIMEOUT_S = 5.0
_served_windows: dict[tuple[str, str, str], tuple[float, Optional[int]]] = {}
diff --git a/studio/backend/tests/test_external_provider_stream_usage_opt_in.py b/studio/backend/tests/test_external_provider_stream_usage_opt_in.py
index 6a7b1c7e758..8c5c890134e 100644
--- a/studio/backend/tests/test_external_provider_stream_usage_opt_in.py
+++ b/studio/backend/tests/test_external_provider_stream_usage_opt_in.py
@@ -93,14 +93,20 @@ def test_only_an_opted_in_caller_receives_the_usage_chunk():
def test_a_llama_cpp_connection_receives_the_usage_chunk():
- # The chat context bar reads prompt_tokens from this chunk, not from llama-server timings.
+ # the chat context bar reads prompt_tokens from this chunk instead of llama-server timings.
opted_in, body = _proxy("llama_cpp", stream_options = {"include_usage": True})
assert body["stream_options"] == {"include_usage": True}
assert _usage_chunks(opted_in) == [_USAGE]
+def test_an_ollama_connection_receives_the_usage_chunk():
+ opted_in, body = _proxy("ollama", stream_options = {"include_usage": True})
+ assert body["stream_options"] == {"include_usage": True}
+ assert _usage_chunks(opted_in) == [_USAGE]
+
+
def test_the_opt_in_does_not_reach_a_custom_endpoint():
- # "custom" is never asked for usage upstream: a strict endpoint 400s on the field.
+ # custom endpoints omit upstream usage requests because strict endpoints reject the field with HTTP 400.
_, opted_in = _proxy("custom", stream_options = {"include_usage": True})
_, plain = _proxy("custom")
assert opted_in == plain
diff --git a/studio/backend/tests/test_external_provider_usage_chunk.py b/studio/backend/tests/test_external_provider_usage_chunk.py
index d17d7cfff2e..8a4308e16b0 100644
--- a/studio/backend/tests/test_external_provider_usage_chunk.py
+++ b/studio/backend/tests/test_external_provider_usage_chunk.py
@@ -733,16 +733,14 @@ def test_other_providers_do_not_get_the_continuation_flags(monkeypatch, provider
("openrouter", True),
("kimi", True),
("llama_cpp", True),
- # Any user-supplied base_url: a strict endpoint 400s on an unknown field.
+ ("ollama", True),
+ # user-supplied base_url endpoints may reject the unknown field with a 400.
("custom", False),
- ("ollama", False),
- # "openai" is absent: it routes to /v1/responses, which reports usage itself.
+ # "openai" is absent because /v1/responses reports usage.
],
)
def test_streamed_usage_is_requested_only_where_documented(monkeypatch, provider_type, expected):
- # An OAI-compatible stream omits usage without stream_options.include_usage, and
- # these providers report no llama.cpp timings, so the monitor has no token count to
- # derive a speed from and the row shows a blank Speed for every completed request.
+ # include_usage supplies token counts when compatible providers expose no llama.cpp timings.
captured: dict = {}
def handler(request: httpx.Request) -> httpx.Response: