diff --git a/core/gallery/models_test.go b/core/gallery/models_test.go index 6229c983..ef4faed8 100644 --- a/core/gallery/models_test.go +++ b/core/gallery/models_test.go @@ -48,8 +48,10 @@ var _ = Describe("Model test", func() { defer os.RemoveAll(tempdir) gallery := []GalleryModel{{ - Name: "bert", - URL: bertEmbeddingsURL, + Metadata: Metadata{ + Name: "bert", + URL: bertEmbeddingsURL, + }, }} out, err := yaml.Marshal(gallery) Expect(err).ToNot(HaveOccurred()) diff --git a/core/gallery/request.go b/core/gallery/request.go index eec764c1..72d078a1 100644 --- a/core/gallery/request.go +++ b/core/gallery/request.go @@ -11,6 +11,14 @@ import ( // It is used to install the model by resolving the URL and downloading the files. // The other fields are used to override the configuration of the model. type GalleryModel struct { + Metadata `json:",inline" yaml:",inline"` + // config_file is read in the situation where URL is blank - and therefore this is a base config. + ConfigFile map[string]interface{} `json:"config_file,omitempty" yaml:"config_file,omitempty"` + // Overrides are used to override the configuration of the model located at URL + Overrides map[string]interface{} `json:"overrides,omitempty" yaml:"overrides,omitempty"` +} + +type Metadata struct { URL string `json:"url,omitempty" yaml:"url,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"` @@ -18,10 +26,6 @@ type GalleryModel struct { URLs []string `json:"urls,omitempty" yaml:"urls,omitempty"` Icon string `json:"icon,omitempty" yaml:"icon,omitempty"` Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` - // config_file is read in the situation where URL is blank - and therefore this is a base config. - ConfigFile map[string]interface{} `json:"config_file,omitempty" yaml:"config_file,omitempty"` - // Overrides are used to override the configuration of the model located at URL - Overrides map[string]interface{} `json:"overrides,omitempty" yaml:"overrides,omitempty"` // AdditionalFiles are used to add additional files to the model AdditionalFiles []File `json:"files,omitempty" yaml:"files,omitempty"` // Gallery is a reference to the gallery which contains the model diff --git a/core/gallery/request_test.go b/core/gallery/request_test.go index 23281cc6..ed07f474 100644 --- a/core/gallery/request_test.go +++ b/core/gallery/request_test.go @@ -9,7 +9,11 @@ import ( var _ = Describe("Gallery API tests", func() { Context("requests", func() { It("parses github with a branch", func() { - req := GalleryModel{URL: "github:go-skynet/model-gallery/gpt4all-j.yaml@main"} + req := GalleryModel{ + Metadata: Metadata{ + URL: "github:go-skynet/model-gallery/gpt4all-j.yaml@main", + }, + } e, err := GetGalleryConfigFromURL(req.URL, "") Expect(err).ToNot(HaveOccurred()) Expect(e.Name).To(Equal("gpt4all-j")) diff --git a/core/http/app_test.go b/core/http/app_test.go index bc4ecfae..ca7a2eaa 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -299,14 +299,18 @@ var _ = Describe("API test", func() { g := []gallery.GalleryModel{ { - Name: "bert", - URL: bertEmbeddingsURL, + Metadata: gallery.Metadata{ + Name: "bert", + URL: bertEmbeddingsURL, + }, }, { - Name: "bert2", - URL: bertEmbeddingsURL, - Overrides: map[string]interface{}{"foo": "bar"}, - AdditionalFiles: []gallery.File{{Filename: "foo.yaml", URI: bertEmbeddingsURL}}, + Metadata: gallery.Metadata{ + Name: "bert2", + URL: bertEmbeddingsURL, + AdditionalFiles: []gallery.File{{Filename: "foo.yaml", URI: bertEmbeddingsURL}}, + }, + Overrides: map[string]interface{}{"foo": "bar"}, }, } out, err := yaml.Marshal(g) diff --git a/core/http/endpoints/localai/gallery.go b/core/http/endpoints/localai/gallery.go index 5b2968f4..9dc99f5d 100644 --- a/core/http/endpoints/localai/gallery.go +++ b/core/http/endpoints/localai/gallery.go @@ -117,19 +117,25 @@ func (mgs *ModelGalleryEndpointService) DeleteModelGalleryEndpoint() func(c *fib // @Router /models/available [get] func (mgs *ModelGalleryEndpointService) ListModelFromGalleryEndpoint() func(c *fiber.Ctx) error { return func(c *fiber.Ctx) error { - log.Debug().Msgf("Listing models from galleries: %+v", mgs.galleries) models, err := gallery.AvailableGalleryModels(mgs.galleries, mgs.modelPath) if err != nil { return err } - log.Debug().Msgf("Models found from galleries: %+v", models) - for _, m := range models { - log.Debug().Msgf("Model found from galleries: %+v", m) + + log.Debug().Msgf("Available %d models from %d galleries\n", len(models), len(mgs.galleries)) + + m := []gallery.Metadata{} + + for _, mm := range models { + m = append(m, mm.Metadata) } - dat, err := json.Marshal(models) + + log.Debug().Msgf("Models %#v", m) + + dat, err := json.Marshal(m) if err != nil { - return err + return fmt.Errorf("could not marshal models: %w", err) } return c.Send(dat) }