chore(gallery agent): strip thinking tags (#7464)

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-12-07 19:25:41 +01:00
committed by GitHub
parent 262afd28a0
commit 18b8956bd9

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"slices"
"strings"
@@ -45,7 +46,7 @@ func cleanTextContent(text string) string {
}
// Remove trailing empty lines from the result
result := strings.Join(cleanedLines, "\n")
return strings.TrimRight(result, "\n")
return stripThinkingTags(strings.TrimRight(result, "\n"))
}
// isModelExisting checks if a specific model ID exists in the gallery using text search
@@ -92,6 +93,16 @@ func getGalleryIndexPath() string {
return "gallery/index.yaml"
}
func stripThinkingTags(content string) string {
// Remove content between <thinking> and </thinking> (including multi-line)
content = regexp.MustCompile(`(?s)<thinking>.*?</thinking>`).ReplaceAllString(content, "")
// Remove content between <think> and </think> (including multi-line)
content = regexp.MustCompile(`(?s)<think>.*?</think>`).ReplaceAllString(content, "")
// Clean up any extra whitespace
content = strings.TrimSpace(content)
return content
}
func getRealReadme(ctx context.Context, repository string) (string, error) {
// Create a conversation fragment
fragment := cogito.NewEmptyFragment().