wd666/report/report_generator.py
2026-01-07 11:02:05 +08:00

144 lines
3.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
报告生成器 - 汇总辩论内容并生成决策报告
"""
from typing import List
from orchestrator.debate_manager import SpeechRecord
from utils.llm_client import LLMClient
class ReportGenerator:
"""决策报告生成器"""
def __init__(self, llm_client: LLMClient = None):
self.llm_client = llm_client or LLMClient()
def generate_report(
self,
topic: str,
speeches: List[SpeechRecord],
context: str = ""
) -> str:
"""
生成决策报告
Args:
topic: 讨论议题
speeches: 所有发言记录
context: 背景信息
Returns:
str: Markdown 格式的决策报告
"""
# 构建发言摘要
speeches_text = self._format_speeches(speeches)
system_prompt = """你是一位专业的决策分析师,擅长汇总多方观点并生成结构化的决策报告。
你的任务是根据多位专家的讨论,生成一份清晰、可操作的决策报告。
报告格式要求:
1. 使用 Markdown 格式
2. 结构清晰,重点突出
3. 提炼核心要点,不要罗列原文
4. 给出明确的建议和下一步行动"""
user_prompt = f"""## 讨论议题
{topic}
{f"## 背景信息" + chr(10) + context if context else ""}
## 专家讨论记录
{speeches_text}
## 你的任务
请生成一份决策报告,包含以下部分:
### 📋 议题概述
1-2句话总结讨论的核心问题
### ✅ 支持观点汇总
(列出支持该决策的主要理由,注明来源角色)
### ❌ 反对/风险观点汇总
(列出反对意见和风险点,注明来源角色)
### 🔑 关键决策要点
3-5个需要重点考虑的因素
### 💡 建议与下一步行动
(给出明确的建议,以及具体的下一步行动项)
### ⚖️ 决策框架
(提供一个简单的决策框架或检查清单,帮助做出最终决策)
"""
return self.llm_client.chat(
system_prompt=system_prompt,
user_prompt=user_prompt,
max_tokens=2048
)
def _format_speeches(self, speeches: List[SpeechRecord]) -> str:
"""格式化发言记录"""
formatted = []
current_round = 0
for speech in speeches:
if speech.round_num != current_round:
current_round = speech.round_num
formatted.append(f"\n### 第 {current_round} 轮讨论\n")
formatted.append(
f"**{speech.emoji} {speech.agent_name}**:\n{speech.content}\n"
)
return "\n".join(formatted)
def generate_report_stream(
self,
topic: str,
speeches: List[SpeechRecord],
context: str = ""
):
"""流式生成决策报告"""
speeches_text = self._format_speeches(speeches)
system_prompt = """你是一位专业的决策分析师,擅长汇总多方观点并生成结构化的决策报告。"""
user_prompt = f"""## 讨论议题
{topic}
{f"## 背景信息" + chr(10) + context if context else ""}
## 专家讨论记录
{speeches_text}
## 你的任务
请生成一份决策报告,包含以下部分:
### 📋 议题概述
1-2句话总结讨论的核心问题
### ✅ 支持观点汇总
(列出支持该决策的主要理由,注明来源角色)
### ❌ 反对/风险观点汇总
(列出反对意见和风险点,注明来源角色)
### 🔑 关键决策要点
3-5个需要重点考虑的因素
### 💡 建议与下一步行动
(给出明确的建议,以及具体的下一步行动项)
### ⚖️ 决策框架
(提供一个简单的决策框架或检查清单)
"""
for chunk in self.llm_client.chat_stream(
system_prompt=system_prompt,
user_prompt=user_prompt,
max_tokens=2048
):
yield chunk