This commit is contained in:
@@ -93,6 +93,54 @@ class BailianService:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"AI Evaluation failed: {e}")
|
logger.error(f"AI Evaluation failed: {e}")
|
||||||
evaluation.status = AIEvaluation.Status.FAILED
|
evaluation.status = AIEvaluation.Status.FAILED
|
||||||
evaluation.error_message = str(e)
|
evaluation.error_message = str(e)
|
||||||
evaluation.save()
|
evaluation.save()
|
||||||
return evaluation
|
return evaluation
|
||||||
|
|
||||||
|
def summarize_task(self, task):
|
||||||
|
"""
|
||||||
|
使用 AI 模型总结转写和章节数据
|
||||||
|
"""
|
||||||
|
if not self.client:
|
||||||
|
logger.error("DashScope client not initialized")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
summary_data = json.dumps(task.summary_data or {}, ensure_ascii=False)
|
||||||
|
chapters_data = json.dumps(task.auto_chapters_data or {}, ensure_ascii=False)
|
||||||
|
|
||||||
|
prompt = f"""
|
||||||
|
你是一个专业的会议摘要和内容分析助手。请根据以下提供的“总结原始数据”和“章节原始数据”,生成一个结构清晰、专业且易于阅读的 Markdown 格式总结。
|
||||||
|
|
||||||
|
要求:
|
||||||
|
1. 包含一个总体的“核心摘要”。
|
||||||
|
2. 包含一个详细的“内容大纲”。
|
||||||
|
3. 如果有问答或对话信息,请包含“关键问答”或“发言人观点”。
|
||||||
|
4. 包含一个带有时间戳的“章节回顾”,格式为 [HH:MM:SS] 标题。
|
||||||
|
5. 语言简练,重点突出。
|
||||||
|
|
||||||
|
总结原始数据:
|
||||||
|
{summary_data}
|
||||||
|
|
||||||
|
章节原始数据:
|
||||||
|
{chapters_data}
|
||||||
|
"""
|
||||||
|
messages = [
|
||||||
|
{'role': 'system', 'content': '你是一个专业的文档总结助手。请直接返回 Markdown 格式的内容,不要包含任何引导性文字。'},
|
||||||
|
{'role': 'user', 'content': prompt}
|
||||||
|
]
|
||||||
|
|
||||||
|
completion = self.client.chat.completions.create(
|
||||||
|
model="qwen-turbo",
|
||||||
|
messages=messages,
|
||||||
|
temperature=0.7
|
||||||
|
)
|
||||||
|
|
||||||
|
ai_summary = completion.choices[0].message.content
|
||||||
|
if ai_summary:
|
||||||
|
task.summary = ai_summary
|
||||||
|
task.save()
|
||||||
|
logger.info(f"AI summary generated for task {task.id}")
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to generate AI summary: {e}")
|
||||||
|
|||||||
@@ -272,62 +272,7 @@ class AliyunTingwuService:
|
|||||||
|
|
||||||
# 提取文本 (MindMapSummary)
|
# 提取文本 (MindMapSummary)
|
||||||
# 结构: {"MindMapSummary": [{"Title": "...", "Topic": [...]}]}
|
# 结构: {"MindMapSummary": [{"Title": "...", "Topic": [...]}]}
|
||||||
summary_text = []
|
# 移除了原先的 summary_text 拼接逻辑
|
||||||
|
|
||||||
# 1. 优先提取段落标题和摘要
|
|
||||||
if 'ParagraphTitle' in summarization:
|
|
||||||
summary_text.append(f"### {summarization['ParagraphTitle']}")
|
|
||||||
if 'ParagraphSummary' in summarization:
|
|
||||||
summary_text.append(summarization['ParagraphSummary'])
|
|
||||||
summary_text.append("") # 空行分隔
|
|
||||||
|
|
||||||
# 2. 提取思维导图作为大纲
|
|
||||||
def parse_mindmap_topic(topic_list, level=0):
|
|
||||||
indent = " " * level
|
|
||||||
for topic in topic_list:
|
|
||||||
title = topic.get('Title', '')
|
|
||||||
if title:
|
|
||||||
summary_text.append(f"{indent}- {title}")
|
|
||||||
|
|
||||||
sub_topics = topic.get('Topic', [])
|
|
||||||
if sub_topics:
|
|
||||||
parse_mindmap_topic(sub_topics, level + 1)
|
|
||||||
|
|
||||||
if 'MindMapSummary' in summarization:
|
|
||||||
summary_text.append("### 内容大纲")
|
|
||||||
parse_mindmap_topic(summarization['MindMapSummary'])
|
|
||||||
summary_text.append("")
|
|
||||||
|
|
||||||
# 3. 提取对话总结 (ConversationalSummary)
|
|
||||||
if 'ConversationalSummary' in summarization and isinstance(summarization['ConversationalSummary'], list):
|
|
||||||
summary_text.append("### 对话总结")
|
|
||||||
for conv in summarization['ConversationalSummary']:
|
|
||||||
speaker = conv.get('SpeakerName', '发言人')
|
|
||||||
summary = conv.get('Summary', '')
|
|
||||||
if summary:
|
|
||||||
summary_text.append(f"- **{speaker}**: {summary}")
|
|
||||||
summary_text.append("")
|
|
||||||
|
|
||||||
# 4. 提取问答总结 (QuestionsAnsweringSummary)
|
|
||||||
if 'QuestionsAnsweringSummary' in summarization and isinstance(summarization['QuestionsAnsweringSummary'], list):
|
|
||||||
summary_text.append("### 问答回顾")
|
|
||||||
for qa in summarization['QuestionsAnsweringSummary']:
|
|
||||||
question = qa.get('Question', '')
|
|
||||||
answer = qa.get('Answer', '')
|
|
||||||
if question and answer:
|
|
||||||
summary_text.append(f"**Q: {question}**")
|
|
||||||
summary_text.append(f"A: {answer}")
|
|
||||||
summary_text.append("")
|
|
||||||
|
|
||||||
# 兼容旧逻辑:如果上述都为空,尝试 Text 或 Headline
|
|
||||||
if not summary_text:
|
|
||||||
if 'Text' in summarization:
|
|
||||||
summary_text.append(summarization['Text'])
|
|
||||||
elif 'Headline' in summarization:
|
|
||||||
summary_text.append(summarization['Headline'])
|
|
||||||
|
|
||||||
if summary_text:
|
|
||||||
task.summary = "\n".join(summary_text)
|
|
||||||
|
|
||||||
# --- C. 处理章节 (AutoChapters) ---
|
# --- C. 处理章节 (AutoChapters) ---
|
||||||
auto_chapters = get_data_field(task_result, 'AutoChapters') or get_data_field(data_obj, 'AutoChapters') or []
|
auto_chapters = get_data_field(task_result, 'AutoChapters') or get_data_field(data_obj, 'AutoChapters') or []
|
||||||
@@ -346,34 +291,18 @@ class AliyunTingwuService:
|
|||||||
# 保存原始数据
|
# 保存原始数据
|
||||||
task.auto_chapters_data = auto_chapters
|
task.auto_chapters_data = auto_chapters
|
||||||
|
|
||||||
# 将章节信息追加到 summary
|
# 保存任务,确保原始数据已写入数据库
|
||||||
if auto_chapters and isinstance(auto_chapters, list):
|
|
||||||
if summary_text:
|
|
||||||
summary_text.append("\n\n### 章节速览")
|
|
||||||
else:
|
|
||||||
summary_text.append("### 章节速览")
|
|
||||||
|
|
||||||
for chapter in auto_chapters:
|
|
||||||
headline = chapter.get('Headline', '')
|
|
||||||
summary = chapter.get('Summary', '')
|
|
||||||
start_time = chapter.get('Start', 0)
|
|
||||||
|
|
||||||
# 格式化时间戳 (毫秒 -> HH:MM:SS)
|
|
||||||
seconds = int(start_time / 1000)
|
|
||||||
m, s = divmod(seconds, 60)
|
|
||||||
h, m = divmod(m, 60)
|
|
||||||
time_str = f"{h:02d}:{m:02d}:{s:02d}"
|
|
||||||
|
|
||||||
chapter_text = f"- [{time_str}] {headline}"
|
|
||||||
if summary:
|
|
||||||
chapter_text += f"\n {summary}"
|
|
||||||
summary_text.append(chapter_text)
|
|
||||||
|
|
||||||
if summary_text:
|
|
||||||
task.summary = "\n".join(summary_text)
|
|
||||||
|
|
||||||
task.save()
|
task.save()
|
||||||
|
|
||||||
|
# 调用大模型生成总结 (如果 summary_data 或 auto_chapters_data 存在)
|
||||||
|
if task.summary_data or task.auto_chapters_data:
|
||||||
|
try:
|
||||||
|
from .bailian_service import BailianService
|
||||||
|
bailian_service = BailianService()
|
||||||
|
bailian_service.summarize_task(task)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to trigger AI summarization: {e}")
|
||||||
|
|
||||||
# 4. 自动触发 AI 评估 (如果任务首次成功且有启用的模板)
|
# 4. 自动触发 AI 评估 (如果任务首次成功且有启用的模板)
|
||||||
if previous_status != 'SUCCEEDED' and task.status == 'SUCCEEDED' and task.transcription:
|
if previous_status != 'SUCCEEDED' and task.status == 'SUCCEEDED' and task.transcription:
|
||||||
self.trigger_ai_evaluations(task)
|
self.trigger_ai_evaluations(task)
|
||||||
|
|||||||
Reference in New Issue
Block a user