mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
fix: parse ZGCI Qwen JSON routing responses
This commit is contained in:
parent
4c3e759363
commit
c9c1aea47f
2 changed files with 19 additions and 3 deletions
|
|
@ -85,7 +85,7 @@ class LLMProvider(LLMProviderBase):
|
||||||
return catalog
|
return catalog
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_tool_call(result, allowed_names):
|
def _parse_json_object(result):
|
||||||
decoder = json.JSONDecoder()
|
decoder = json.JSONDecoder()
|
||||||
for index, char in enumerate(result or ""):
|
for index, char in enumerate(result or ""):
|
||||||
if char != "{":
|
if char != "{":
|
||||||
|
|
@ -94,6 +94,16 @@ class LLMProvider(LLMProviderBase):
|
||||||
payload, _ = decoder.raw_decode(result[index:])
|
payload, _ = decoder.raw_decode(result[index:])
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
continue
|
continue
|
||||||
|
if isinstance(payload, dict):
|
||||||
|
return payload
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _parse_tool_call(cls, result, allowed_names):
|
||||||
|
payload = cls._parse_json_object(result)
|
||||||
|
if payload is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
name = payload.get("name")
|
name = payload.get("name")
|
||||||
arguments = payload.get("arguments", {})
|
arguments = payload.get("arguments", {})
|
||||||
if isinstance(arguments, str):
|
if isinstance(arguments, str):
|
||||||
|
|
@ -103,6 +113,8 @@ class LLMProvider(LLMProviderBase):
|
||||||
return None
|
return None
|
||||||
if name in allowed_names and isinstance(arguments, dict):
|
if name in allowed_names and isinstance(arguments, dict):
|
||||||
return name, arguments
|
return name, arguments
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _route(self, dialogue, functions):
|
def _route(self, dialogue, functions):
|
||||||
|
|
@ -123,7 +135,9 @@ class LLMProvider(LLMProviderBase):
|
||||||
result = self.router_provider.response_no_stream(
|
result = self.router_provider.response_no_stream(
|
||||||
prompt, context, max_tokens=self.router_max_tokens, temperature=0
|
prompt, context, max_tokens=self.router_max_tokens, temperature=0
|
||||||
)
|
)
|
||||||
payload = json.loads(result.strip())
|
payload = self._parse_json_object(result)
|
||||||
|
if payload is None:
|
||||||
|
raise ValueError("response did not contain a JSON object")
|
||||||
route = payload.get("route")
|
route = payload.get("route")
|
||||||
if route in {"device_tool", "zgc_chat"}:
|
if route in {"device_tool", "zgc_chat"}:
|
||||||
logger.bind(tag=TAG).info(f"LLM router decision: {route}")
|
logger.bind(tag=TAG).info(f"LLM router decision: {route}")
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ logger = setup_logging()
|
||||||
# 需要禁用思考模式的平台域名及其对应参数(默认关闭思考模式)
|
# 需要禁用思考模式的平台域名及其对应参数(默认关闭思考模式)
|
||||||
THINKING_DISABLED_DOMAINS = {
|
THINKING_DISABLED_DOMAINS = {
|
||||||
"aliyuncs.com": {"enable_thinking": False},
|
"aliyuncs.com": {"enable_thinking": False},
|
||||||
"hub.zgci.org": {"enable_thinking": False},
|
# The ZGCI Qwen gateway is backed by vLLM, which reads this setting from
|
||||||
|
# chat template kwargs instead of the top-level OpenAI-compatible field.
|
||||||
|
"hub.zgci.org": {"chat_template_kwargs": {"enable_thinking": False}},
|
||||||
"deepseek.com": {"thinking": {"type": "disabled"}},
|
"deepseek.com": {"thinking": {"type": "disabled"}},
|
||||||
"bigmodel.cn": {"thinking": {"type": "disabled"}},
|
"bigmodel.cn": {"thinking": {"type": "disabled"}},
|
||||||
"moonshot.cn": {"thinking": {"type": "disabled"}},
|
"moonshot.cn": {"thinking": {"type": "disabled"}},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue