fix:1.修复自定义系统模板提示词的多出问题

This commit is contained in:
xiamuceer
2025-11-30 12:25:47 +08:00
parent 19e08d99b3
commit 1bb3be3942
4 changed files with 44 additions and 13 deletions
+3 -1
View File
@@ -2709,7 +2709,9 @@ async def regenerate_chapter_stream(
analysis=analysis,
regenerate_request=regenerate_request,
project_context=project_context,
style_content=style_content
style_content=style_content,
user_id=user_id,
db=db_session
):
# 处理不同类型的事件
if event['type'] == 'chunk':
+7 -7
View File
@@ -67,7 +67,7 @@ class ChapterRegenerator:
user_id=user_id,
db=db
)
logger.info(f"🎯 提示词构建完成,开始AI生成")
yield {'type': 'progress', 'progress': 15, 'message': '开始AI生成内容...'}
@@ -177,11 +177,9 @@ class ChapterRegenerator:
db: AsyncSession = None
) -> str:
"""构建完整的重新生成提示词"""
# 获取自定义提示词模板
template = await PromptService.get_template("CHAPTER_REGENERATION_SYSTEM", user_id, db)
# 格式化提示词
return PromptService.format_prompt(
template,
# 使用PromptService的get_chapter_regeneration_prompt方法
# 该方法会处理自定义模板加载和完整提示词构建
return await PromptService.get_chapter_regeneration_prompt(
chapter_number=chapter.chapter_number,
title=chapter.title,
word_count=chapter.word_count,
@@ -189,7 +187,9 @@ class ChapterRegenerator:
modification_instructions=modification_instructions,
project_context=project_context,
style_content=style_content,
target_word_count=regenerate_request.target_word_count
target_word_count=regenerate_request.target_word_count,
user_id=user_id,
db=db
)
def calculate_content_diff(
+6 -1
View File
@@ -53,7 +53,12 @@ class PlotAnalyzer:
analysis_content = content[:8000] if len(content) > 8000 else content
# 获取自定义提示词模板
template = await PromptService.get_template("PLOT_ANALYSIS", user_id, db)
if user_id and db:
template = await PromptService.get_template("PLOT_ANALYSIS", user_id, db)
else:
# 降级到系统默认模板
template = PromptService.PLOT_ANALYSIS
# 格式化提示词
prompt = PromptService.format_prompt(
template,
+28 -4
View File
@@ -1901,11 +1901,35 @@ class PromptService:
)
@classmethod
def get_chapter_regeneration_prompt(cls, chapter_number: int, title: str, word_count: int, content: str,
async def get_chapter_regeneration_prompt(cls, chapter_number: int, title: str, word_count: int, content: str,
modification_instructions: str, project_context: Dict[str, Any],
style_content: str, target_word_count: int) -> str:
"""获取章节重写提示词"""
prompt_parts = [cls.CHAPTER_REGENERATION_SYSTEM]
style_content: str, target_word_count: int,
user_id: str = None, db = None) -> str:
"""
获取章节重写提示词(支持用户自定义)
Args:
chapter_number: 章节序号
title: 章节标题
word_count: 原始字数
content: 原始内容
modification_instructions: 修改指令
project_context: 项目上下文
style_content: 写作风格
target_word_count: 目标字数
user_id: 用户ID(可选,用于获取自定义模板)
db: 数据库会话(可选,用于查询自定义模板)
Returns:
完整的章节重写提示词
"""
# 获取系统提示词模板(支持用户自定义)
if user_id and db:
system_template = await cls.get_template("CHAPTER_REGENERATION_SYSTEM", user_id, db)
else:
system_template = cls.CHAPTER_REGENERATION_SYSTEM
prompt_parts = [system_template]
# 原始章节信息
prompt_parts.append(f"""## 📖 原始章节信息