From 2508348a3b176bae7e432b9bb43f68af79f1817b Mon Sep 17 00:00:00 2001 From: Alphaxiaoteng <230277249+Alphaxiaoteng@users.noreply.github.com> Date: Thu, 3 Sep 2026 13:44:23 +0800 Subject: [PATCH] fix(llm): route all DashScope models through native provider DashScope's OpenAI-compatible endpoint serves DeepSeek/Kimi/GLM/etc., not only Qwen. Stop restricting the native match to the qwen* prefix so DASHSCOPE_BASE_URL applies consistently. Fixes #7233. --- lib/crewai/src/crewai/llm.py | 3 ++- .../openai_compatible/test_openai_compatible.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/crewai/src/crewai/llm.py b/lib/crewai/src/crewai/llm.py index c644455184..533b6132a1 100644 --- a/lib/crewai/src/crewai/llm.py +++ b/lib/crewai/src/crewai/llm.py @@ -573,7 +573,8 @@ def _matches_provider_pattern(cls, model: str, provider: str) -> bool: return True if provider == "dashscope": - return model_lower.startswith("qwen") + # DashScope's OpenAI-compatible endpoint serves Qwen plus DeepSeek/Kimi/GLM/etc. + return True if provider == "openrouter": # OpenRouter uses org/model format but accepts anything diff --git a/lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py b/lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py index ce856a5334..1b2975e29b 100644 --- a/lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py +++ b/lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py @@ -271,6 +271,20 @@ def test_llm_creates_openai_compatible_for_dashscope(self): assert isinstance(llm, OpenAICompatibleCompletion) assert llm.provider == "dashscope" + def test_llm_creates_openai_compatible_for_dashscope_non_qwen(self): + """Non-Qwen DashScope models must still use the native OpenAI-compatible path.""" + with patch.dict( + os.environ, + { + "DASHSCOPE_API_KEY": "test-key", + "DASHSCOPE_BASE_URL": "https://my-dashscope.example.com/v1", + }, + ): + llm = LLM(model="dashscope/deepseek-v3") + assert isinstance(llm, OpenAICompatibleCompletion) + assert llm.provider == "dashscope" + assert llm.base_url == "https://my-dashscope.example.com/v1" + def test_llm_with_explicit_provider(self): """Test LLM with explicit provider parameter.""" with patch.dict(os.environ, {"DEEPSEEK_API_KEY": "test-key"}):