Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
77ccbf04
Unverified
Commit
77ccbf04
authored
Aug 02, 2024
by
Michael Yang
Committed by
GitHub
Aug 02, 2024
Browse files
Merge pull request #6128 from ollama/mxyng/lint
enable gofmt/gofumpt/goimports/tenv
parents
4addf6b5
b732beba
Changes
68
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
14 deletions
+25
-14
server/routes_test.go
server/routes_test.go
+0
-1
server/sched.go
server/sched.go
+1
-1
server/sched_test.go
server/sched_test.go
+12
-6
server/upload.go
server/upload.go
+4
-2
template/template.go
template/template.go
+2
-1
template/template_test.go
template/template_test.go
+1
-0
types/errtypes/errtypes.go
types/errtypes/errtypes.go
+4
-2
types/model/name.go
types/model/name.go
+1
-1
No files found.
server/routes_test.go
View file @
77ccbf04
...
...
@@ -333,7 +333,6 @@ func Test_Routes(t *testing.T) {
t
.
Fatalf
(
"expected content type application/json; charset=utf-8, got %s"
,
contentType
)
}
_
,
err
:=
io
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
server/sched.go
View file @
77ccbf04
...
...
@@ -58,7 +58,7 @@ var defaultModelsPerGPU = 3
// we'll back off down to 1 to try to get it to fit
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
{
maxQueue
:=
envconfig
.
MaxQueue
()
...
...
server/sched_test.go
View file @
77ccbf04
...
...
@@ -3,23 +3,25 @@ package server
import
(
"bytes"
"context"
"
fmt
"
"
errors
"
"log/slog"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/app/lifecycle"
"github.com/ollama/ollama/format"
"github.com/ollama/ollama/gpu"
"github.com/ollama/ollama/llm"
"github.com/stretchr/testify/require"
)
func
init
(
)
{
func
TestMain
(
m
*
testing
.
M
)
{
os
.
Setenv
(
"OLLAMA_DEBUG"
,
"1"
)
lifecycle
.
InitLogging
()
os
.
Exit
(
m
.
Run
())
}
func
TestInitScheduler
(
t
*
testing
.
T
)
{
...
...
@@ -46,7 +48,7 @@ func TestLoad(t *testing.T) {
}
// 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
)
{
return
nil
,
fmt
.
Errorf
(
"something failed to load model blah"
)
return
nil
,
errors
.
New
(
"something failed to load model blah"
)
}
gpus
:=
gpu
.
GpuInfoList
{}
s
.
load
(
req
,
ggml
,
gpus
,
0
)
...
...
@@ -75,7 +77,7 @@ func TestLoad(t *testing.T) {
}
req
.
model
.
ModelPath
=
"dummy_model_path"
server
.
waitResp
=
fmt
.
Errorf
(
"wait failure"
)
server
.
waitResp
=
errors
.
New
(
"wait failure"
)
s
.
load
(
req
,
ggml
,
gpus
,
0
)
select
{
case
err
:=
<-
req
.
errCh
:
...
...
@@ -600,7 +602,7 @@ func TestNeedsReload(t *testing.T) {
resp
=
runner
.
needsReload
(
ctx
,
req
)
require
.
True
(
t
,
resp
)
req
.
opts
.
NumBatch
=
runner
.
Options
.
NumBatch
llm
.
pingResp
=
fmt
.
Errorf
(
"foo"
)
llm
.
pingResp
=
errors
.
New
(
"foo"
)
resp
=
runner
.
needsReload
(
ctx
,
req
)
require
.
True
(
t
,
resp
)
llm
.
pingResp
=
nil
...
...
@@ -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
{
return
s
.
completionResp
}
func
(
s
*
mockLlm
)
Embed
(
ctx
context
.
Context
,
input
[]
string
)
(
*
llm
.
EmbedResponse
,
error
)
{
return
s
.
embedResp
,
s
.
embedRespErr
}
func
(
s
*
mockLlm
)
Tokenize
(
ctx
context
.
Context
,
content
string
)
([]
int
,
error
)
{
return
s
.
tokenizeResp
,
s
.
tokenizeRespErr
}
func
(
s
*
mockLlm
)
Detokenize
(
ctx
context
.
Context
,
tokens
[]
int
)
(
string
,
error
)
{
return
s
.
detokenizeResp
,
s
.
detonekizeRespErr
}
func
(
s
*
mockLlm
)
Close
()
error
{
s
.
closeCalled
=
true
return
s
.
closeResp
...
...
server/upload.go
View file @
77ccbf04
...
...
@@ -12,13 +12,15 @@ import (
"net/http"
"net/url"
"os"
"strconv"
"sync"
"sync/atomic"
"time"
"golang.org/x/sync/errgroup"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/format"
"golang.org/x/sync/errgroup"
)
var
blobUploadManager
sync
.
Map
...
...
@@ -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
{
headers
:=
make
(
http
.
Header
)
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
{
headers
.
Set
(
"X-Redirect-Uploads"
,
"1"
)
...
...
template/template.go
View file @
77ccbf04
...
...
@@ -15,8 +15,9 @@ import (
"text/template/parse"
"github.com/agnivade/levenshtein"
"github.com/ollama/ollama/api"
"golang.org/x/exp/maps"
"github.com/ollama/ollama/api"
)
//go:embed index.json
...
...
template/template_test.go
View file @
77ccbf04
...
...
@@ -12,6 +12,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/llm"
)
...
...
types/errtypes/errtypes.go
View file @
77ccbf04
...
...
@@ -6,8 +6,10 @@ import (
"strings"
)
const
UnknownOllamaKeyErrMsg
=
"unknown ollama key"
const
InvalidModelNameErrMsg
=
"invalid model name"
const
(
UnknownOllamaKeyErrMsg
=
"unknown ollama key"
InvalidModelNameErrMsg
=
"invalid model name"
)
// TODO: This should have a structured response from the API
type
UnknownOllamaKey
struct
{
...
...
types/model/name.go
View file @
77ccbf04
...
...
@@ -258,7 +258,7 @@ func (n Name) IsValid() bool {
// IsFullyQualified returns true if all parts of the name are present and
// valid without the digest.
func
(
n
Name
)
IsFullyQualified
()
bool
{
var
parts
=
[]
string
{
parts
:
=
[]
string
{
n
.
Host
,
n
.
Namespace
,
n
.
Model
,
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment