From e3c588f39979add2801c6d0662eadf2d16c26234 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 17 Sep 2024 00:19:21 -0400 Subject: [PATCH 01/14] add api key to existing app tests, add preliminary auth test Signed-off-by: Dave Lee --- core/http/app.go | 18 ---------------- core/http/app_test.go | 43 +++++++++++++++++++++++++++++++++++++ core/http/routes/localai.go | 2 +- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/core/http/app.go b/core/http/app.go index fa9cd866926..23e97f18d92 100644 --- a/core/http/app.go +++ b/core/http/app.go @@ -31,24 +31,6 @@ import ( "github.com/rs/zerolog/log" ) -func readAuthHeader(c *fiber.Ctx) string { - authHeader := c.Get("Authorization") - - // elevenlabs - xApiKey := c.Get("xi-api-key") - if xApiKey != "" { - authHeader = "Bearer " + xApiKey - } - - // anthropic - xApiKey = c.Get("x-api-key") - if xApiKey != "" { - authHeader = "Bearer " + xApiKey - } - - return authHeader -} - // Embed a directory // //go:embed static/* diff --git a/core/http/app_test.go b/core/http/app_test.go index 86fe7fdddbf..18ba7c49013 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -31,6 +31,8 @@ import ( "github.com/sashabaranov/go-openai/jsonschema" ) +const apiKey = "joshua" + const testPrompt = `### System: You are an AI assistant that follows instruction extremely well. Help as much as you can. @@ -101,6 +103,7 @@ func postModelApplyRequest(url string, request modelApplyRequest) (response map[ return } req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", "Bearer "+apiKey) // Make the request client := &http.Client{} @@ -140,6 +143,7 @@ func postRequestJSON[B any](url string, bodyJson *B) error { } req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", "Bearer "+apiKey) client := &http.Client{} resp, err := client.Do(req) @@ -175,6 +179,7 @@ func postRequestResponseJSON[B1 any, B2 any](url string, reqJson *B1, respJson * } req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", "Bearer "+apiKey) client := &http.Client{} resp, err := client.Do(req) @@ -195,6 +200,35 @@ func postRequestResponseJSON[B1 any, B2 any](url string, reqJson *B1, respJson * return json.Unmarshal(body, respJson) } +func postInvalidRequest(url string) (error, int) { + + req, err := http.NewRequest("POST", url, bytes.NewBufferString("invalid request")) + if err != nil { + return err, -1 + } + + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err, -1 + } + + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + return err, -1 + } + + if resp.StatusCode < 200 || resp.StatusCode >= 400 { + return fmt.Errorf("unexpected status code: %d, body: %s", resp.StatusCode, string(body)), resp.StatusCode + } + + return nil, resp.StatusCode +} + //go:embed backend-assets/* var backendAssets embed.FS @@ -260,6 +294,7 @@ var _ = Describe("API test", func() { config.WithContext(c), config.WithGalleries(galleries), config.WithModelPath(modelDir), + config.WithApiKeys([]string{apiKey}), config.WithBackendAssets(backendAssets), config.WithBackendAssetsOutput(backendAssetsDir))...) Expect(err).ToNot(HaveOccurred()) @@ -295,6 +330,14 @@ var _ = Describe("API test", func() { Expect(err).To(HaveOccurred()) }) + Context("Auth Tests", func() { + It("Should fail if the api key is missing", func() { + err, sc := postInvalidRequest("http://127.0.0.1:9090/models/available") + Expect(err).ToNot(BeNil()) + Expect(sc).To(Equal(403)) + }) + }) + Context("Applying models", func() { It("applies models from a gallery", func() { diff --git a/core/http/routes/localai.go b/core/http/routes/localai.go index 29fef37876d..247596c0e20 100644 --- a/core/http/routes/localai.go +++ b/core/http/routes/localai.go @@ -69,6 +69,6 @@ func RegisterLocalAIRoutes(app *fiber.App, }{Version: internal.PrintableVersion()}) }) - app.Get("/system", auth, localai.SystemInformations(ml, appConfig)) + app.Get("/system", localai.SystemInformations(ml, appConfig)) } From 9519c5148d5fa5948975ccaacfbcbba8e2d6fd41 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 17 Sep 2024 16:43:45 -0400 Subject: [PATCH 02/14] small fix, run test Signed-off-by: Dave Lee --- core/http/app_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/http/app_test.go b/core/http/app_test.go index 18ba7c49013..5ef1e2548b4 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -304,7 +304,7 @@ var _ = Describe("API test", func() { go app.Listen("127.0.0.1:9090") - defaultConfig := openai.DefaultConfig("") + defaultConfig := openai.DefaultConfig(apiKey) defaultConfig.BaseURL = "http://127.0.0.1:9090/v1" client2 = openaigo.NewClient("") From d5f0f7a4ea363b5266e1efd4402d7055e2e3f67c Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 17 Sep 2024 18:04:29 -0400 Subject: [PATCH 03/14] status on non-opaque Signed-off-by: Dave Lee --- core/http/middleware/auth.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/http/middleware/auth.go b/core/http/middleware/auth.go index bc8bcf80c20..988e5b4c592 100644 --- a/core/http/middleware/auth.go +++ b/core/http/middleware/auth.go @@ -42,6 +42,10 @@ func getApiKeyErrorHandler(applicationConfig *config.ApplicationConfig) fiber.Er if applicationConfig.OpaqueErrors { return ctx.SendStatus(500) } + e2 := ctx.SendStatus(403) + if e2 != nil { + err = errors.Join(err, e2) + } return err } } @@ -90,4 +94,4 @@ func getApiKeyRequiredFilterFunction(applicationConfig *config.ApplicationConfig } } return func(c *fiber.Ctx) bool { return false } -} \ No newline at end of file +} From 9a2790a3470a2b5e853ba546d7008725210804c8 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 17 Sep 2024 18:45:34 -0400 Subject: [PATCH 04/14] tweak auth error Signed-off-by: Dave Lee --- .devcontainer-scripts/utils.sh | 2 ++ core/http/middleware/auth.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.devcontainer-scripts/utils.sh b/.devcontainer-scripts/utils.sh index 98ac063cfdb..8416d43d578 100644 --- a/.devcontainer-scripts/utils.sh +++ b/.devcontainer-scripts/utils.sh @@ -9,6 +9,7 @@ # Param 2: email # config_user() { + echo "Configuring git for $1 <$2>" local gcn=$(git config --global user.name) if [ -z "${gcn}" ]; then echo "Setting up git user / remote" @@ -24,6 +25,7 @@ config_user() { # Param 2: remote url # config_remote() { + echo "Adding git remote and fetching $2 as $1" local gr=$(git remote -v | grep $1) if [ -z "${gr}" ]; then git remote add $1 $2 diff --git a/core/http/middleware/auth.go b/core/http/middleware/auth.go index 988e5b4c592..8c1e0dae8bb 100644 --- a/core/http/middleware/auth.go +++ b/core/http/middleware/auth.go @@ -38,14 +38,14 @@ func getApiKeyErrorHandler(applicationConfig *config.ApplicationConfig) fiber.Er if applicationConfig.OpaqueErrors { return ctx.SendStatus(403) } + e2 := ctx.SendStatus(403) + if e2 != nil { + err = errors.Join(err, e2) + } } if applicationConfig.OpaqueErrors { return ctx.SendStatus(500) } - e2 := ctx.SendStatus(403) - if e2 != nil { - err = errors.Join(err, e2) - } return err } } From 32a26e0675a043aed162202f4433e988be1a1acd Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Tue, 17 Sep 2024 20:18:03 -0400 Subject: [PATCH 05/14] exp Signed-off-by: Dave Lee --- core/http/middleware/auth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/http/middleware/auth.go b/core/http/middleware/auth.go index 8c1e0dae8bb..74858ea1be8 100644 --- a/core/http/middleware/auth.go +++ b/core/http/middleware/auth.go @@ -40,7 +40,7 @@ func getApiKeyErrorHandler(applicationConfig *config.ApplicationConfig) fiber.Er } e2 := ctx.SendStatus(403) if e2 != nil { - err = errors.Join(err, e2) + err = errors.Join(e2, err) } } if applicationConfig.OpaqueErrors { From a882b1cf8ff5f2ab1cda5a765eac0e505dcceea5 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 18 Sep 2024 14:10:12 -0400 Subject: [PATCH 06/14] quick fix on real laptop Signed-off-by: Dave Lee --- core/http/middleware/auth.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/http/middleware/auth.go b/core/http/middleware/auth.go index 74858ea1be8..d2152e9b39c 100644 --- a/core/http/middleware/auth.go +++ b/core/http/middleware/auth.go @@ -38,10 +38,7 @@ func getApiKeyErrorHandler(applicationConfig *config.ApplicationConfig) fiber.Er if applicationConfig.OpaqueErrors { return ctx.SendStatus(403) } - e2 := ctx.SendStatus(403) - if e2 != nil { - err = errors.Join(e2, err) - } + return ctx.Status(403).SendString(err.Error()) } if applicationConfig.OpaqueErrors { return ctx.SendStatus(500) From 0656fabf2ab7b583a889a8022e29a3b660168bab Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Wed, 18 Sep 2024 17:32:53 -0400 Subject: [PATCH 07/14] add downloader version that allows providing an auth header Signed-off-by: Dave Lee --- core/http/app_test.go | 20 ++++++++++++-------- pkg/downloader/uri.go | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/core/http/app_test.go b/core/http/app_test.go index 5ef1e2548b4..22994e98d8e 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -32,6 +32,7 @@ import ( ) const apiKey = "joshua" +const bearerKey = "Bearer " + apiKey const testPrompt = `### System: You are an AI assistant that follows instruction extremely well. Help as much as you can. @@ -74,14 +75,15 @@ func getModelStatus(url string) (response map[string]interface{}) { return } -func getModels(url string) (response []gallery.GalleryModel) { +func getModels(url string) ([]gallery.GalleryModel, error) { + response := []gallery.GalleryModel{} uri := downloader.URI(url) // TODO: No tests currently seem to exercise file:// urls. Fix? - uri.DownloadAndUnmarshal("", func(url string, i []byte) error { + err := uri.DownloadWithAuthorizationAndUnmarshal("", bearerKey, func(url string, i []byte) error { // Unmarshal YAML data into a struct return json.Unmarshal(i, &response) }) - return + return response, err } func postModelApplyRequest(url string, request modelApplyRequest) (response map[string]interface{}) { @@ -103,7 +105,7 @@ func postModelApplyRequest(url string, request modelApplyRequest) (response map[ return } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+apiKey) + req.Header.Set("Authorization", bearerKey) // Make the request client := &http.Client{} @@ -143,7 +145,7 @@ func postRequestJSON[B any](url string, bodyJson *B) error { } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+apiKey) + req.Header.Set("Authorization", bearerKey) client := &http.Client{} resp, err := client.Do(req) @@ -179,7 +181,7 @@ func postRequestResponseJSON[B1 any, B2 any](url string, reqJson *B1, respJson * } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Authorization", "Bearer "+apiKey) + req.Header.Set("Authorization", bearerKey) client := &http.Client{} resp, err := client.Do(req) @@ -341,7 +343,8 @@ var _ = Describe("API test", func() { Context("Applying models", func() { It("applies models from a gallery", func() { - models := getModels("http://127.0.0.1:9090/models/available") + models, err := getModels("http://127.0.0.1:9090/models/available") + Expect(err).To(BeNil()) Expect(len(models)).To(Equal(2), fmt.Sprint(models)) Expect(models[0].Installed).To(BeFalse(), fmt.Sprint(models)) Expect(models[1].Installed).To(BeFalse(), fmt.Sprint(models)) @@ -374,7 +377,8 @@ var _ = Describe("API test", func() { Expect(content["backend"]).To(Equal("bert-embeddings")) Expect(content["foo"]).To(Equal("bar")) - models = getModels("http://127.0.0.1:9090/models/available") + models, err = getModels("http://127.0.0.1:9090/models/available") + Expect(err).To(BeNil()) Expect(len(models)).To(Equal(2), fmt.Sprint(models)) Expect(models[0].Name).To(Or(Equal("bert"), Equal("bert2"))) Expect(models[1].Name).To(Or(Equal("bert"), Equal("bert2"))) diff --git a/pkg/downloader/uri.go b/pkg/downloader/uri.go index 7fedd646120..d74d353d8ac 100644 --- a/pkg/downloader/uri.go +++ b/pkg/downloader/uri.go @@ -32,6 +32,10 @@ const ( type URI string func (uri URI) DownloadAndUnmarshal(basePath string, f func(url string, i []byte) error) error { + return uri.DownloadWithAuthorizationAndUnmarshal(basePath, "", f) +} + +func (uri URI) DownloadWithAuthorizationAndUnmarshal(basePath string, authorization string, f func(url string, i []byte) error) error { url := uri.ResolveURL() if strings.HasPrefix(url, LocalPrefix) { @@ -63,7 +67,16 @@ func (uri URI) DownloadAndUnmarshal(basePath string, f func(url string, i []byte } // Send a GET request to the URL - response, err := http.Get(url) + + req, err := http.NewRequest("GET", url, nil) + if err != nil { + return err + } + if authorization != "" { + req.Header.Add("Authorization", authorization) + } + + response, err := http.DefaultClient.Do(req) if err != nil { return err } From 0edf49b19dade4a140e4c562805a2f2ca918f817 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 19 Sep 2024 13:01:10 -0400 Subject: [PATCH 08/14] stash some devcontainer fixes during testing Signed-off-by: Dave Lee --- Dockerfile | 5 ++--- Makefile | 3 +++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index f08cb9a03b2..8dd6e1d5b01 100644 --- a/Dockerfile +++ b/Dockerfile @@ -338,9 +338,8 @@ RUN if [ "${FFMPEG}" = "true" ]; then \ RUN apt-get update && \ apt-get install -y --no-install-recommends \ - ssh less && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + ssh less wget +# For the devcontainer, leave apt functional in case additional devtools are needed at runtime. RUN go install github.com/go-delve/delve/cmd/dlv@latest diff --git a/Makefile b/Makefile index 286f4b5a2a1..9723c8ce730 100644 --- a/Makefile +++ b/Makefile @@ -359,6 +359,9 @@ clean-tests: rm -rf test-dir rm -rf core/http/backend-assets +clean-dc: clean clean-tests + cp -r /build/backend-assets /workspace/backend-assets + ## Build: build: prepare backend-assets grpcs ## Build the project $(info ${GREEN}I local-ai build info:${RESET}) From 5ebd37eaa179bb3ac68b6895c63b582a04487f88 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 19 Sep 2024 14:22:27 -0400 Subject: [PATCH 09/14] s2 Signed-off-by: Dave Lee --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 9723c8ce730..c560b80eb1f 100644 --- a/Makefile +++ b/Makefile @@ -361,6 +361,7 @@ clean-tests: clean-dc: clean clean-tests cp -r /build/backend-assets /workspace/backend-assets + touch sources/go-stable-diffusion ## Build: build: prepare backend-assets grpcs ## Build the project From fbb7e0e1db25f5a6d9783fc3488fa3437176a387 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 19 Sep 2024 21:54:31 -0400 Subject: [PATCH 10/14] s Signed-off-by: Dave Lee --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c560b80eb1f..b7ed5cfc524 100644 --- a/Makefile +++ b/Makefile @@ -361,7 +361,8 @@ clean-tests: clean-dc: clean clean-tests cp -r /build/backend-assets /workspace/backend-assets - touch sources/go-stable-diffusion + mkdir -p sources/go-stable-diffusion + touch sources/go-stable-diffusion/dc ## Build: build: prepare backend-assets grpcs ## Build the project From a5333436f4fdae101367dec98c70dd89bf9fbdf1 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 19 Sep 2024 22:04:45 -0400 Subject: [PATCH 11/14] done with experiment Signed-off-by: Dave Lee --- Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile b/Makefile index b7ed5cfc524..286f4b5a2a1 100644 --- a/Makefile +++ b/Makefile @@ -359,11 +359,6 @@ clean-tests: rm -rf test-dir rm -rf core/http/backend-assets -clean-dc: clean clean-tests - cp -r /build/backend-assets /workspace/backend-assets - mkdir -p sources/go-stable-diffusion - touch sources/go-stable-diffusion/dc - ## Build: build: prepare backend-assets grpcs ## Build the project $(info ${GREEN}I local-ai build info:${RESET}) From ca58a81cb7d743790fc55d3a9479d7c86bb1559a Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Thu, 19 Sep 2024 22:07:49 -0400 Subject: [PATCH 12/14] done with experiment Signed-off-by: Dave Lee --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 286f4b5a2a1..9723c8ce730 100644 --- a/Makefile +++ b/Makefile @@ -359,6 +359,9 @@ clean-tests: rm -rf test-dir rm -rf core/http/backend-assets +clean-dc: clean clean-tests + cp -r /build/backend-assets /workspace/backend-assets + ## Build: build: prepare backend-assets grpcs ## Build the project $(info ${GREEN}I local-ai build info:${RESET}) From eef31755d50c7197e67bd901aecee7944884f4f1 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Sep 2024 10:24:57 -0400 Subject: [PATCH 13/14] after merge fix Signed-off-by: Dave Lee --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1f5f6f2624c..84bae34fde4 100644 --- a/Makefile +++ b/Makefile @@ -359,7 +359,7 @@ clean-tests: rm -rf test-dir rm -rf core/http/backend-assets -clean-dc: clean clean-tests +clean-dc: clean cp -r /build/backend-assets /workspace/backend-assets ## Build: From 7534795dc3afb1502cb6156d5e7fcd0088fae2b7 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 23 Sep 2024 13:41:22 -0400 Subject: [PATCH 14/14] rename and fix Signed-off-by: Dave Lee --- core/gallery/gallery.go | 4 ++-- core/gallery/models.go | 2 +- core/http/app_test.go | 12 ++++++++++-- embedded/embedded.go | 2 +- go.mod | 4 ++-- pkg/downloader/uri.go | 7 +++---- pkg/downloader/uri_test.go | 6 +++--- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/core/gallery/gallery.go b/core/gallery/gallery.go index 6ced6244128..3a60e618a32 100644 --- a/core/gallery/gallery.go +++ b/core/gallery/gallery.go @@ -132,7 +132,7 @@ func AvailableGalleryModels(galleries []config.Gallery, basePath string) ([]*Gal func findGalleryURLFromReferenceURL(url string, basePath string) (string, error) { var refFile string uri := downloader.URI(url) - err := uri.DownloadAndUnmarshal(basePath, func(url string, d []byte) error { + err := uri.DownloadWithCallback(basePath, func(url string, d []byte) error { refFile = string(d) if len(refFile) == 0 { return fmt.Errorf("invalid reference file at url %s: %s", url, d) @@ -156,7 +156,7 @@ func getGalleryModels(gallery config.Gallery, basePath string) ([]*GalleryModel, } uri := downloader.URI(gallery.URL) - err := uri.DownloadAndUnmarshal(basePath, func(url string, d []byte) error { + err := uri.DownloadWithCallback(basePath, func(url string, d []byte) error { return yaml.Unmarshal(d, &models) }) if err != nil { diff --git a/core/gallery/models.go b/core/gallery/models.go index dec6312eaf3..58f1963a533 100644 --- a/core/gallery/models.go +++ b/core/gallery/models.go @@ -69,7 +69,7 @@ type PromptTemplate struct { func GetGalleryConfigFromURL(url string, basePath string) (Config, error) { var config Config uri := downloader.URI(url) - err := uri.DownloadAndUnmarshal(basePath, func(url string, d []byte) error { + err := uri.DownloadWithCallback(basePath, func(url string, d []byte) error { return yaml.Unmarshal(d, &config) }) if err != nil { diff --git a/core/http/app_test.go b/core/http/app_test.go index 22994e98d8e..bbe52c34182 100644 --- a/core/http/app_test.go +++ b/core/http/app_test.go @@ -53,11 +53,19 @@ type modelApplyRequest struct { func getModelStatus(url string) (response map[string]interface{}) { // Create the HTTP request - resp, err := http.Get(url) + req, err := http.NewRequest("GET", url, nil) + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Authorization", bearerKey) if err != nil { fmt.Println("Error creating request:", err) return } + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + fmt.Println("Error sending request:", err) + return + } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) @@ -79,7 +87,7 @@ func getModels(url string) ([]gallery.GalleryModel, error) { response := []gallery.GalleryModel{} uri := downloader.URI(url) // TODO: No tests currently seem to exercise file:// urls. Fix? - err := uri.DownloadWithAuthorizationAndUnmarshal("", bearerKey, func(url string, i []byte) error { + err := uri.DownloadWithAuthorizationAndCallback("", bearerKey, func(url string, i []byte) error { // Unmarshal YAML data into a struct return json.Unmarshal(i, &response) }) diff --git a/embedded/embedded.go b/embedded/embedded.go index 672c32edd63..3a4ea2628d4 100644 --- a/embedded/embedded.go +++ b/embedded/embedded.go @@ -39,7 +39,7 @@ func init() { func GetRemoteLibraryShorteners(url string, basePath string) (map[string]string, error) { remoteLibrary := map[string]string{} uri := downloader.URI(url) - err := uri.DownloadAndUnmarshal(basePath, func(_ string, i []byte) error { + err := uri.DownloadWithCallback(basePath, func(_ string, i []byte) error { return yaml.Unmarshal(i, &remoteLibrary) }) if err != nil { diff --git a/go.mod b/go.mod index a3359abf661..dd8fce9f533 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ module github.com/mudler/LocalAI -go 1.22.0 +go 1.23 -toolchain go1.22.4 +toolchain go1.23.1 require ( dario.cat/mergo v1.0.0 diff --git a/pkg/downloader/uri.go b/pkg/downloader/uri.go index d74d353d8ac..9acbb621737 100644 --- a/pkg/downloader/uri.go +++ b/pkg/downloader/uri.go @@ -31,11 +31,11 @@ const ( type URI string -func (uri URI) DownloadAndUnmarshal(basePath string, f func(url string, i []byte) error) error { - return uri.DownloadWithAuthorizationAndUnmarshal(basePath, "", f) +func (uri URI) DownloadWithCallback(basePath string, f func(url string, i []byte) error) error { + return uri.DownloadWithAuthorizationAndCallback(basePath, "", f) } -func (uri URI) DownloadWithAuthorizationAndUnmarshal(basePath string, authorization string, f func(url string, i []byte) error) error { +func (uri URI) DownloadWithAuthorizationAndCallback(basePath string, authorization string, f func(url string, i []byte) error) error { url := uri.ResolveURL() if strings.HasPrefix(url, LocalPrefix) { @@ -45,7 +45,6 @@ func (uri URI) DownloadWithAuthorizationAndUnmarshal(basePath string, authorizat if err != nil { return err } - // ??? resolvedBasePath, err := filepath.EvalSymlinks(basePath) if err != nil { return err diff --git a/pkg/downloader/uri_test.go b/pkg/downloader/uri_test.go index 21a093a9550..3b7a80b3ee9 100644 --- a/pkg/downloader/uri_test.go +++ b/pkg/downloader/uri_test.go @@ -11,7 +11,7 @@ var _ = Describe("Gallery API tests", func() { It("parses github with a branch", func() { uri := URI("github:go-skynet/model-gallery/gpt4all-j.yaml") Expect( - uri.DownloadAndUnmarshal("", func(url string, i []byte) error { + uri.DownloadWithCallback("", func(url string, i []byte) error { Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml")) return nil }), @@ -21,7 +21,7 @@ var _ = Describe("Gallery API tests", func() { uri := URI("github:go-skynet/model-gallery/gpt4all-j.yaml@main") Expect( - uri.DownloadAndUnmarshal("", func(url string, i []byte) error { + uri.DownloadWithCallback("", func(url string, i []byte) error { Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml")) return nil }), @@ -30,7 +30,7 @@ var _ = Describe("Gallery API tests", func() { It("parses github with urls", func() { uri := URI("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml") Expect( - uri.DownloadAndUnmarshal("", func(url string, i []byte) error { + uri.DownloadWithCallback("", func(url string, i []byte) error { Expect(url).To(Equal("https://raw.githubusercontent.com/go-skynet/model-gallery/main/gpt4all-j.yaml")) return nil }),