style: format summarizer.py
This commit is contained in:
@@ -93,9 +93,7 @@ def _expand_anchor_ids(group_text: str) -> list[str]:
|
|||||||
return ids
|
return ids
|
||||||
|
|
||||||
|
|
||||||
def check_anchors(
|
def check_anchors(summary: str, anchor_map: dict[str, str]) -> tuple[str, dict[str, int]]:
|
||||||
summary: str, anchor_map: dict[str, str]
|
|
||||||
) -> tuple[str, dict[str, int]]:
|
|
||||||
"""校验行号引注:非法行号删锚不删断言。
|
"""校验行号引注:非法行号删锚不删断言。
|
||||||
|
|
||||||
参数:
|
参数:
|
||||||
@@ -235,9 +233,7 @@ async def _call_llm(
|
|||||||
{"role": "system", "content": system_prompt},
|
{"role": "system", "content": system_prompt},
|
||||||
{"role": "user", "content": user_text},
|
{"role": "user", "content": user_text},
|
||||||
]
|
]
|
||||||
response = await llm.chat(
|
response = await llm.chat(messages, session_id=session_id, parent_call_id=parent_call_id)
|
||||||
messages, session_id=session_id, parent_call_id=parent_call_id
|
|
||||||
)
|
|
||||||
return response.content
|
return response.content
|
||||||
|
|
||||||
|
|
||||||
@@ -315,9 +311,7 @@ async def summarize_node(
|
|||||||
verify_result = "跳过(调用失败)"
|
verify_result = "跳过(调用失败)"
|
||||||
|
|
||||||
if anchor_map is not None:
|
if anchor_map is not None:
|
||||||
raw_summary, asm_stats = assemble_anchored_output(
|
raw_summary, asm_stats = assemble_anchored_output(raw_summary, anchor_map, assemble_mode)
|
||||||
raw_summary, anchor_map, assemble_mode
|
|
||||||
)
|
|
||||||
anchor_stats.update(asm_stats)
|
anchor_stats.update(asm_stats)
|
||||||
|
|
||||||
result = f"[内容摘要] {raw_summary}\n[核实] {verify_result}"
|
result = f"[内容摘要] {raw_summary}\n[核实] {verify_result}"
|
||||||
@@ -358,9 +352,7 @@ async def summarize_children(
|
|||||||
lines = []
|
lines = []
|
||||||
for child in children_info:
|
for child in children_info:
|
||||||
t_start, t_end = child["time_range"]
|
t_start, t_end = child["time_range"]
|
||||||
lines.append(
|
lines.append(f"- {child['id']} ({t_start:.0f}-{t_end:.0f}s): {child['summary']}")
|
||||||
f"- {child['id']} ({t_start:.0f}-{t_end:.0f}s): {child['summary']}"
|
|
||||||
)
|
|
||||||
children_text = "\n".join(lines)
|
children_text = "\n".join(lines)
|
||||||
|
|
||||||
extract_input = f"问题: {question}\n\n{children_text}"
|
extract_input = f"问题: {question}\n\n{children_text}"
|
||||||
@@ -417,9 +409,7 @@ async def _summarize_search_result(
|
|||||||
返回:
|
返回:
|
||||||
"[内容摘要] {提取结果}\\n[核实] {验证结果}" 或错误信息。
|
"[内容摘要] {提取结果}\\n[核实] {验证结果}" 或错误信息。
|
||||||
"""
|
"""
|
||||||
extract_input = (
|
extract_input = f"问题: {question}\n\n以下是语义搜索命中的视频节点描述和字幕:\n{raw_text}"
|
||||||
f"问题: {question}\n\n以下是语义搜索命中的视频节点描述和字幕:\n{raw_text}"
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
raw_summary = await _call_llm(
|
raw_summary = await _call_llm(
|
||||||
llm,
|
llm,
|
||||||
@@ -487,9 +477,7 @@ async def summarize_nodes_batch(
|
|||||||
)
|
)
|
||||||
return idx, node_id, summary
|
return idx, node_id, summary
|
||||||
|
|
||||||
tasks = [
|
tasks = [_worker(i, nid, text) for i, (nid, text, _) in enumerate(items)]
|
||||||
_worker(i, nid, text) for i, (nid, text, _) in enumerate(items)
|
|
||||||
]
|
|
||||||
results_raw = await asyncio.gather(*tasks)
|
results_raw = await asyncio.gather(*tasks)
|
||||||
|
|
||||||
results: dict[int, tuple[str, str]] = {}
|
results: dict[int, tuple[str, str]] = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user