From b67ae1be98f3131fa8cec9ae01d8f86fd4df8e06 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Tue, 17 Feb 2026 13:42:49 +0300 Subject: Enha: filter out thinking blocks from chat history, removed {role}: --- helpfuncs.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'helpfuncs.go') diff --git a/helpfuncs.go b/helpfuncs.go index b6b5faa..cc6bfe3 100644 --- a/helpfuncs.go +++ b/helpfuncs.go @@ -23,6 +23,25 @@ func isASCII(s string) bool { return true } +// stripThinkingFromMsg removes thinking blocks from assistant messages. +// Skips user, tool, and system messages as they may contain thinking examples. +func stripThinkingFromMsg(msg models.RoleMsg) *models.RoleMsg { + if !cfg.StripThinkingFromAPI { + return &msg + } + // Skip user, tool, and system messages - they might contain thinking examples + if msg.Role == cfg.UserRole || msg.Role == cfg.ToolRole || msg.Role == "system" { + return &msg + } + // Strip thinking from assistant messages + if thinkRE.MatchString(msg.Content) { + msg.Content = thinkRE.ReplaceAllString(msg.Content, "") + // Clean up any double newlines that might result + msg.Content = strings.TrimSpace(msg.Content) + } + return &msg +} + // refreshChatDisplay updates the chat display based on current character view // It filters messages for the character the user is currently "writing as" // and updates the textView with the filtered conversation -- cgit v1.2.3