Files
Memoh/internal/chat/assistant_output.go
T
BBQ a246b79a4f refactor: restructure channel gateway and chat module architecture
- Refactor channel adapters (feishu, telegram, local) with enhanced descriptor and config
- Restructure channel manager, service, types, and outbound messaging
- Simplify chat module by removing normalize.go and chat.go, consolidating into resolver and types
- Update router channel handlers and tests
- Sync swagger documentation
2026-02-06 23:47:12 +08:00

37 lines
879 B
Go

package chat
import "strings"
// ExtractAssistantOutputs collects assistant-role outputs from a slice of ModelMessages.
func ExtractAssistantOutputs(messages []ModelMessage) []AssistantOutput {
if len(messages) == 0 {
return nil
}
outputs := make([]AssistantOutput, 0, len(messages))
for _, msg := range messages {
if msg.Role != "assistant" {
continue
}
content := strings.TrimSpace(msg.TextContent())
parts := filterContentParts(msg.ContentParts())
if content == "" && len(parts) == 0 {
continue
}
outputs = append(outputs, AssistantOutput{Content: content, Parts: parts})
}
return outputs
}
func filterContentParts(parts []ContentPart) []ContentPart {
if len(parts) == 0 {
return nil
}
filtered := make([]ContentPart, 0, len(parts))
for _, p := range parts {
if p.HasValue() {
filtered = append(filtered, p)
}
}
return filtered
}