mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix(text): fix resolve emoji shown in telegram stream mode (#261)
* 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
This commit is contained in:
@@ -401,10 +401,11 @@ func (s *telegramOutboundStream) pushFinal(ctx context.Context, event channel.St
|
|||||||
|
|
||||||
msg := event.Final.Message
|
msg := event.Final.Message
|
||||||
finalText := bufText
|
finalText := bufText
|
||||||
if finalText == "" && !s.isPrivateChat {
|
if authoritative := strings.TrimSpace(msg.PlainText()); authoritative != "" {
|
||||||
finalText = strings.TrimSpace(msg.PlainText())
|
if !s.isPrivateChat || bufText != "" {
|
||||||
|
finalText = authoritative
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert markdown to Telegram HTML for the final message.
|
// Convert markdown to Telegram HTML for the final message.
|
||||||
formatted, pm := formatTelegramOutput(finalText, msg.Format)
|
formatted, pm := formatTelegramOutput(finalText, msg.Format)
|
||||||
if pm != "" {
|
if pm != "" {
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio
|
|||||||
if msg.Role != "assistant" {
|
if msg.Role != "assistant" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// skip tool call tips content.
|
||||||
|
if hasToolCallContent(msg) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
content := strings.TrimSpace(msg.TextContent())
|
content := strings.TrimSpace(msg.TextContent())
|
||||||
parts := filterContentParts(msg.ContentParts())
|
parts := filterContentParts(msg.ContentParts())
|
||||||
if content == "" && len(parts) == 0 {
|
if content == "" && len(parts) == 0 {
|
||||||
@@ -26,12 +30,28 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio
|
|||||||
return outputs
|
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 {
|
func filterContentParts(parts []conversation.ContentPart) []conversation.ContentPart {
|
||||||
if len(parts) == 0 {
|
if len(parts) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
filtered := make([]conversation.ContentPart, 0, len(parts))
|
filtered := make([]conversation.ContentPart, 0, len(parts))
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
|
// Ignore Reasoning parts
|
||||||
|
if p.Type == "reasoning" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if p.HasValue() {
|
if p.HasValue() {
|
||||||
filtered = append(filtered, p)
|
filtered = append(filtered, p)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,10 @@ func (m ModelMessage) TextContent() string {
|
|||||||
if err := json.Unmarshal(m.Content, &parts); err == nil {
|
if err := json.Unmarshal(m.Content, &parts); err == nil {
|
||||||
texts := make([]string, 0, len(parts))
|
texts := make([]string, 0, len(parts))
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
|
// Ignore Reasoning parts
|
||||||
|
if p.Type == "reasoning" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if strings.TrimSpace(p.Text) != "" {
|
if strings.TrimSpace(p.Text) != "" {
|
||||||
texts = append(texts, p.Text)
|
texts = append(texts, p.Text)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user