Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(vlm): preserve explicit Ollama chat routes (#4898)

Evo9c921cc8817e
diff --git a/openviking/models/vlm/backends/litellm_vlm.py b/openviking/models/vlm/backends/litellm_vlm.py
index 5cbec4d0e..f9bcc0b7f 100644
--- a/openviking/models/vlm/backends/litellm_vlm.py
+++ b/openviking/models/vlm/backends/litellm_vlm.py
@@ -195,7 +195,7 @@ class LiteLLMVLMProvider(VLMBase):
"""Resolve model name by applying provider prefixes."""
if _has_litellm_prefix(model, EXPLICIT_LITELLM_PREFIXES):
return model
- if model.lower().startswith("openai/"):
+ if model.lower().startswith(("openai/", *OLLAMA_LITELLM_PREFIXES)):
return model
provider = self._detected_provider or detect_provider_by_model(model)
diff --git a/tests/unit/test_litellm_vlm_provider_detection.py b/tests/unit/test_litellm_vlm_provider_detection.py
index 0b2918952..ed0e4a2b4 100644
--- a/tests/unit/test_litellm_vlm_provider_detection.py
+++ b/tests/unit/test_litellm_vlm_provider_detection.py
@@ -2,9 +2,12 @@
# SPDX-License-Identifier: AGPL-3.0
"""Tests for LiteLLM VLM provider detection and model prefix resolution."""
+import asyncio
import os
+from unittest.mock import AsyncMock, Mock
import pytest
+from litellm import ModelResponse
from openviking.models.vlm.backends.litellm_vlm import (
LiteLLMVLMProvider,
@@ -73,3 +76,43 @@ class TestLiteLLMVLMProviderDetection:
)
def test_existing_provider_detection_still_matches(self, model, provider):
assert detect_provider_by_model(model) == provider
+
+
+ "model", ["ollama_chat/qwen2.5:7b", "ollama/qwen2.5:7b", "openai/qwen2.5:7b"]
+)
[email protected]("api_key", [None, "test-key"])
[email protected]("api_base", [None, "http://localhost:11434"])
[email protected]("extra_body", [{}, {"num_ctx": 32768, "think": True}])
+def test_explicit_local_routes_reach_completion_unchanged(
+ monkeypatch, model, api_key, api_base, extra_body
+):
+ monkeypatch.setenv("OLLAMA_API_KEY", "")
+ monkeypatch.setenv("DASHSCOPE_API_KEY", "")
+ provider = LiteLLMVLMProvider(
+ {
+ "provider": "litellm",
+ "model": model,
+ "api_key": api_key,
+ "api_base": api_base,
+ "extra_request_body": extra_body,
+ }
+ )
+ tools = [{"type": "function", "function": {"name": "read", "parameters": {"type": "object"}}}]
+ response = ModelResponse(choices=[{"message": {"role": "assistant", "content": "ok"}}])
+ sync_call = Mock(return_value=response)
+ async_call = AsyncMock(return_value=response)
+ monkeypatch.setattr("openviking.models.vlm.backends.litellm_vlm.completion", sync_call)
+ monkeypatch.setattr("openviking.models.vlm.backends.litellm_vlm.acompletion", async_call)
+
+ provider.get_completion(prompt="test", tools=tools)
+ asyncio.run(provider.get_completion_async(prompt="test", tools=tools))
+
+ for call in (sync_call, async_call):
+ kwargs = call.call_args.kwargs
+ assert kwargs["model"] == model
+ assert kwargs["tools"] == tools
+ assert kwargs.get("api_key") == api_key
+ assert kwargs.get("api_base") == api_base
+ if model.startswith(("ollama/", "ollama_chat/")):
+ assert kwargs["extra_body"] == {"num_ctx": 16384, "think": False} | extra_body