fix: 对话历史上限增至100条 + filterActions 兼容 <app> 动作标签
- 会话历史存储上限从 50 条增至 100 条 - filterActions 同时处理 <action> 和 <app> 标签(DeepSeek 偶用 <app> 替代 <action>) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -133,7 +133,7 @@ func main() {
|
||||
}
|
||||
|
||||
// 初始化会话历史存储
|
||||
convStore := ctxbuild.NewConversationStore(50)
|
||||
convStore := ctxbuild.NewConversationStore(100)
|
||||
|
||||
// 从数据库恢复主会话历史(避免重启丢失上下文)
|
||||
adminUserID := "admin"
|
||||
|
||||
@@ -828,36 +828,29 @@ func splitContent(text string) []bridge.ResponseMessage {
|
||||
return msgs
|
||||
}
|
||||
|
||||
// filterActions removes <action>...</action> tags and their content from text.
|
||||
// Also handles unescaped <action> tags from SSE (e.g. <action>).
|
||||
// filterActions removes action/emote tags and their content from text.
|
||||
// Handles both <action> and <app> tag variants that DeepSeek may produce.
|
||||
func filterActions(text string) string {
|
||||
// Remove standard <action>...</action> tags.
|
||||
for {
|
||||
start := strings.Index(text, "<action>")
|
||||
if start == -1 {
|
||||
break
|
||||
}
|
||||
end := strings.Index(text[start:], "</action>")
|
||||
if end == -1 {
|
||||
// Unclosed action tag — just remove the opening tag.
|
||||
text = text[:start] + text[start+len("<action>"):]
|
||||
continue
|
||||
}
|
||||
text = text[:start] + text[start+end+len("</action>"):]
|
||||
// Tags to filter (paired: open → close).
|
||||
actionTags := [][2]string{
|
||||
{"<action>", "</action>"},
|
||||
{"<app>", "</app>"},
|
||||
}
|
||||
|
||||
// Remove SSE-escaped action tags (<action>...</action>).
|
||||
for {
|
||||
start := strings.Index(text, `<action>`)
|
||||
if start == -1 {
|
||||
break
|
||||
for _, tags := range actionTags {
|
||||
openTag, closeTag := tags[0], tags[1]
|
||||
for {
|
||||
start := strings.Index(text, openTag)
|
||||
if start == -1 {
|
||||
break
|
||||
}
|
||||
end := strings.Index(text[start:], closeTag)
|
||||
if end == -1 {
|
||||
text = text[:start] + text[start+len(openTag):]
|
||||
continue
|
||||
}
|
||||
text = text[:start] + text[start+end+len(closeTag):]
|
||||
}
|
||||
end := strings.Index(text[start:], `</action>`)
|
||||
if end == -1 {
|
||||
text = text[:start] + text[start+len(`<action>`):]
|
||||
continue
|
||||
}
|
||||
text = text[:start] + text[start+end+len(`</action>`):]
|
||||
}
|
||||
|
||||
return strings.TrimSpace(text)
|
||||
|
||||
Reference in New Issue
Block a user