mirror of
https://github.com/mudler/LocalAI.git
synced 2026-01-06 02:29:54 -06:00
chore(gallery agent): clean content
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
29
.github/gallery-agent/agent.go
vendored
29
.github/gallery-agent/agent.go
vendored
@@ -23,6 +23,29 @@ var (
|
||||
llm = cogito.NewOpenAILLM(openAIModel, openAIKey, openAIBaseURL)
|
||||
)
|
||||
|
||||
// cleanTextContent removes trailing spaces, tabs, and normalizes line endings
|
||||
// to prevent YAML linting issues like trailing spaces and multiple empty lines
|
||||
func cleanTextContent(text string) string {
|
||||
lines := strings.Split(text, "\n")
|
||||
var cleanedLines []string
|
||||
var prevEmpty bool
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimRight(line, "\t")
|
||||
trimmed = strings.TrimSpace(trimmed)
|
||||
// Avoid multiple consecutive empty lines
|
||||
if trimmed == "" {
|
||||
if !prevEmpty {
|
||||
cleanedLines = append(cleanedLines, trimmed)
|
||||
}
|
||||
prevEmpty = true
|
||||
} else {
|
||||
cleanedLines = append(cleanedLines, trimmed)
|
||||
prevEmpty = false
|
||||
}
|
||||
}
|
||||
return strings.Join(cleanedLines, "\n")
|
||||
}
|
||||
|
||||
// getGalleryIndexPath returns the gallery index file path, with a default fallback
|
||||
func getGalleryIndexPath() string {
|
||||
if galleryIndexPath != "" {
|
||||
@@ -54,7 +77,8 @@ func getRealReadme(ctx context.Context, repository string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return newFragment.LastMessage().Content, nil
|
||||
content := newFragment.LastMessage().Content
|
||||
return cleanTextContent(content), nil
|
||||
}
|
||||
|
||||
func selectMostInterestingModels(ctx context.Context, searchResult *SearchResult) ([]ProcessedModel, error) {
|
||||
@@ -255,6 +279,9 @@ func generateYAMLEntry(model ProcessedModel, familyAnchor string) string {
|
||||
description = fmt.Sprintf("AI model: %s", modelName)
|
||||
}
|
||||
|
||||
// Clean up description to prevent YAML linting issues
|
||||
description = cleanTextContent(description)
|
||||
|
||||
// Format description for YAML (indent each line)
|
||||
formattedDescription := strings.ReplaceAll(description, "\n", "\n ")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user