fix
This commit is contained in:
parent
22037a4309
commit
19885f5e0b
@ -1,4 +1,6 @@
|
||||
import json
|
||||
import ast
|
||||
import re
|
||||
import logging
|
||||
from typing import List, Dict, Any, Optional, Union, Tuple
|
||||
import requests
|
||||
@ -728,10 +730,26 @@ class InputParser:
|
||||
|
||||
# 处理JSON字符串形式
|
||||
if isinstance(candidate, str):
|
||||
try:
|
||||
candidate = json.loads(candidate)
|
||||
except json.JSONDecodeError:
|
||||
self.logger.warning(f"Schema for '{name}' is a string but not valid JSON; skipping this model.")
|
||||
candidate_str = candidate.strip()
|
||||
if candidate_str:
|
||||
try:
|
||||
candidate = json.loads(candidate_str)
|
||||
except json.JSONDecodeError:
|
||||
fallback_literal = candidate_str
|
||||
fallback_literal = re.sub(r'\bnull\b', 'None', fallback_literal, flags=re.IGNORECASE)
|
||||
fallback_literal = re.sub(r'\btrue\b', 'True', fallback_literal, flags=re.IGNORECASE)
|
||||
fallback_literal = re.sub(r'\bfalse\b', 'False', fallback_literal, flags=re.IGNORECASE)
|
||||
try:
|
||||
candidate = ast.literal_eval(fallback_literal)
|
||||
self.logger.info(
|
||||
f"Schema for '{name}' parsed using ast.literal_eval fallback after JSON decode failure."
|
||||
)
|
||||
except (ValueError, SyntaxError):
|
||||
self.logger.warning(
|
||||
f"Schema for '{name}' is a string but not valid JSON; skipping this model."
|
||||
)
|
||||
candidate = None
|
||||
else:
|
||||
candidate = None
|
||||
|
||||
if isinstance(candidate, dict):
|
||||
@ -741,10 +759,26 @@ class InputParser:
|
||||
else:
|
||||
model = None
|
||||
elif isinstance(raw_model_data, str):
|
||||
try:
|
||||
model = json.loads(raw_model_data)
|
||||
except json.JSONDecodeError:
|
||||
self.logger.warning(f"Schema for '{name}' returned as string is not valid JSON; skipping this model.")
|
||||
raw_model_str = raw_model_data.strip()
|
||||
if raw_model_str:
|
||||
try:
|
||||
model = json.loads(raw_model_str)
|
||||
except json.JSONDecodeError:
|
||||
fallback_literal = raw_model_str
|
||||
fallback_literal = re.sub(r'\bnull\b', 'None', fallback_literal, flags=re.IGNORECASE)
|
||||
fallback_literal = re.sub(r'\btrue\b', 'True', fallback_literal, flags=re.IGNORECASE)
|
||||
fallback_literal = re.sub(r'\bfalse\b', 'False', fallback_literal, flags=re.IGNORECASE)
|
||||
try:
|
||||
model = ast.literal_eval(fallback_literal)
|
||||
self.logger.info(
|
||||
f"Schema for '{name}' string parsed using ast.literal_eval fallback after JSON decode failure."
|
||||
)
|
||||
except (ValueError, SyntaxError):
|
||||
self.logger.warning(
|
||||
f"Schema for '{name}' returned as string is not valid JSON; skipping this model."
|
||||
)
|
||||
model = None
|
||||
else:
|
||||
model = None
|
||||
|
||||
if not isinstance(model, dict):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user