mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
a246b79a4f
- 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
37 lines
879 B
Go
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
|
|
}
|