chore/ 删除无用文件

This commit is contained in:
Kevin
2026-03-19 14:36:14 +08:00
parent 2f60858c9c
commit c6e07ce5ca
135 changed files with 2111 additions and 4510 deletions

View File

@@ -1,4 +1,5 @@
"""回忆录模块MemoryAgent、BackgroundTaskRunner、MemoirOrchestrator、各 Specialist Agent"""
from app.agents.memoir.memory_agent import MemoryAgent
from app.agents.memoir.processor import (
BackgroundTaskRunner,

View File

@@ -2,6 +2,7 @@
ClassificationAgent将内容分类到 8 个章节类别,或判定无价值返回 None。
对应现有逻辑_classify_chapter_category
"""
from __future__ import annotations
from typing import Any, Optional
@@ -63,7 +64,9 @@ class ClassificationAgent:
response = llm.invoke(prompt)
category = (response.content or "").strip().lower()
if category == "none":
logger.info("LLM 判定内容无回忆录价值,跳过: %s...", (text or "")[:80])
logger.info(
"LLM 判定内容无回忆录价值,跳过: %s...", (text or "")[:80]
)
return None
if category in CHAPTER_CATEGORIES:
return category

View File

@@ -2,6 +2,7 @@
ExtractionAgent从用户消息中提取 5-stage 状态与 slots。
对应现有逻辑get_state_extraction_prompt + JSON 解析
"""
from __future__ import annotations
import json
@@ -19,6 +20,7 @@ logger = get_logger(__name__)
@dataclass
class ExtractionResult:
"""状态提取结果"""
detected_stage: str
slots: Dict[str, str]
@@ -41,7 +43,9 @@ class ExtractionAgent:
extracted_slots: Dict[str, str] = {}
if not llm:
return ExtractionResult(detected_stage=detected_stage, slots=extracted_slots)
return ExtractionResult(
detected_stage=detected_stage, slots=extracted_slots
)
try:
prompt = get_state_extraction_prompt(
@@ -61,8 +65,7 @@ class ExtractionAgent:
detected_stage = parsed.get("detected_stage", detected_stage)
raw_slots = parsed.get("slots", {}) or {}
extracted_slots = {
k: v if isinstance(v, str) else str(v)
for k, v in raw_slots.items()
k: v if isinstance(v, str) else str(v) for k, v in raw_slots.items()
}
except (json.JSONDecodeError, Exception) as e:
logger.warning("ExtractionAgent LLM 解析失败: %s", e)

View File

@@ -2,6 +2,7 @@
回忆录整理 Agent基于传记结构将口语改写为书面语归类到章节
支持异步调用
"""
import json
from typing import Dict, List, Optional
@@ -40,7 +41,9 @@ class MemoryAgent:
try:
prompt = get_chapter_classification_prompt(segments_text)
response = await self.llm.ainvoke(prompt)
content = response.content if hasattr(response, "content") else str(response)
content = (
response.content if hasattr(response, "content") else str(response)
)
category = content.strip().lower()
if category in CHAPTER_CATEGORIES:
return category
@@ -70,7 +73,9 @@ class MemoryAgent:
max_tokens=4096,
)
response = await json_llm.ainvoke(prompt)
content = response.content if hasattr(response, "content") else str(response)
content = (
response.content if hasattr(response, "content") else str(response)
)
content = content.strip()
result = json.loads(extract_json_payload(content))
result["content"] = inject_image_placeholder_template(

View File

@@ -2,6 +2,7 @@
NarrativeAgent生成创意标题和叙事改写。
对应现有逻辑get_creative_title_prompt、get_narrative_prompt
"""
from __future__ import annotations
from typing import Any, Dict, Optional

View File

@@ -3,6 +3,7 @@ MemoirOrchestrator按 segment 编排流水线,调用各 Specialist Agent。
负责:遍历 segments、按 category 聚合、调用 Specialist、更新 state
持久化与章节生成由 process_category 回调完成。
"""
from __future__ import annotations
from typing import Any, Callable, Dict, List, Set, Tuple
@@ -39,9 +40,7 @@ class MemoirOrchestrator:
user_profile: str = "",
user_birth_year: Any = None,
get_or_create_state: Callable[[], MemoirStateSchema],
update_slot: Callable[
[str, str, str, List[str]], MemoirStateSchema
],
update_slot: Callable[[str, str, str, List[str]], MemoirStateSchema],
acquire_lock: Callable[[str], bool],
release_lock: Callable[[str], None],
process_category: Callable[

View File

@@ -3,6 +3,7 @@ PlaceholderInjectAgent对 narrative 做占位符模板注入。
对应现有逻辑inject_image_placeholder_template
纯函数式,无 LLM 调用。
"""
from app.agents.memoir.prompts import inject_image_placeholder_template

View File

@@ -2,6 +2,7 @@
回忆录后台处理器:分析对话、更新状态、生成章节、创意标题
使用 Celery 进行后台任务处理
"""
from __future__ import annotations
import json
@@ -70,9 +71,7 @@ class ContentAnalyzer:
async def analyze_message(
self, user_message: str, current_state: MemoirStateSchema
) -> AnalysisResult:
detected_stage = self._detect_stage(
user_message, current_state.current_stage
)
detected_stage = self._detect_stage(user_message, current_state.current_stage)
extracted_slots: Dict[str, str] = {}
emotion = "neutral"
is_new_chapter = False

View File

@@ -1,6 +1,7 @@
"""
回忆录整理 Agent 提示词模板
"""
import json
import re
from typing import Optional
@@ -67,8 +68,13 @@ def inject_image_placeholder_template(content: str) -> str:
if not inner:
return match.group(0)
if inner.startswith(IMAGE_PLACEHOLDER_TEMPLATE):
desc = inner[len(IMAGE_PLACEHOLDER_TEMPLATE):].lstrip("").strip()
return "{{{{IMAGE:" + IMAGE_PLACEHOLDER_TEMPLATE + ("" + desc if desc else "") + "}}}}"
desc = inner[len(IMAGE_PLACEHOLDER_TEMPLATE) :].lstrip("").strip()
return (
"{{{{IMAGE:"
+ IMAGE_PLACEHOLDER_TEMPLATE
+ ("" + desc if desc else "")
+ "}}}}"
)
return "{{{{IMAGE:" + IMAGE_PLACEHOLDER_TEMPLATE + "" + inner + "}}}}"
content = _IMAGE_PLACEHOLDER_ANY_BRACES_RE.sub(replace_one, content)
@@ -146,10 +152,14 @@ def get_chapter_classification_prompt(segments_text: str) -> str:
如果对话内容中没有任何与人生经历相关的实质内容,返回 none。"""
def get_text_rewrite_prompt(segments_text: str, chapter_category: str, existing_content: str = "") -> str:
def get_text_rewrite_prompt(
segments_text: str, chapter_category: str, existing_content: str = ""
) -> str:
"""获取文本改写的提示词"""
chapter_name = CHAPTER_CATEGORIES.get(chapter_category, chapter_category)
existing_section = f"\n\n已有章节内容:\n{existing_content}" if existing_content else ""
existing_section = (
f"\n\n已有章节内容:\n{existing_content}" if existing_content else ""
)
return f"""{get_system_prompt()}
请将以下口语化的对话内容改写为书面语,归类到"{chapter_name}"章节。
@@ -181,7 +191,9 @@ def get_text_rewrite_prompt(segments_text: str, chapter_category: str, existing_
{{{{IMAGE:奶奶坐在院子里的藤椅上,手里摇着蒲扇}}}}"""
def get_state_extraction_prompt(user_message: str, current_stage: str, stage_slots: dict) -> str:
def get_state_extraction_prompt(
user_message: str, current_stage: str, stage_slots: dict
) -> str:
"""抽取结构化信息并判断阶段"""
slot_keys = list(stage_slots.keys())
all_stage_slots = {
@@ -296,9 +308,19 @@ def get_narrative_prompt(
"""将新对话改写为叙述(只输出新内容的改写,不重复已有内容)"""
context_tail = ""
if existing_content:
context_tail = existing_content[-300:] if len(existing_content) > 300 else existing_content
context_section = f"\n\n【衔接上下文(已有内容的末尾,仅供参考衔接,不要重复)】:\n{context_tail}" if context_tail else ""
archived_section = f"\n\n【已删除的该类别历史章节(仅供参考,请勿直接使用或重复)】:\n{archived_summaries}" if archived_summaries else ""
context_tail = (
existing_content[-300:] if len(existing_content) > 300 else existing_content
)
context_section = (
f"\n\n【衔接上下文(已有内容的末尾,仅供参考衔接,不要重复)】:\n{context_tail}"
if context_tail
else ""
)
archived_section = (
f"\n\n【已删除的该类别历史章节(仅供参考,请勿直接使用或重复)】:\n{archived_summaries}"
if archived_summaries
else ""
)
profile_section = f"\n\n用户基本信息:\n{user_profile}" if user_profile else ""
age_hint = _build_age_hint(stage, birth_year)
@@ -366,8 +388,14 @@ def get_narrative_json_prompt(
"""将新对话改写为叙述,输出 JSON 格式paragraphs: [{content, image_description}]"""
context_tail = ""
if existing_content:
context_tail = existing_content[-300:] if len(existing_content) > 300 else existing_content
context_section = f"\n\n【衔接上下文(已有内容的末尾,仅供参考衔接,不要重复)】:\n{context_tail}" if context_tail else ""
context_tail = (
existing_content[-300:] if len(existing_content) > 300 else existing_content
)
context_section = (
f"\n\n【衔接上下文(已有内容的末尾,仅供参考衔接,不要重复)】:\n{context_tail}"
if context_tail
else ""
)
profile_section = f"\n\n用户基本信息:\n{user_profile}" if user_profile else ""
age_hint = _build_age_hint(stage, birth_year)
time_section = f"\n时间参考:{age_hint}" if age_hint else ""