mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
ebf238a568
* fix(text): resolve emoji shown in telegram stream mode * chore(text): removing "reasoing" types in plain msg. * feat(conversation): add function to check for tool call content in assistant outputs
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package flow
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/memohai/memoh/internal/conversation"
|
|
)
|
|
|
|
// ExtractAssistantOutputs collects assistant-role outputs from a slice of ModelMessages.
|
|
func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversation.AssistantOutput {
|
|
if len(messages) == 0 {
|
|
return nil
|
|
}
|
|
outputs := make([]conversation.AssistantOutput, 0, len(messages))
|
|
for _, msg := range messages {
|
|
if msg.Role != "assistant" {
|
|
continue
|
|
}
|
|
// skip tool call tips content.
|
|
if hasToolCallContent(msg) {
|
|
continue
|
|
}
|
|
content := strings.TrimSpace(msg.TextContent())
|
|
parts := filterContentParts(msg.ContentParts())
|
|
if content == "" && len(parts) == 0 {
|
|
continue
|
|
}
|
|
outputs = append(outputs, conversation.AssistantOutput{Content: content, Parts: parts})
|
|
}
|
|
return outputs
|
|
}
|
|
|
|
func hasToolCallContent(msg conversation.ModelMessage) bool {
|
|
if len(msg.ToolCalls) > 0 {
|
|
return true
|
|
}
|
|
for _, p := range msg.ContentParts() {
|
|
if p.Type == "tool-call" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func filterContentParts(parts []conversation.ContentPart) []conversation.ContentPart {
|
|
if len(parts) == 0 {
|
|
return nil
|
|
}
|
|
filtered := make([]conversation.ContentPart, 0, len(parts))
|
|
for _, p := range parts {
|
|
// Ignore Reasoning parts
|
|
if p.Type == "reasoning" {
|
|
continue
|
|
}
|
|
if p.HasValue() {
|
|
filtered = append(filtered, p)
|
|
}
|
|
}
|
|
return filtered
|
|
}
|