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
b732beba
"megatron/vscode:/vscode.git/clone" did not exist on "513d7d8ee331271029bd5e994fd3d7cd56bad13c"
Commit
b732beba
authored
Aug 01, 2024
by
Michael Yang
Browse files
lint
parent
558a54b0
Changes
68
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
44 additions
and
31 deletions
+44
-31
.gitattributes
.gitattributes
+1
-0
.github/workflows/test.yaml
.github/workflows/test.yaml
+1
-1
.golangci.yaml
.golangci.yaml
+14
-4
api/client.go
api/client.go
+2
-1
api/types_test.go
api/types_test.go
+2
-2
app/lifecycle/getstarted_nonwindows.go
app/lifecycle/getstarted_nonwindows.go
+2
-2
app/lifecycle/getstarted_windows.go
app/lifecycle/getstarted_windows.go
+0
-1
app/lifecycle/logging.go
app/lifecycle/logging.go
+1
-1
app/lifecycle/logging_nonwindows.go
app/lifecycle/logging_nonwindows.go
+1
-1
app/lifecycle/logging_test.go
app/lifecycle/logging_test.go
+2
-2
app/lifecycle/server.go
app/lifecycle/server.go
+1
-1
app/lifecycle/updater.go
app/lifecycle/updater.go
+2
-1
app/lifecycle/updater_nonwindows.go
app/lifecycle/updater_nonwindows.go
+2
-2
app/lifecycle/updater_windows.go
app/lifecycle/updater_windows.go
+3
-2
app/tray/tray_nonwindows.go
app/tray/tray_nonwindows.go
+2
-2
app/tray/wintray/eventloop.go
app/tray/wintray/eventloop.go
+1
-3
app/tray/wintray/tray.go
app/tray/wintray/tray.go
+3
-2
auth/auth.go
auth/auth.go
+2
-1
cmd/cmd.go
cmd/cmd.go
+1
-1
cmd/interactive.go
cmd/interactive.go
+1
-1
No files found.
.gitattributes
View file @
b732beba
llm/ext_server/* linguist-vendored
* text eol=lf
.github/workflows/test.yaml
View file @
b732beba
...
...
@@ -273,7 +273,7 @@ jobs:
if
:
${{ startsWith(matrix.os, 'macos-') }}
-
uses
:
golangci/golangci-lint-action@v6
with
:
args
:
--timeout 8m0s -v
${{ startsWith(matrix.os, 'windows-') && '' || '--disable gofmt --disable goimports' }}
args
:
--timeout 8m0s -v
test
:
strategy
:
matrix
:
...
...
.golangci.yaml
View file @
b732beba
...
...
@@ -7,22 +7,32 @@ linters:
-
bodyclose
-
containedctx
-
contextcheck
-
errcheck
-
exportloopref
-
gci
-
gocheckcompilerdirectives
# conditionally enable this on linux/macos
# - gofmt
# - goimports
-
gofmt
-
gofumpt
-
gosimple
-
govet
-
ineffassign
-
intrange
-
makezero
-
misspell
-
nilerr
-
nolintlint
-
nosprintfhostport
-
staticcheck
-
tenv
-
testifylint
-
unconvert
-
unused
-
usestdlibvars
-
wastedassign
-
whitespace
-
usestdlibvars
linters-settings
:
gci
:
sections
:
[
standard
,
default
,
localmodule
]
severity
:
default-severity
:
error
rules
:
...
...
api/client.go
View file @
b732beba
...
...
@@ -18,6 +18,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
...
...
@@ -172,7 +173,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
}
if
errorResponse
.
Error
!=
""
{
return
fmt
.
Errorf
(
errorResponse
.
Error
)
return
errors
.
New
(
errorResponse
.
Error
)
}
if
response
.
StatusCode
>=
http
.
StatusBadRequest
{
...
...
api/types_test.go
View file @
b732beba
...
...
@@ -2,7 +2,7 @@ package api
import
(
"encoding/json"
"
fmt
"
"
errors
"
"math"
"testing"
"time"
...
...
@@ -192,7 +192,7 @@ func TestUseMmapFormatParams(t *testing.T) {
"use_mmap"
:
{
"foo"
},
},
exp
:
nil
,
err
:
fmt
.
Errorf
(
"invalid bool value [foo]"
),
err
:
errors
.
New
(
"invalid bool value [foo]"
),
},
}
...
...
app/lifecycle/getstarted_nonwindows.go
View file @
b732beba
...
...
@@ -2,8 +2,8 @@
package
lifecycle
import
"
fmt
"
import
"
errors
"
func
GetStarted
()
error
{
return
fmt
.
Errorf
(
"GetStarted
not implemented"
)
return
errors
.
New
(
"
not implemented"
)
}
app/lifecycle/getstarted_windows.go
View file @
b732beba
...
...
@@ -34,7 +34,6 @@ func GetStarted() error {
Sys
:
&
syscall
.
SysProcAttr
{
CreationFlags
:
CREATE_NEW_CONSOLE
,
HideWindow
:
false
},
}
proc
,
err
:=
os
.
StartProcess
(
args
[
0
],
args
,
attrs
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to start getting started shell %w"
,
err
)
}
...
...
app/lifecycle/logging.go
View file @
b732beba
...
...
@@ -27,7 +27,7 @@ func InitLogging() {
// TODO - write one-line to the app.log file saying we're running in console mode to help avoid confusion
}
else
{
rotateLogs
(
AppLogFile
)
logFile
,
err
=
os
.
OpenFile
(
AppLogFile
,
os
.
O_APPEND
|
os
.
O_WRONLY
|
os
.
O_CREATE
,
0755
)
logFile
,
err
=
os
.
OpenFile
(
AppLogFile
,
os
.
O_APPEND
|
os
.
O_WRONLY
|
os
.
O_CREATE
,
0
o
755
)
if
err
!=
nil
{
slog
.
Error
(
fmt
.
Sprintf
(
"failed to create server log %v"
,
err
))
return
...
...
app/lifecycle/logging_nonwindows.go
View file @
b732beba
...
...
@@ -5,5 +5,5 @@ package lifecycle
import
"log/slog"
func
ShowLogs
()
{
slog
.
Warn
(
"
ShowLogs not ye
t implemented"
)
slog
.
Warn
(
"
no
t implemented"
)
}
app/lifecycle/logging_test.go
View file @
b732beba
...
...
@@ -17,7 +17,7 @@ func TestRotateLogs(t *testing.T) {
// No log exists
rotateLogs
(
logFile
)
require
.
NoError
(
t
,
os
.
WriteFile
(
logFile
,
[]
byte
(
"1"
),
0644
))
require
.
NoError
(
t
,
os
.
WriteFile
(
logFile
,
[]
byte
(
"1"
),
0
o
644
))
assert
.
FileExists
(
t
,
logFile
)
// First rotation
rotateLogs
(
logFile
)
...
...
@@ -32,7 +32,7 @@ func TestRotateLogs(t *testing.T) {
assert
.
NoFileExists
(
t
,
logFile
)
for
i
:=
2
;
i
<=
LogRotationCount
+
1
;
i
++
{
require
.
NoError
(
t
,
os
.
WriteFile
(
logFile
,
[]
byte
(
strconv
.
Itoa
(
i
)),
0644
))
require
.
NoError
(
t
,
os
.
WriteFile
(
logFile
,
[]
byte
(
strconv
.
Itoa
(
i
)),
0
o
644
))
assert
.
FileExists
(
t
,
logFile
)
rotateLogs
(
logFile
)
assert
.
NoFileExists
(
t
,
logFile
)
...
...
app/lifecycle/server.go
View file @
b732beba
...
...
@@ -55,7 +55,7 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) {
}
rotateLogs
(
ServerLogFile
)
logFile
,
err
:=
os
.
OpenFile
(
ServerLogFile
,
os
.
O_APPEND
|
os
.
O_WRONLY
|
os
.
O_CREATE
,
0755
)
logFile
,
err
:=
os
.
OpenFile
(
ServerLogFile
,
os
.
O_APPEND
|
os
.
O_WRONLY
|
os
.
O_CREATE
,
0
o
755
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to create server log: %w"
,
err
)
}
...
...
app/lifecycle/updater.go
View file @
b732beba
...
...
@@ -15,6 +15,7 @@ import (
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"time"
...
...
@@ -46,7 +47,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
query
.
Add
(
"os"
,
runtime
.
GOOS
)
query
.
Add
(
"arch"
,
runtime
.
GOARCH
)
query
.
Add
(
"version"
,
version
.
Version
)
query
.
Add
(
"ts"
,
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
Unix
()))
query
.
Add
(
"ts"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
,
10
))
nonce
,
err
:=
auth
.
NewNonce
(
rand
.
Reader
,
16
)
if
err
!=
nil
{
...
...
app/lifecycle/updater_nonwindows.go
View file @
b732beba
...
...
@@ -4,9 +4,9 @@ package lifecycle
import
(
"context"
"
fmt
"
"
errors
"
)
func
DoUpgrade
(
cancel
context
.
CancelFunc
,
done
chan
int
)
error
{
return
fmt
.
Errorf
(
"DoUpgrade not ye
t implemented"
)
return
errors
.
New
(
"no
t implemented"
)
}
app/lifecycle/updater_windows.go
View file @
b732beba
...
...
@@ -2,6 +2,7 @@ package lifecycle
import
(
"context"
"errors"
"fmt"
"log/slog"
"os"
...
...
@@ -15,7 +16,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
return
fmt
.
Errorf
(
"failed to lookup downloads: %s"
,
err
)
}
if
len
(
files
)
==
0
{
return
fmt
.
Errorf
(
"no update downloads found"
)
return
errors
.
New
(
"no update downloads found"
)
}
else
if
len
(
files
)
>
1
{
// Shouldn't happen
slog
.
Warn
(
fmt
.
Sprintf
(
"multiple downloads found, using first one %v"
,
files
))
...
...
@@ -64,7 +65,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
}
}
else
{
// TODO - some details about why it didn't start, or is this a pedantic error case?
return
fmt
.
Errorf
(
"installer process did not start"
)
return
errors
.
New
(
"installer process did not start"
)
}
// TODO should we linger for a moment and check to make sure it's actually running by checking the pid?
...
...
app/tray/tray_nonwindows.go
View file @
b732beba
...
...
@@ -3,11 +3,11 @@
package
tray
import
(
"
fmt
"
"
errors
"
"github.com/ollama/ollama/app/tray/commontray"
)
func
InitPlatformTray
(
icon
,
updateIcon
[]
byte
)
(
commontray
.
OllamaTray
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"NOT IMPLEMENTED YET
"
)
return
nil
,
errors
.
New
(
"not implemented
"
)
}
app/tray/wintray/eventloop.go
View file @
b732beba
...
...
@@ -11,9 +11,7 @@ import (
"golang.org/x/sys/windows"
)
var
(
quitOnce
sync
.
Once
)
var
quitOnce
sync
.
Once
func
(
t
*
winTray
)
Run
()
{
nativeLoop
()
...
...
app/tray/wintray/tray.go
View file @
b732beba
...
...
@@ -13,8 +13,9 @@ import (
"sync"
"unsafe"
"github.com/ollama/ollama/app/tray/commontray"
"golang.org/x/sys/windows"
"github.com/ollama/ollama/app/tray/commontray"
)
// Helpful sources: https://github.com/golang/exp/blob/master/shiny/driver/internal/win32
...
...
@@ -414,7 +415,7 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) {
iconFilePath
:=
filepath
.
Join
(
os
.
TempDir
(),
"ollama_temp_icon_"
+
dataHash
)
if
_
,
err
:=
os
.
Stat
(
iconFilePath
);
os
.
IsNotExist
(
err
)
{
if
err
:=
os
.
WriteFile
(
iconFilePath
,
iconBytes
,
0644
);
err
!=
nil
{
if
err
:=
os
.
WriteFile
(
iconFilePath
,
iconBytes
,
0
o
644
);
err
!=
nil
{
return
""
,
err
}
}
...
...
auth/auth.go
View file @
b732beba
...
...
@@ -5,6 +5,7 @@ import (
"context"
"crypto/rand"
"encoding/base64"
"errors"
"fmt"
"io"
"log/slog"
...
...
@@ -78,7 +79,7 @@ func Sign(ctx context.Context, bts []byte) (string, error) {
publicKey
:=
ssh
.
MarshalAuthorizedKey
(
privateKey
.
PublicKey
())
parts
:=
bytes
.
Split
(
publicKey
,
[]
byte
(
" "
))
if
len
(
parts
)
<
2
{
return
""
,
fmt
.
Errorf
(
"malformed public key"
)
return
""
,
errors
.
New
(
"malformed public key"
)
}
signedData
,
err
:=
privateKey
.
Sign
(
rand
.
Reader
,
bts
)
...
...
cmd/cmd.go
View file @
b732beba
...
...
@@ -1160,7 +1160,7 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error {
return
err
}
if
err
:=
startApp
(
cmd
.
Context
(),
client
);
err
!=
nil
{
return
fmt
.
Errorf
(
"could not connect to ollama app, is it running?"
)
return
errors
.
New
(
"could not connect to ollama app, is it running?"
)
}
}
return
nil
...
...
cmd/interactive.go
View file @
b732beba
...
...
@@ -604,7 +604,7 @@ func getImageData(filePath string) ([]byte, error) {
// Check if the file size exceeds 100MB
var
maxSize
int64
=
100
*
1024
*
1024
// 100MB in bytes
if
info
.
Size
()
>
maxSize
{
return
nil
,
fmt
.
Errorf
(
"file size exceeds maximum limit (100MB)"
)
return
nil
,
errors
.
New
(
"file size exceeds maximum limit (100MB)"
)
}
buf
=
make
([]
byte
,
info
.
Size
())
...
...
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