Skip to content

Commit 18b8956

Browse files
authored
chore(gallery agent): strip thinking tags (#7464)
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 262afd2 commit 18b8956

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

.github/gallery-agent/agent.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"regexp"
78
"slices"
89
"strings"
910

@@ -45,7 +46,7 @@ func cleanTextContent(text string) string {
4546
}
4647
// Remove trailing empty lines from the result
4748
result := strings.Join(cleanedLines, "\n")
48-
return strings.TrimRight(result, "\n")
49+
return stripThinkingTags(strings.TrimRight(result, "\n"))
4950
}
5051

5152
// isModelExisting checks if a specific model ID exists in the gallery using text search
@@ -92,6 +93,16 @@ func getGalleryIndexPath() string {
9293
return "gallery/index.yaml"
9394
}
9495

96+
func stripThinkingTags(content string) string {
97+
// Remove content between <thinking> and </thinking> (including multi-line)
98+
content = regexp.MustCompile(`(?s)<thinking>.*?</thinking>`).ReplaceAllString(content, "")
99+
// Remove content between <think> and </think> (including multi-line)
100+
content = regexp.MustCompile(`(?s)<think>.*?</think>`).ReplaceAllString(content, "")
101+
// Clean up any extra whitespace
102+
content = strings.TrimSpace(content)
103+
return content
104+
}
105+
95106
func getRealReadme(ctx context.Context, repository string) (string, error) {
96107
// Create a conversation fragment
97108
fragment := cogito.NewEmptyFragment().

0 commit comments

Comments
 (0)