Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
fix(vlm): send Ollama num_ctx as a top-level option (#5033)
Yohanes95564021e0c4
diff --git a/openviking/models/vlm/backends/litellm_vlm.py b/openviking/models/vlm/backends/litellm_vlm.pyindex f9bcc0b7f..7040c1ee4 100644--- a/openviking/models/vlm/backends/litellm_vlm.py+++ b/openviking/models/vlm/backends/litellm_vlm.py@@ -315,9 +315,16 @@ class LiteLLMVLMProvider(VLMBase):# truncates long prompts to its 4096-token default; thinking models left# in thinking mode emit only reasoning and stall on CPU. Set safe# defaults, but let extra_request_body override either.+ #+ # ``num_ctx`` must be a top-level argument, not part of ``extra_body``:+ # LiteLLM forwards ``extra_body`` verbatim as top-level JSON while Ollama+ # only reads ``num_ctx`` from ``options``, so an ``extra_body`` value is+ # silently ignored and the window stays at the 4096 default. ``think`` is+ # accepted top-level by Ollama either way.if _has_litellm_prefix(model, OLLAMA_LITELLM_PREFIXES):extra = kwargs.get("extra_body", {})- extra.setdefault("num_ctx", OLLAMA_DEFAULT_NUM_CTX)+ num_ctx = extra.pop("num_ctx", None)+ kwargs["num_ctx"] = num_ctx if num_ctx is not None else OLLAMA_DEFAULT_NUM_CTXextra.setdefault("think", self._effective_thinking(thinking))kwargs["extra_body"] = extradiff --git a/tests/unit/test_extra_headers_vlm.py b/tests/unit/test_extra_headers_vlm.pyindex 46e35c144..2c2681ce6 100644--- a/tests/unit/test_extra_headers_vlm.py+++ b/tests/unit/test_extra_headers_vlm.py@@ -8,6 +8,7 @@ import threadingfrom unittest.mock import AsyncMock, MagicMock, patchimport httpx+from litellm.llms.ollama.chat.transformation import OllamaChatConfigfrom openai import OpenAIfrom openviking.models.vlm.backends.litellm_vlm import (@@ -531,7 +532,10 @@ class TestVLMExtraRequestBody:kwargs = vlm._build_text_kwargs(prompt="hello")# Ollama models also get a default num_ctx; the explicit think is kept.- assert kwargs["extra_body"] == {"think": False, "num_ctx": 16384}+ # num_ctx must be top-level so LiteLLM maps it into Ollama's `options`;+ # inside extra_body it is forwarded verbatim and silently ignored.+ assert kwargs["num_ctx"] == 16384+ assert kwargs["extra_body"] == {"think": False}def test_ollama_defaults_num_ctx_and_think(self):"""Ollama models get a larger context window and thinking disabled by default."""@@ -545,7 +549,8 @@ class TestVLMExtraRequestBody:kwargs = vlm._build_text_kwargs(prompt="hello")- assert kwargs["extra_body"] == {"num_ctx": 16384, "think": False}+ assert kwargs["num_ctx"] == 16384+ assert kwargs["extra_body"] == {"think": False}def test_ollama_extra_request_body_overrides_num_ctx(self):"""An explicit num_ctx in extra_request_body is not overridden by the default."""@@ -560,7 +565,40 @@ class TestVLMExtraRequestBody:kwargs = vlm._build_text_kwargs(prompt="hello")- assert kwargs["extra_body"] == {"num_ctx": 32768, "think": False}+ assert kwargs["num_ctx"] == 32768+ assert "num_ctx" not in kwargs["extra_body"]+ assert kwargs["extra_body"] == {"think": False}++ def test_ollama_num_ctx_lands_in_ollama_options_on_the_wire(self):+ """The request LiteLLM actually sends must carry num_ctx under `options`.++ Asserting the built kwargs only proves where OV puts the value; this+ checks the field Ollama reads, which is what #5030 is about.+ """+ vlm = LiteLLMVLMProvider(+ {+ "model": "ollama/qwen3.5:4b",+ "provider": "litellm",+ "api_base": "http://127.0.0.1:11434",+ "extra_request_body": {"num_ctx": 32768},+ }+ )+ kwargs = vlm._build_text_kwargs(prompt="hello")++ body = OllamaChatConfig().transform_request(+ model="qwen3.5:4b",+ messages=kwargs["messages"],+ optional_params={+ k: v+ for k, v in kwargs.items()+ if k not in ("model", "messages", "timeout", "api_key", "api_base")+ },+ litellm_params={},+ headers={},+ )++ assert body["options"]["num_ctx"] == 32768+ assert "num_ctx" not in bodydef test_non_ollama_model_gets_no_num_ctx(self):"""num_ctx is Ollama-specific and must not leak into other providers."""