更新了响应形式
This commit is contained in:
parent
d04e406972
commit
28ff0979c1
Binary file not shown.
Binary file not shown.
@ -146,3 +146,4 @@ class TopicGenerator:
|
|||||||
return topics
|
return topics
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ class TopicParser:
|
|||||||
# 验证每个选题是否包含所有必需的键
|
# 验证每个选题是否包含所有必需的键
|
||||||
valid_topics = []
|
valid_topics = []
|
||||||
required_keys = {"index", "date", "logic", "object", "product", "style", "target_audience"}
|
required_keys = {"index", "date", "logic", "object", "product", "style", "target_audience"}
|
||||||
|
optional_keys = {"product_logic", "style_logic", "target_audience_logic"}
|
||||||
|
|
||||||
for i, item in enumerate(parsed_json):
|
for i, item in enumerate(parsed_json):
|
||||||
if isinstance(item, dict) and required_keys.issubset(item.keys()):
|
if isinstance(item, dict) and required_keys.issubset(item.keys()):
|
||||||
|
|||||||
Binary file not shown.
@ -202,14 +202,12 @@ def process_llm_json_text(text: Any) -> Optional[Dict[str, Any]]:
|
|||||||
for candidate in json_candidates:
|
for candidate in json_candidates:
|
||||||
# 直接尝试解析
|
# 直接尝试解析
|
||||||
try:
|
try:
|
||||||
import json
|
|
||||||
return json.loads(candidate)
|
return json.loads(candidate)
|
||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 使用json_repair尝试修复
|
# 使用json_repair尝试修复
|
||||||
try:
|
try:
|
||||||
import json_repair
|
|
||||||
return json_repair.loads(candidate)
|
return json_repair.loads(candidate)
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user