mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
fix(reasoning): persist canonical history for DeepSeek and web chat
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package messageutil
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/providers/protocoltypes"
|
||||
)
|
||||
|
||||
// IsTransientAssistantThoughtMessage reports whether msg is an invalid
|
||||
// reasoning-only assistant history record. These "hanging" thought messages
|
||||
// are not a canonical persisted format and should be discarded instead of
|
||||
// replayed or reconstructed.
|
||||
func IsTransientAssistantThoughtMessage(msg protocoltypes.Message) bool {
|
||||
return msg.Role == "assistant" &&
|
||||
strings.TrimSpace(msg.Content) == "" &&
|
||||
strings.TrimSpace(msg.ReasoningContent) != "" &&
|
||||
len(msg.ToolCalls) == 0 &&
|
||||
len(msg.Media) == 0 &&
|
||||
len(msg.Attachments) == 0 &&
|
||||
strings.TrimSpace(msg.ToolCallID) == ""
|
||||
}
|
||||
|
||||
// FilterInvalidHistoryMessages removes invalid persisted history records such
|
||||
// as transient assistant thought-only messages.
|
||||
func FilterInvalidHistoryMessages(history []protocoltypes.Message) []protocoltypes.Message {
|
||||
if len(history) == 0 {
|
||||
return []protocoltypes.Message{}
|
||||
}
|
||||
|
||||
filtered := make([]protocoltypes.Message, 0, len(history))
|
||||
for _, msg := range history {
|
||||
if IsTransientAssistantThoughtMessage(msg) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, msg)
|
||||
}
|
||||
if filtered == nil {
|
||||
return []protocoltypes.Message{}
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
Reference in New Issue
Block a user