++
This commit is contained in:
@@ -306,24 +306,24 @@ class Narrator:
|
||||
try:
|
||||
forecast_analysis = forecast.analyze(metrics_history)
|
||||
except Exception as e:
|
||||
logger.debug("Forecast analysis failed: %s", e)
|
||||
logger.debug("预测分析失败:%s", e)
|
||||
try:
|
||||
causal_links = forecast.discover_causality(simulation_id)
|
||||
causal_map = ReportAnalyzer.format_causal_links(causal_links)
|
||||
except Exception as e:
|
||||
logger.debug("Causal discovery failed: %s", e)
|
||||
logger.debug("因果关系分析失败:%s", e)
|
||||
try:
|
||||
counterfactual_results = forecast.compute_counterfactuals(simulation_id)
|
||||
counterfactual_data = ReportAnalyzer.format_counterfactuals(counterfactual_results)
|
||||
except Exception as e:
|
||||
logger.debug("Counterfactual computation failed: %s", e)
|
||||
logger.debug("反事实计算失败:%s", e)
|
||||
try:
|
||||
from app.services.forecast import _SimState
|
||||
sim_state = forecast._sims.get(simulation_id)
|
||||
if sim_state and sim_state.coherence_scores:
|
||||
coherence_data = ReportAnalyzer.format_coherence_scores(sim_state.coherence_scores)
|
||||
except Exception as e:
|
||||
logger.debug("Coherence formatting failed: %s", e)
|
||||
logger.debug("一致性结果格式化失败:%s", e)
|
||||
|
||||
# --- Pass 2: Metric interpretation + insights ---
|
||||
metrics_summary = "\n".join(
|
||||
@@ -363,8 +363,8 @@ class Narrator:
|
||||
+ (f"\n\nCausal analysis:\n{causal_summary}" if causal_summary else "")
|
||||
)
|
||||
|
||||
response_p2 = await self.llm.generate(system=system_p2, user=user_p2, json_mode=True, max_tokens=2000)
|
||||
pass2 = parse_json(response_p2)
|
||||
response_p2 = await self.llm.generate(system=system_p2, user=user_p2, json_mode=True, max_tokens=2000, purpose="报告指标分析")
|
||||
pass2 = parse_json(response_p2, purpose="报告指标分析")
|
||||
|
||||
explanations = pass2.get("metric_explanations", {})
|
||||
scorecard = []
|
||||
@@ -397,8 +397,8 @@ class Narrator:
|
||||
) + f"\n\n{tail}"
|
||||
user_p3 = f"Segment data:\n{segment_input}"
|
||||
|
||||
response_p3 = await self.llm.generate(system=system_p3, user=user_p3, json_mode=True, max_tokens=1500)
|
||||
pass3 = parse_json(response_p3)
|
||||
response_p3 = await self.llm.generate(system=system_p3, user=user_p3, json_mode=True, max_tokens=1500, purpose="报告分群分析")
|
||||
pass3 = parse_json(response_p3, purpose="报告分群分析")
|
||||
|
||||
llm_segments = {s["name"]: s for s in pass3.get("segments", [])}
|
||||
segments_final = []
|
||||
@@ -437,8 +437,8 @@ class Narrator:
|
||||
rules="; ".join(blueprint.rules),
|
||||
) + f"\n\n{tail}"
|
||||
|
||||
response_p4 = await self.llm.generate(system=system_p4, user=synthesis_context, json_mode=True, max_tokens=1500)
|
||||
pass4 = parse_json(response_p4)
|
||||
response_p4 = await self.llm.generate(system=system_p4, user=synthesis_context, json_mode=True, max_tokens=1500, purpose="报告行动建议")
|
||||
pass4 = parse_json(response_p4, purpose="报告行动建议")
|
||||
|
||||
# --- Assemble final report ---
|
||||
key_moments = []
|
||||
|
||||
Reference in New Issue
Block a user