完成对生成逻辑的优化,但也发现新的问题

前后章节的衔接有问题,这里想着应该要把前一个章节内容发送作为参考,不然中断感很重
This commit is contained in:
YILING0013
2025-02-05 22:43:09 +08:00
parent dd78666071
commit f388403b08
3 changed files with 76 additions and 57 deletions
+15 -9
View File
@@ -21,13 +21,19 @@ def parse_chapter_blueprint(blueprint_text: str):
chunks = re.split(r'\n\s*\n', blueprint_text.strip())
results = []
chapter_number_pattern = re.compile(r'^第\s*(\d+)\s*章\s*-\s*\[(.*?)\]') # 捕获章号与标题
role_pattern = re.compile(r'^本章定位:\s*(.*)$')
purpose_pattern = re.compile(r'^核心作用:\s*(.*)$')
suspense_pattern = re.compile(r'^悬念密度:\s*(.*)$')
foreshadow_pattern = re.compile(r'^伏笔操作:\s*(.*)$')
twist_pattern = re.compile(r'^认知颠覆:\s*(.*)$')
summary_pattern = re.compile(r'^本章简述:\s*\[(.*)\]$')
# 兼容是否使用方括号包裹章节标题
# 例如:
# 第1章 - 紫极光下的预兆
# 或
# 第1章 - [紫极光下的预兆]
chapter_number_pattern = re.compile(r'^\s*(\d+)\s*章\s*-\s*\[?(.*?)\]?$')
role_pattern = re.compile(r'^本章定位:\s*\[?(.*)\]?$')
purpose_pattern = re.compile(r'^核心作用:\s*\[?(.*)\]?$')
suspense_pattern = re.compile(r'^悬念密度:\s*\[?(.*)\]?$')
foreshadow_pattern = re.compile(r'^伏笔操作:\s*\[?(.*)\]?$')
twist_pattern = re.compile(r'^认知颠覆:\s*\[?(.*)\]?$')
summary_pattern = re.compile(r'^本章简述:\s*\[?(.*)\]?$')
for chunk in chunks:
lines = chunk.strip().splitlines()
@@ -44,9 +50,9 @@ def parse_chapter_blueprint(blueprint_text: str):
chapter_summary = ""
# 先匹配第一行(或前几行),找到章号和标题
header_match = chapter_number_pattern.match(lines[0].strip()) if lines else None
header_match = chapter_number_pattern.match(lines[0].strip())
if not header_match:
# 不符合格式,跳过
# 不符合“第X章 - 标题”的格式,跳过
continue
chapter_number = int(header_match.group(1))