- DB: segments 用户输入文本(Alembic 0002) - Chat: 阶段检测/阶段提示/回复限制,编排与访谈/画像 prompts 调整 - Memoir: 忠实度检查 agent,叙事与分类等链路更新 - Core: agent 日志、Alembic 启动、LangChain/日志/配置等 - Story: time_hints;Memory 检索与相关测试 - Expo: 助手头像、会话页与消息拆分、实时会话与文案/i18n - Docs/scripts/tests: 迁移脚本、LLM JSON/记忆检索文档、新增单测
25 lines
765 B
Python
25 lines
765 B
Python
"""访谈/资料追问:回复条数与单条字数硬限制(不靠长 prompt)。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
|
||
def truncate_chat_segments(
|
||
segments: list[str],
|
||
*,
|
||
max_segments: int,
|
||
max_chars_per_segment: int,
|
||
) -> list[str]:
|
||
"""保留前 max_segments 条,每条截断至 max_chars_per_segment(按字符数,中文友好)。"""
|
||
if not segments:
|
||
return []
|
||
out: list[str] = []
|
||
for raw in segments[:max_segments]:
|
||
s = (raw or "").strip()
|
||
if not s:
|
||
continue
|
||
if len(s) > max_chars_per_segment:
|
||
# 保留 1 个字符给省略号,使总长度不超过上限
|
||
s = s[: max_chars_per_segment - 1].rstrip() + "…"
|
||
out.append(s)
|
||
return out
|