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"
|
adminUserID := "admin"
|
||||||
|
|||||||
@@ -828,36 +828,29 @@ func splitContent(text string) []bridge.ResponseMessage {
|
|||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterActions removes <action>...</action> tags and their content from text.
|
// filterActions removes action/emote tags and their content from text.
|
||||||
// Also handles unescaped <action> tags from SSE (e.g. <action>).
|
// Handles both <action> and <app> tag variants that DeepSeek may produce.
|
||||||
func filterActions(text string) string {
|
func filterActions(text string) string {
|
||||||
// Remove standard <action>...</action> tags.
|
// Tags to filter (paired: open → close).
|
||||||
for {
|
actionTags := [][2]string{
|
||||||
start := strings.Index(text, "<action>")
|
{"<action>", "</action>"},
|
||||||
if start == -1 {
|
{"<app>", "</app>"},
|
||||||
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>"):]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove SSE-escaped action tags (<action>...</action>).
|
for _, tags := range actionTags {
|
||||||
|
openTag, closeTag := tags[0], tags[1]
|
||||||
for {
|
for {
|
||||||
start := strings.Index(text, `<action>`)
|
start := strings.Index(text, openTag)
|
||||||
if start == -1 {
|
if start == -1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
end := strings.Index(text[start:], `</action>`)
|
end := strings.Index(text[start:], closeTag)
|
||||||
if end == -1 {
|
if end == -1 {
|
||||||
text = text[:start] + text[start+len(`<action>`):]
|
text = text[:start] + text[start+len(openTag):]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
text = text[:start] + text[start+end+len(`</action>`):]
|
text = text[:start] + text[start+end+len(closeTag):]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSpace(text)
|
return strings.TrimSpace(text)
|
||||||
|
|||||||
Reference in New Issue
Block a user