From 9ab812a8e8b3626d19dcd720213738347d9f8307 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Mon, 29 Dec 2025 10:06:42 +0100 Subject: [PATCH] chore(ci): be more precise when detecting existing models (#7767) Signed-off-by: Ettore Di Giacinto --- .github/gallery-agent/agent.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/gallery-agent/agent.go b/.github/gallery-agent/agent.go index 5efd58dd2..0b9f647b5 100644 --- a/.github/gallery-agent/agent.go +++ b/.github/gallery-agent/agent.go @@ -11,6 +11,7 @@ import ( "slices" "strings" + "github.com/ghodss/yaml" hfapi "github.com/mudler/LocalAI/pkg/huggingface-api" cogito "github.com/mudler/cogito" @@ -52,6 +53,11 @@ func cleanTextContent(text string) string { return stripThinkingTags(strings.TrimRight(result, "\n")) } +type galleryModel struct { + Name string `yaml:"name"` + Urls []string `yaml:"urls"` +} + // isModelExisting checks if a specific model ID exists in the gallery using text search func isModelExisting(modelID string) (bool, error) { indexPath := getGalleryIndexPath() @@ -60,9 +66,20 @@ func isModelExisting(modelID string) (bool, error) { return false, fmt.Errorf("failed to read %s: %w", indexPath, err) } - contentStr := string(content) - // Simple text search - if the model ID appears anywhere in the file, it exists - return strings.Contains(contentStr, modelID), nil + var galleryModels []galleryModel + + err = yaml.Unmarshal(content, &galleryModels) + if err != nil { + return false, fmt.Errorf("failed to unmarshal %s: %w", indexPath, err) + } + + for _, galleryModel := range galleryModels { + if slices.Contains(galleryModel.Urls, modelID) { + return true, nil + } + } + + return false, nil } // filterExistingModels removes models that already exist in the gallery