mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-16 11:24:45 +08:00
fix: improve JSON repair handling for markdown code blocks (#841)
* fix: improve JSON repair handling for markdown code blocks * unified import path * compress_crawl_udf * fix * reverse
This commit is contained in:
@@ -332,9 +332,12 @@ def planner_node(
|
||||
logger.debug(f"Current state messages: {state['messages']}")
|
||||
logger.info(f"Planner response: {full_response}")
|
||||
|
||||
# Clean the response first to handle markdown code blocks (```json, ```ts, etc.)
|
||||
cleaned_response = repair_json_output(full_response)
|
||||
|
||||
# Validate explicitly that response content is valid JSON before proceeding to parse it
|
||||
if not full_response.strip().startswith('{') and not full_response.strip().startswith('['):
|
||||
logger.warning("Planner response does not appear to be valid JSON")
|
||||
if not cleaned_response.strip().startswith('{') and not cleaned_response.strip().startswith('['):
|
||||
logger.warning("Planner response does not appear to be valid JSON after cleanup")
|
||||
if plan_iterations > 0:
|
||||
return Command(
|
||||
update=preserve_state_meta_fields(state),
|
||||
@@ -347,7 +350,7 @@ def planner_node(
|
||||
)
|
||||
|
||||
try:
|
||||
curr_plan = json.loads(repair_json_output(full_response))
|
||||
curr_plan = json.loads(cleaned_response)
|
||||
# Need to extract the plan from the full_response
|
||||
curr_plan_content = extract_plan_content(curr_plan)
|
||||
# load the current_plan
|
||||
@@ -1428,4 +1431,4 @@ async def analyst_node(
|
||||
config,
|
||||
"analyst",
|
||||
[], # No tools - pure reasoning
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user