fix: 兼容 mimo-v2.5 返回 JSON 数组而非对象的格式
- intent_analyzer._parse_json: 解析结果为 list 时取第一个 dict 元素 - llm_utils.parse_json_from_response: 同样处理 list 返回值 - 修复日志错误: 'list' object has no attribute 'get'
This commit is contained in:
@@ -529,7 +529,16 @@ class IntentAnalyzer:
|
||||
"""解析 JSON 响应"""
|
||||
# 尝试直接解析
|
||||
try:
|
||||
return json.loads(content)
|
||||
parsed = json.loads(content)
|
||||
# mimo 等模型可能返回 JSON 数组而非对象,取第一个元素
|
||||
if isinstance(parsed, list) and len(parsed) > 0:
|
||||
first = parsed[0]
|
||||
if isinstance(first, dict):
|
||||
return first
|
||||
return None
|
||||
if isinstance(parsed, dict):
|
||||
return parsed
|
||||
return None
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -245,7 +245,13 @@ def parse_json_from_response(content: str) -> Optional[dict]:
|
||||
json_str = json_match.group(1) if json_match else content
|
||||
|
||||
try:
|
||||
return json.loads(json_str.strip())
|
||||
parsed = json.loads(json_str.strip())
|
||||
# mimo 等模型可能返回 JSON 数组而非对象,取第一个元素
|
||||
if isinstance(parsed, list) and len(parsed) > 0 and isinstance(parsed[0], dict):
|
||||
return parsed[0]
|
||||
if isinstance(parsed, dict):
|
||||
return parsed
|
||||
return None
|
||||
except (json.JSONDecodeError, TypeError, ValueError):
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user