YAML 反斜杠修复扩大范围 — 之前只匹配 "D:\..." 格式,现在匹配所有双引号内含反斜杠的字符串。"outputs\session_20260420..." 会被正确转成 "outputs/session_20260420...",不再导致 YAML 解析失败。这直接解决了第 10-19 轮的死循环。
_process_response 的 analysis_complete 检测已经在上一轮修好了,配合反斜杠修复,YAML 能正确解析出 action: "analysis_complete",不会再 fallback 到代码执行。
文件选择改为只用最近一次上传的文件 — app.state.last_uploaded_files 记录上传的文件列表,/api/start 优先使用它,不再 glob("uploads/*.csv") 把所有历史文件都拿来分析。
This commit is contained in:
@@ -139,7 +139,21 @@ class DataAnalysisAgent:
|
||||
"""
|
||||
try:
|
||||
yaml_data = self.llm.parse_yaml_response(response)
|
||||
action = yaml_data.get("action", "generate_code")
|
||||
action = yaml_data.get("action", "")
|
||||
|
||||
# If YAML parsing returned empty/no action, try to detect action from raw text
|
||||
if not action:
|
||||
if "analysis_complete" in response:
|
||||
action = "analysis_complete"
|
||||
# Try to extract final_report from raw text
|
||||
if not yaml_data.get("final_report"):
|
||||
yaml_data["action"] = "analysis_complete"
|
||||
yaml_data["final_report"] = ""
|
||||
elif "collect_figures" in response:
|
||||
action = "collect_figures"
|
||||
yaml_data["action"] = "collect_figures"
|
||||
else:
|
||||
action = "generate_code"
|
||||
|
||||
print(f"[TARGET] 检测到动作: {action}")
|
||||
|
||||
@@ -155,6 +169,11 @@ class DataAnalysisAgent:
|
||||
|
||||
except Exception as e:
|
||||
print(f"[WARN] 解析响应失败: {str(e)},尝试提取代码并按generate_code处理")
|
||||
# Check if this is actually an analysis_complete or collect_figures response
|
||||
if "analysis_complete" in response:
|
||||
return self._handle_analysis_complete(response, {"final_report": ""})
|
||||
if "collect_figures" in response:
|
||||
return self._handle_collect_figures(response, {"figures_to_collect": []})
|
||||
# 即使YAML解析失败,也尝试提取代码
|
||||
extracted_code = extract_code_from_response(response)
|
||||
if extracted_code:
|
||||
|
||||
Reference in New Issue
Block a user