"docs/vscode:/vscode.git/clone" did not exist on "cd817a1a006e452cb7e6d741c4f42342639f21a7"
Unverified Commit 77ccbf04 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #6128 from ollama/mxyng/lint

enable gofmt/gofumpt/goimports/tenv
parents 4addf6b5 b732beba
...@@ -333,7 +333,6 @@ func Test_Routes(t *testing.T) { ...@@ -333,7 +333,6 @@ func Test_Routes(t *testing.T) {
t.Fatalf("expected content type application/json; charset=utf-8, got %s", contentType) t.Fatalf("expected content type application/json; charset=utf-8, got %s", contentType)
} }
_, err := io.ReadAll(resp.Body) _, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
......
...@@ -58,7 +58,7 @@ var defaultModelsPerGPU = 3 ...@@ -58,7 +58,7 @@ var defaultModelsPerGPU = 3
// we'll back off down to 1 to try to get it to fit // we'll back off down to 1 to try to get it to fit
var defaultParallel = 4 var defaultParallel = 4
var ErrMaxQueue = fmt.Errorf("server busy, please try again. maximum pending requests exceeded") var ErrMaxQueue = errors.New("server busy, please try again. maximum pending requests exceeded")
func InitScheduler(ctx context.Context) *Scheduler { func InitScheduler(ctx context.Context) *Scheduler {
maxQueue := envconfig.MaxQueue() maxQueue := envconfig.MaxQueue()
......
...@@ -3,23 +3,25 @@ package server ...@@ -3,23 +3,25 @@ package server
import ( import (
"bytes" "bytes"
"context" "context"
"fmt" "errors"
"log/slog" "log/slog"
"os" "os"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
"github.com/ollama/ollama/app/lifecycle" "github.com/ollama/ollama/app/lifecycle"
"github.com/ollama/ollama/format" "github.com/ollama/ollama/format"
"github.com/ollama/ollama/gpu" "github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/llm" "github.com/ollama/ollama/llm"
"github.com/stretchr/testify/require"
) )
func init() { func TestMain(m *testing.M) {
os.Setenv("OLLAMA_DEBUG", "1") os.Setenv("OLLAMA_DEBUG", "1")
lifecycle.InitLogging() lifecycle.InitLogging()
os.Exit(m.Run())
} }
func TestInitScheduler(t *testing.T) { func TestInitScheduler(t *testing.T) {
...@@ -46,7 +48,7 @@ func TestLoad(t *testing.T) { ...@@ -46,7 +48,7 @@ func TestLoad(t *testing.T) {
} }
// Fail to load model first // Fail to load model first
s.newServerFn = func(gpus gpu.GpuInfoList, model string, ggml *llm.GGML, adapters []string, projectors []string, opts api.Options, numParallel int) (llm.LlamaServer, error) { s.newServerFn = func(gpus gpu.GpuInfoList, model string, ggml *llm.GGML, adapters []string, projectors []string, opts api.Options, numParallel int) (llm.LlamaServer, error) {
return nil, fmt.Errorf("something failed to load model blah") return nil, errors.New("something failed to load model blah")
} }
gpus := gpu.GpuInfoList{} gpus := gpu.GpuInfoList{}
s.load(req, ggml, gpus, 0) s.load(req, ggml, gpus, 0)
...@@ -75,7 +77,7 @@ func TestLoad(t *testing.T) { ...@@ -75,7 +77,7 @@ func TestLoad(t *testing.T) {
} }
req.model.ModelPath = "dummy_model_path" req.model.ModelPath = "dummy_model_path"
server.waitResp = fmt.Errorf("wait failure") server.waitResp = errors.New("wait failure")
s.load(req, ggml, gpus, 0) s.load(req, ggml, gpus, 0)
select { select {
case err := <-req.errCh: case err := <-req.errCh:
...@@ -600,7 +602,7 @@ func TestNeedsReload(t *testing.T) { ...@@ -600,7 +602,7 @@ func TestNeedsReload(t *testing.T) {
resp = runner.needsReload(ctx, req) resp = runner.needsReload(ctx, req)
require.True(t, resp) require.True(t, resp)
req.opts.NumBatch = runner.Options.NumBatch req.opts.NumBatch = runner.Options.NumBatch
llm.pingResp = fmt.Errorf("foo") llm.pingResp = errors.New("foo")
resp = runner.needsReload(ctx, req) resp = runner.needsReload(ctx, req)
require.True(t, resp) require.True(t, resp)
llm.pingResp = nil llm.pingResp = nil
...@@ -724,15 +726,19 @@ func (s *mockLlm) WaitUntilRunning(ctx context.Context) error { return s.waitRes ...@@ -724,15 +726,19 @@ func (s *mockLlm) WaitUntilRunning(ctx context.Context) error { return s.waitRes
func (s *mockLlm) Completion(ctx context.Context, req llm.CompletionRequest, fn func(llm.CompletionResponse)) error { func (s *mockLlm) Completion(ctx context.Context, req llm.CompletionRequest, fn func(llm.CompletionResponse)) error {
return s.completionResp return s.completionResp
} }
func (s *mockLlm) Embed(ctx context.Context, input []string) (*llm.EmbedResponse, error) { func (s *mockLlm) Embed(ctx context.Context, input []string) (*llm.EmbedResponse, error) {
return s.embedResp, s.embedRespErr return s.embedResp, s.embedRespErr
} }
func (s *mockLlm) Tokenize(ctx context.Context, content string) ([]int, error) { func (s *mockLlm) Tokenize(ctx context.Context, content string) ([]int, error) {
return s.tokenizeResp, s.tokenizeRespErr return s.tokenizeResp, s.tokenizeRespErr
} }
func (s *mockLlm) Detokenize(ctx context.Context, tokens []int) (string, error) { func (s *mockLlm) Detokenize(ctx context.Context, tokens []int) (string, error) {
return s.detokenizeResp, s.detonekizeRespErr return s.detokenizeResp, s.detonekizeRespErr
} }
func (s *mockLlm) Close() error { func (s *mockLlm) Close() error {
s.closeCalled = true s.closeCalled = true
return s.closeResp return s.closeResp
......
...@@ -12,13 +12,15 @@ import ( ...@@ -12,13 +12,15 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"strconv"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
"golang.org/x/sync/errgroup"
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
"github.com/ollama/ollama/format" "github.com/ollama/ollama/format"
"golang.org/x/sync/errgroup"
) )
var blobUploadManager sync.Map var blobUploadManager sync.Map
...@@ -212,7 +214,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) { ...@@ -212,7 +214,7 @@ func (b *blobUpload) Run(ctx context.Context, opts *registryOptions) {
func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *url.URL, part *blobUploadPart, opts *registryOptions) error { func (b *blobUpload) uploadPart(ctx context.Context, method string, requestURL *url.URL, part *blobUploadPart, opts *registryOptions) error {
headers := make(http.Header) headers := make(http.Header)
headers.Set("Content-Type", "application/octet-stream") headers.Set("Content-Type", "application/octet-stream")
headers.Set("Content-Length", fmt.Sprintf("%d", part.Size)) headers.Set("Content-Length", strconv.FormatInt(part.Size, 10))
if method == http.MethodPatch { if method == http.MethodPatch {
headers.Set("X-Redirect-Uploads", "1") headers.Set("X-Redirect-Uploads", "1")
......
...@@ -15,8 +15,9 @@ import ( ...@@ -15,8 +15,9 @@ import (
"text/template/parse" "text/template/parse"
"github.com/agnivade/levenshtein" "github.com/agnivade/levenshtein"
"github.com/ollama/ollama/api"
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"github.com/ollama/ollama/api"
) )
//go:embed index.json //go:embed index.json
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/api" "github.com/ollama/ollama/api"
"github.com/ollama/ollama/llm" "github.com/ollama/ollama/llm"
) )
......
...@@ -6,8 +6,10 @@ import ( ...@@ -6,8 +6,10 @@ import (
"strings" "strings"
) )
const UnknownOllamaKeyErrMsg = "unknown ollama key" const (
const InvalidModelNameErrMsg = "invalid model name" UnknownOllamaKeyErrMsg = "unknown ollama key"
InvalidModelNameErrMsg = "invalid model name"
)
// TODO: This should have a structured response from the API // TODO: This should have a structured response from the API
type UnknownOllamaKey struct { type UnknownOllamaKey struct {
......
...@@ -258,7 +258,7 @@ func (n Name) IsValid() bool { ...@@ -258,7 +258,7 @@ func (n Name) IsValid() bool {
// IsFullyQualified returns true if all parts of the name are present and // IsFullyQualified returns true if all parts of the name are present and
// valid without the digest. // valid without the digest.
func (n Name) IsFullyQualified() bool { func (n Name) IsFullyQualified() bool {
var parts = []string{ parts := []string{
n.Host, n.Host,
n.Namespace, n.Namespace,
n.Model, n.Model,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment