FanHong пре 18 часа
родитељ
комит
ce319fe8a8
1 измењених фајлова са 15 додато и 5 уклоњено
  1. 15 5
      shudao-chat-py/services/qwen_service.py

+ 15 - 5
shudao-chat-py/services/qwen_service.py

@@ -14,14 +14,16 @@ from services.deepseek_service import deepseek_service
 
 class QwenService:
     def __init__(self):
-        # 确保 API URL 包含完整路径
-        base_url = settings.qwen3.api_url.rstrip('/')
-        self.api_url = f"{base_url}/v1/chat/completions"
+        # 兼容配置填写基础域名或完整 chat completions 路径
+        self.api_url = self._normalize_chat_completions_url(
+            settings.qwen3.api_url
+        )
         self.model = settings.qwen3.model
 
         # 意图识别使用专门的配置
-        intent_base_url = settings.intent.api_url.rstrip('/')
-        self.intent_api_url = f"{intent_base_url}/v1/chat/completions"
+        self.intent_api_url = self._normalize_chat_completions_url(
+            settings.intent.api_url
+        )
         self.intent_model = settings.intent.model
 
         self._timeout = httpx.Timeout(120.0, connect=10.0)
@@ -33,6 +35,14 @@ class QwenService:
     async def aclose(self) -> None:
         await self._client.aclose()
 
+    def _normalize_chat_completions_url(self, raw_url: str) -> str:
+        normalized = (raw_url or "").rstrip("/")
+        if normalized.endswith("/chat/completions"):
+            return normalized
+        if normalized.endswith("/v1"):
+            return f"{normalized}/chat/completions"
+        return f"{normalized}/v1/chat/completions"
+
     def _should_fallback(self, status_code: int) -> bool:
         return status_code in (429, 500, 502, 503, 504)