From 824ee5446f498092653e647fdef2167d28e33b4b Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Fri, 10 May 2024 16:49:48 -0700 Subject: [PATCH 1/6] Fix envconfig unit test --- server/envconfig/config_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/envconfig/config_test.go b/server/envconfig/config_test.go index b2760299..bad7c4a7 100644 --- a/server/envconfig/config_test.go +++ b/server/envconfig/config_test.go @@ -1,20 +1,20 @@ package envconfig import ( - "os" "testing" "github.com/stretchr/testify/require" ) func TestConfig(t *testing.T) { - os.Setenv("OLLAMA_DEBUG", "") + Debug = false // Reset whatever was loaded in init() + t.Setenv("OLLAMA_DEBUG", "") LoadConfig() require.False(t, Debug) - os.Setenv("OLLAMA_DEBUG", "false") + t.Setenv("OLLAMA_DEBUG", "false") LoadConfig() require.False(t, Debug) - os.Setenv("OLLAMA_DEBUG", "1") + t.Setenv("OLLAMA_DEBUG", "1") LoadConfig() require.True(t, Debug) } From ec14f6ceda63183987deb328686f85ad3194e7b0 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sat, 11 May 2024 14:12:36 -0700 Subject: [PATCH 2/6] case sensitive filepaths (#4366) --- types/model/name.go | 8 +++----- types/model/name_test.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/types/model/name.go b/types/model/name.go index b79374c3..f32b2596 100644 --- a/types/model/name.go +++ b/types/model/name.go @@ -291,11 +291,9 @@ func (n Name) Filepath() string { panic("illegal attempt to get filepath of invalid name") } return filepath.Join( - strings.ToLower(filepath.Join( - n.Host, - n.Namespace, - n.Model, - )), + n.Host, + n.Namespace, + n.Model, n.Tag, ) } diff --git a/types/model/name_test.go b/types/model/name_test.go index fb584291..27a8ccf8 100644 --- a/types/model/name_test.go +++ b/types/model/name_test.go @@ -276,9 +276,9 @@ func TestFilepathAllocs(t *testing.T) { allocs := testing.AllocsPerRun(1000, func() { n.Filepath() }) - var allowedAllocs float64 = 3 + var allowedAllocs float64 = 1 if runtime.GOOS == "windows" { - allowedAllocs = 5 + allowedAllocs = 3 } if allocs > allowedAllocs { t.Errorf("allocs = %v; allowed %v", allocs, allowedAllocs) From 8080fbce35dab9087c1bd9eb6e75f44facd006df Mon Sep 17 00:00:00 2001 From: todashuta Date: Sun, 12 May 2024 06:47:49 +0900 Subject: [PATCH 3/6] fix `ollama create`'s usage string (#4362) --- cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 7814734a..fb10e53f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1050,7 +1050,7 @@ func NewCLI() *cobra.Command { RunE: CreateHandler, } - createCmd.Flags().StringP("file", "f", "Modelfile", "Name of the Modelfile (default \"Modelfile\")") + createCmd.Flags().StringP("file", "f", "Modelfile", "Name of the Modelfile") createCmd.Flags().StringP("quantize", "q", "", "Quantize model to this level (e.g. q4_0)") showCmd := &cobra.Command{ From 41ba3017fd74dfce9a3dc00160f29befec85a41b Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Sat, 11 May 2024 15:31:41 -0700 Subject: [PATCH 4/6] Fix OpenAI `finish_reason` values when empty (#4368) --- openai/openai.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/openai/openai.go b/openai/openai.go index 4b335f36..7ce29e9f 100644 --- a/openai/openai.go +++ b/openai/openai.go @@ -107,9 +107,14 @@ func toChatCompletion(id string, r api.ChatResponse) ChatCompletion { Model: r.Model, SystemFingerprint: "fp_ollama", Choices: []Choice{{ - Index: 0, - Message: Message{Role: r.Message.Role, Content: r.Message.Content}, - FinishReason: &r.DoneReason, + Index: 0, + Message: Message{Role: r.Message.Role, Content: r.Message.Content}, + FinishReason: func(reason string) *string { + if len(reason) > 0 { + return &reason + } + return nil + }(r.DoneReason), }}, Usage: Usage{ // TODO: ollama returns 0 for prompt eval if the prompt was cached, but openai returns the actual count @@ -127,13 +132,16 @@ func toChunk(id string, r api.ChatResponse) ChatCompletionChunk { Created: time.Now().Unix(), Model: r.Model, SystemFingerprint: "fp_ollama", - Choices: []ChunkChoice{ - { - Index: 0, - Delta: Message{Role: "assistant", Content: r.Message.Content}, - FinishReason: &r.DoneReason, - }, - }, + Choices: []ChunkChoice{{ + Index: 0, + Delta: Message{Role: "assistant", Content: r.Message.Content}, + FinishReason: func(reason string) *string { + if len(reason) > 0 { + return &reason + } + return nil + }(r.DoneReason), + }}, } } From 0fec3525ad11402ad2a1e6cafaccd4a9d14885a2 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Sat, 11 May 2024 19:13:16 -0700 Subject: [PATCH 5/6] use post token --- app/lifecycle/updater.go | 4 ++-- server/auth.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/lifecycle/updater.go b/app/lifecycle/updater.go index 243bbf22..759ec7e6 100644 --- a/app/lifecycle/updater.go +++ b/app/lifecycle/updater.go @@ -56,13 +56,13 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) { query.Add("nonce", nonce) requestURL.RawQuery = query.Encode() - data := []byte(fmt.Sprintf("%s,%s", http.MethodGet, requestURL.RequestURI())) + data := []byte(fmt.Sprintf("%s,%s", http.MethodPost, requestURL.RequestURI())) signature, err := auth.Sign(ctx, data) if err != nil { return false, updateResp } - req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestURL.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL.String(), nil) if err != nil { slog.Warn(fmt.Sprintf("failed to check for update: %s", err)) return false, updateResp diff --git a/server/auth.go b/server/auth.go index e92a5b65..b8496447 100644 --- a/server/auth.go +++ b/server/auth.go @@ -57,7 +57,7 @@ func getAuthorizationToken(ctx context.Context, challenge registryChallenge) (st } sha256sum := sha256.Sum256(nil) - data := []byte(fmt.Sprintf("%s,%s,%s", http.MethodGet, redirectURL.String(), base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(sha256sum[:]))))) + data := []byte(fmt.Sprintf("%s,%s,%s", http.MethodPost, redirectURL.String(), base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(sha256sum[:]))))) headers := make(http.Header) signature, err := auth.Sign(ctx, data) @@ -67,7 +67,7 @@ func getAuthorizationToken(ctx context.Context, challenge registryChallenge) (st headers.Add("Authorization", signature) - response, err := makeRequest(ctx, http.MethodGet, redirectURL, headers, nil, nil) + response, err := makeRequest(ctx, http.MethodPost, redirectURL, headers, nil, nil) if err != nil { return "", err } From 4ec7445a6f678b6efc773bb9fa886d7c9b075577 Mon Sep 17 00:00:00 2001 From: jmorganca Date: Sat, 11 May 2024 22:19:14 -0700 Subject: [PATCH 6/6] Revert "use post token" This reverts commit 0fec3525ad11402ad2a1e6cafaccd4a9d14885a2. --- app/lifecycle/updater.go | 4 ++-- server/auth.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/lifecycle/updater.go b/app/lifecycle/updater.go index 759ec7e6..243bbf22 100644 --- a/app/lifecycle/updater.go +++ b/app/lifecycle/updater.go @@ -56,13 +56,13 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) { query.Add("nonce", nonce) requestURL.RawQuery = query.Encode() - data := []byte(fmt.Sprintf("%s,%s", http.MethodPost, requestURL.RequestURI())) + data := []byte(fmt.Sprintf("%s,%s", http.MethodGet, requestURL.RequestURI())) signature, err := auth.Sign(ctx, data) if err != nil { return false, updateResp } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, requestURL.String(), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestURL.String(), nil) if err != nil { slog.Warn(fmt.Sprintf("failed to check for update: %s", err)) return false, updateResp diff --git a/server/auth.go b/server/auth.go index b8496447..e92a5b65 100644 --- a/server/auth.go +++ b/server/auth.go @@ -57,7 +57,7 @@ func getAuthorizationToken(ctx context.Context, challenge registryChallenge) (st } sha256sum := sha256.Sum256(nil) - data := []byte(fmt.Sprintf("%s,%s,%s", http.MethodPost, redirectURL.String(), base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(sha256sum[:]))))) + data := []byte(fmt.Sprintf("%s,%s,%s", http.MethodGet, redirectURL.String(), base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(sha256sum[:]))))) headers := make(http.Header) signature, err := auth.Sign(ctx, data) @@ -67,7 +67,7 @@ func getAuthorizationToken(ctx context.Context, challenge registryChallenge) (st headers.Add("Authorization", signature) - response, err := makeRequest(ctx, http.MethodPost, redirectURL, headers, nil, nil) + response, err := makeRequest(ctx, http.MethodGet, redirectURL, headers, nil, nil) if err != nil { return "", err }