新对话重置系统提示词为文件内容
This commit is contained in:
+4
-1
@@ -139,9 +139,12 @@ func (b *Bot) Tools() []string {
|
||||
return b.toolRegistry.List()
|
||||
}
|
||||
|
||||
// ClearHistory 清空内存中的会话历史,开启新对话(系统提示词保留)。
|
||||
// ClearHistory 清空内存中的会话历史,开启新对话;系统提示词重置为配置加载的文件内容。
|
||||
func (b *Bot) ClearHistory() {
|
||||
b.history = nil
|
||||
if b.cfg != nil {
|
||||
b.systemPrompt = b.cfg.SystemPrompt
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Bot) ContextWindow() int64 {
|
||||
|
||||
@@ -89,11 +89,12 @@ func TestRestoreTrimsHistory(t *testing.T) {
|
||||
func TestClearHistory(t *testing.T) {
|
||||
b := newTestBot(t)
|
||||
b.history = append(b.history, openai.UserMessage("hi"))
|
||||
b.systemPrompt = "被会话覆盖的旧提示词"
|
||||
b.ClearHistory()
|
||||
if len(b.history) != 0 {
|
||||
t.Errorf("history 应清空, got %d", len(b.history))
|
||||
}
|
||||
if b.systemPrompt != "测试系统提示" {
|
||||
t.Errorf("systemPrompt 应保留: %q", b.systemPrompt)
|
||||
t.Errorf("systemPrompt 应重置为配置内容, got %q", b.systemPrompt)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user