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
89d99001
Unverified
Commit
89d99001
authored
Jun 04, 2024
by
Michael Yang
Committed by
GitHub
Jun 04, 2024
Browse files
Merge pull request #4570 from ollama/mxyng/slices
lint some of the things
parents
4a048715
6297f856
Changes
54
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
80 additions
and
63 deletions
+80
-63
.github/workflows/test.yaml
.github/workflows/test.yaml
+2
-2
.golangci.yaml
.golangci.yaml
+18
-1
api/types.go
api/types.go
+1
-1
api/types_test.go
api/types_test.go
+4
-4
app/lifecycle/paths.go
app/lifecycle/paths.go
+0
-1
app/lifecycle/server.go
app/lifecycle/server.go
+1
-2
app/lifecycle/server_windows.go
app/lifecycle/server_windows.go
+4
-2
app/lifecycle/updater.go
app/lifecycle/updater.go
+3
-3
app/store/store.go
app/store/store.go
+0
-1
app/tray/wintray/eventloop.go
app/tray/wintray/eventloop.go
+2
-3
app/tray/wintray/tray.go
app/tray/wintray/tray.go
+3
-7
cmd/cmd.go
cmd/cmd.go
+1
-20
cmd/interactive.go
cmd/interactive.go
+1
-1
cmd/interactive_test.go
cmd/interactive_test.go
+5
-4
cmd/start.go
cmd/start.go
+27
-0
convert/convert.go
convert/convert.go
+1
-1
convert/gemma.go
convert/gemma.go
+0
-1
convert/llama.go
convert/llama.go
+4
-3
convert/safetensors.go
convert/safetensors.go
+1
-1
convert/tokenizer.go
convert/tokenizer.go
+2
-5
No files found.
.github/workflows/test.yaml
View file @
89d99001
...
@@ -269,9 +269,9 @@ jobs:
...
@@ -269,9 +269,9 @@ jobs:
mkdir -p llm/build/darwin/$ARCH/stub/bin
mkdir -p llm/build/darwin/$ARCH/stub/bin
touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
touch llm/build/darwin/$ARCH/stub/bin/ollama_llama_server
if
:
${{ startsWith(matrix.os, 'macos-') }}
if
:
${{ startsWith(matrix.os, 'macos-') }}
-
uses
:
golangci/golangci-lint-action@v
4
-
uses
:
golangci/golangci-lint-action@v
6
with
:
with
:
args
:
--timeout 8m0s -v
args
:
--timeout 8m0s -v
${{ startsWith(matrix.os, 'windows-') && '' || '--disable gofmt --disable goimports' }}
test
:
test
:
strategy
:
strategy
:
matrix
:
matrix
:
...
...
.golangci.yaml
View file @
89d99001
...
@@ -9,9 +9,26 @@ linters:
...
@@ -9,9 +9,26 @@ linters:
-
contextcheck
-
contextcheck
-
exportloopref
-
exportloopref
-
gocheckcompilerdirectives
-
gocheckcompilerdirectives
#
FIXME: for some reason this error
s on
w
in
dow
s
#
conditionally enable thi
s on
l
in
ux/maco
s
# - gofmt
# - gofmt
# - goimports
# - goimports
-
intrange
-
misspell
-
misspell
-
nilerr
-
nilerr
-
nolintlint
-
nosprintfhostport
-
testifylint
-
unconvert
-
unused
-
unused
-
wastedassign
-
whitespace
-
usestdlibvars
severity
:
default-severity
:
error
rules
:
-
linters
:
-
gofmt
-
goimports
-
intrange
-
usestdlibvars
severity
:
info
api/types.go
View file @
89d99001
...
@@ -306,7 +306,7 @@ type GenerateResponse struct {
...
@@ -306,7 +306,7 @@ type GenerateResponse struct {
// Model is the model name that generated the response.
// Model is the model name that generated the response.
Model
string
`json:"model"`
Model
string
`json:"model"`
//CreatedAt is the timestamp of the response.
//
CreatedAt is the timestamp of the response.
CreatedAt
time
.
Time
`json:"created_at"`
CreatedAt
time
.
Time
`json:"created_at"`
// Response is the textual response itself.
// Response is the textual response itself.
...
...
api/types_test.go
View file @
89d99001
...
@@ -72,13 +72,13 @@ func TestDurationMarshalUnmarshal(t *testing.T) {
...
@@ -72,13 +72,13 @@ func TestDurationMarshalUnmarshal(t *testing.T) {
},
},
{
{
"positive duration"
,
"positive duration"
,
time
.
Duration
(
42
*
time
.
Second
)
,
42
*
time
.
Second
,
time
.
Duration
(
42
*
time
.
Second
)
,
42
*
time
.
Second
,
},
},
{
{
"another positive duration"
,
"another positive duration"
,
time
.
Duration
(
42
*
time
.
Minute
)
,
42
*
time
.
Minute
,
time
.
Duration
(
42
*
time
.
Minute
)
,
42
*
time
.
Minute
,
},
},
{
{
"zero duration"
,
"zero duration"
,
...
...
app/lifecycle/paths.go
View file @
89d99001
...
@@ -69,7 +69,6 @@ func init() {
...
@@ -69,7 +69,6 @@ func init() {
slog
.
Error
(
fmt
.
Sprintf
(
"create ollama dir %s: %v"
,
AppDataDir
,
err
))
slog
.
Error
(
fmt
.
Sprintf
(
"create ollama dir %s: %v"
,
AppDataDir
,
err
))
}
}
}
}
}
else
if
runtime
.
GOOS
==
"darwin"
{
}
else
if
runtime
.
GOOS
==
"darwin"
{
// TODO
// TODO
AppName
+=
".app"
AppName
+=
".app"
...
...
app/lifecycle/server.go
View file @
89d99001
...
@@ -15,7 +15,7 @@ import (
...
@@ -15,7 +15,7 @@ import (
)
)
func
getCLIFullPath
(
command
string
)
string
{
func
getCLIFullPath
(
command
string
)
string
{
cmdPath
:=
""
var
cmdPath
string
appExe
,
err
:=
os
.
Executable
()
appExe
,
err
:=
os
.
Executable
()
if
err
==
nil
{
if
err
==
nil
{
cmdPath
=
filepath
.
Join
(
filepath
.
Dir
(
appExe
),
command
)
cmdPath
=
filepath
.
Join
(
filepath
.
Dir
(
appExe
),
command
)
...
@@ -65,7 +65,6 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) {
...
@@ -65,7 +65,6 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) {
if
err
!=
nil
{
if
err
!=
nil
{
if
!
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
if
!
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
return
nil
,
fmt
.
Errorf
(
"stat ollama server log dir %s: %v"
,
logDir
,
err
)
return
nil
,
fmt
.
Errorf
(
"stat ollama server log dir %s: %v"
,
logDir
,
err
)
}
}
if
err
:=
os
.
MkdirAll
(
logDir
,
0
o755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
logDir
,
0
o755
);
err
!=
nil
{
...
...
app/lifecycle/server_windows.go
View file @
89d99001
...
@@ -24,7 +24,8 @@ func terminate(cmd *exec.Cmd) error {
...
@@ -24,7 +24,8 @@ func terminate(cmd *exec.Cmd) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
defer
dll
.
Release
()
// nolint: errcheck
//nolint:errcheck
defer
dll
.
Release
()
pid
:=
cmd
.
Process
.
Pid
pid
:=
cmd
.
Process
.
Pid
...
@@ -73,7 +74,8 @@ func isProcessExited(pid int) (bool, error) {
...
@@ -73,7 +74,8 @@ func isProcessExited(pid int) (bool, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"failed to open process: %v"
,
err
)
return
false
,
fmt
.
Errorf
(
"failed to open process: %v"
,
err
)
}
}
defer
windows
.
CloseHandle
(
hProcess
)
// nolint: errcheck
//nolint:errcheck
defer
windows
.
CloseHandle
(
hProcess
)
var
exitCode
uint32
var
exitCode
uint32
err
=
windows
.
GetExitCodeProcess
(
hProcess
,
&
exitCode
)
err
=
windows
.
GetExitCodeProcess
(
hProcess
,
&
exitCode
)
...
...
app/lifecycle/updater.go
View file @
89d99001
...
@@ -78,7 +78,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
...
@@ -78,7 +78,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
}
}
defer
resp
.
Body
.
Close
()
defer
resp
.
Body
.
Close
()
if
resp
.
StatusCode
==
204
{
if
resp
.
StatusCode
==
http
.
StatusNoContent
{
slog
.
Debug
(
"check update response 204 (current version is up to date)"
)
slog
.
Debug
(
"check update response 204 (current version is up to date)"
)
return
false
,
updateResp
return
false
,
updateResp
}
}
...
@@ -87,7 +87,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
...
@@ -87,7 +87,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
slog
.
Warn
(
fmt
.
Sprintf
(
"failed to read body response: %s"
,
err
))
slog
.
Warn
(
fmt
.
Sprintf
(
"failed to read body response: %s"
,
err
))
}
}
if
resp
.
StatusCode
!=
200
{
if
resp
.
StatusCode
!=
http
.
StatusOK
{
slog
.
Info
(
fmt
.
Sprintf
(
"check update error %d - %.96s"
,
resp
.
StatusCode
,
string
(
body
)))
slog
.
Info
(
fmt
.
Sprintf
(
"check update error %d - %.96s"
,
resp
.
StatusCode
,
string
(
body
)))
return
false
,
updateResp
return
false
,
updateResp
}
}
...
@@ -114,7 +114,7 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
...
@@ -114,7 +114,7 @@ func DownloadNewRelease(ctx context.Context, updateResp UpdateResponse) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error checking update: %w"
,
err
)
return
fmt
.
Errorf
(
"error checking update: %w"
,
err
)
}
}
if
resp
.
StatusCode
!=
200
{
if
resp
.
StatusCode
!=
http
.
StatusOK
{
return
fmt
.
Errorf
(
"unexpected status attempting to download update %d"
,
resp
.
StatusCode
)
return
fmt
.
Errorf
(
"unexpected status attempting to download update %d"
,
resp
.
StatusCode
)
}
}
resp
.
Body
.
Close
()
resp
.
Body
.
Close
()
...
...
app/store/store.go
View file @
89d99001
...
@@ -29,7 +29,6 @@ func GetID() string {
...
@@ -29,7 +29,6 @@ func GetID() string {
initStore
()
initStore
()
}
}
return
store
.
ID
return
store
.
ID
}
}
func
GetFirstTimeRun
()
bool
{
func
GetFirstTimeRun
()
bool
{
...
...
app/tray/wintray/eventloop.go
View file @
89d99001
...
@@ -47,7 +47,6 @@ func nativeLoop() {
...
@@ -47,7 +47,6 @@ func nativeLoop() {
default
:
default
:
pTranslateMessage
.
Call
(
uintptr
(
unsafe
.
Pointer
(
m
)))
//nolint:errcheck
pTranslateMessage
.
Call
(
uintptr
(
unsafe
.
Pointer
(
m
)))
//nolint:errcheck
pDispatchMessage
.
Call
(
uintptr
(
unsafe
.
Pointer
(
m
)))
//nolint:errcheck
pDispatchMessage
.
Call
(
uintptr
(
unsafe
.
Pointer
(
m
)))
//nolint:errcheck
}
}
}
}
}
}
...
@@ -160,8 +159,8 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui
...
@@ -160,8 +159,8 @@ func (t *winTray) wndProc(hWnd windows.Handle, message uint32, wParam, lParam ui
lResult
,
_
,
_
=
pDefWindowProc
.
Call
(
lResult
,
_
,
_
=
pDefWindowProc
.
Call
(
uintptr
(
hWnd
),
uintptr
(
hWnd
),
uintptr
(
message
),
uintptr
(
message
),
uintptr
(
wParam
)
,
wParam
,
uintptr
(
lParam
)
,
lParam
,
)
)
}
}
return
return
...
...
app/tray/wintray/tray.go
View file @
89d99001
...
@@ -186,7 +186,7 @@ func (t *winTray) initInstance() error {
...
@@ -186,7 +186,7 @@ func (t *winTray) initInstance() error {
t
.
muNID
.
Lock
()
t
.
muNID
.
Lock
()
defer
t
.
muNID
.
Unlock
()
defer
t
.
muNID
.
Unlock
()
t
.
nid
=
&
notifyIconData
{
t
.
nid
=
&
notifyIconData
{
Wnd
:
windows
.
Handle
(
t
.
window
)
,
Wnd
:
t
.
window
,
ID
:
100
,
ID
:
100
,
Flags
:
NIF_MESSAGE
,
Flags
:
NIF_MESSAGE
,
CallbackMessage
:
t
.
wmSystrayMessage
,
CallbackMessage
:
t
.
wmSystrayMessage
,
...
@@ -197,7 +197,6 @@ func (t *winTray) initInstance() error {
...
@@ -197,7 +197,6 @@ func (t *winTray) initInstance() error {
}
}
func
(
t
*
winTray
)
createMenu
()
error
{
func
(
t
*
winTray
)
createMenu
()
error
{
menuHandle
,
_
,
err
:=
pCreatePopupMenu
.
Call
()
menuHandle
,
_
,
err
:=
pCreatePopupMenu
.
Call
()
if
menuHandle
==
0
{
if
menuHandle
==
0
{
return
err
return
err
...
@@ -246,7 +245,7 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title
...
@@ -246,7 +245,7 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title
mi
:=
menuItemInfo
{
mi
:=
menuItemInfo
{
Mask
:
MIIM_FTYPE
|
MIIM_STRING
|
MIIM_ID
|
MIIM_STATE
,
Mask
:
MIIM_FTYPE
|
MIIM_STRING
|
MIIM_ID
|
MIIM_STATE
,
Type
:
MFT_STRING
,
Type
:
MFT_STRING
,
ID
:
uint32
(
menuItemId
)
,
ID
:
menuItemId
,
TypeData
:
titlePtr
,
TypeData
:
titlePtr
,
Cch
:
uint32
(
len
(
title
)),
Cch
:
uint32
(
len
(
title
)),
}
}
...
@@ -302,11 +301,10 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title
...
@@ -302,11 +301,10 @@ func (t *winTray) addOrUpdateMenuItem(menuItemId uint32, parentId uint32, title
}
}
func
(
t
*
winTray
)
addSeparatorMenuItem
(
menuItemId
,
parentId
uint32
)
error
{
func
(
t
*
winTray
)
addSeparatorMenuItem
(
menuItemId
,
parentId
uint32
)
error
{
mi
:=
menuItemInfo
{
mi
:=
menuItemInfo
{
Mask
:
MIIM_FTYPE
|
MIIM_ID
|
MIIM_STATE
,
Mask
:
MIIM_FTYPE
|
MIIM_ID
|
MIIM_STATE
,
Type
:
MFT_SEPARATOR
,
Type
:
MFT_SEPARATOR
,
ID
:
uint32
(
menuItemId
)
,
ID
:
menuItemId
,
}
}
mi
.
Size
=
uint32
(
unsafe
.
Sizeof
(
mi
))
mi
.
Size
=
uint32
(
unsafe
.
Sizeof
(
mi
))
...
@@ -426,7 +424,6 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) {
...
@@ -426,7 +424,6 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) {
// Loads an image from file and shows it in tray.
// Loads an image from file and shows it in tray.
// Shell_NotifyIcon: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762159(v=vs.85).aspx
// Shell_NotifyIcon: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762159(v=vs.85).aspx
func
(
t
*
winTray
)
setIcon
(
src
string
)
error
{
func
(
t
*
winTray
)
setIcon
(
src
string
)
error
{
h
,
err
:=
t
.
loadIconFrom
(
src
)
h
,
err
:=
t
.
loadIconFrom
(
src
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -444,7 +441,6 @@ func (t *winTray) setIcon(src string) error {
...
@@ -444,7 +441,6 @@ func (t *winTray) setIcon(src string) error {
// Loads an image from file to be shown in tray or menu item.
// Loads an image from file to be shown in tray or menu item.
// LoadImage: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
// LoadImage: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx
func
(
t
*
winTray
)
loadIconFrom
(
src
string
)
(
windows
.
Handle
,
error
)
{
func
(
t
*
winTray
)
loadIconFrom
(
src
string
)
(
windows
.
Handle
,
error
)
{
// Save and reuse handles of loaded images
// Save and reuse handles of loaded images
t
.
muLoadedImages
.
RLock
()
t
.
muLoadedImages
.
RLock
()
h
,
ok
:=
t
.
loadedImages
[
src
]
h
,
ok
:=
t
.
loadedImages
[
src
]
...
...
cmd/cmd.go
View file @
89d99001
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"runtime"
"runtime"
"slices"
"strings"
"strings"
"syscall"
"syscall"
"time"
"time"
...
@@ -29,7 +30,6 @@ import (
...
@@ -29,7 +30,6 @@ import (
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh"
"golang.org/x/exp/slices"
"golang.org/x/term"
"golang.org/x/term"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
...
@@ -746,7 +746,6 @@ func displayResponse(content string, wordWrap bool, state *displayResponseState)
...
@@ -746,7 +746,6 @@ func displayResponse(content string, wordWrap bool, state *displayResponseState)
if
wordWrap
&&
termWidth
>=
10
{
if
wordWrap
&&
termWidth
>=
10
{
for
_
,
ch
:=
range
content
{
for
_
,
ch
:=
range
content
{
if
state
.
lineLength
+
1
>
termWidth
-
5
{
if
state
.
lineLength
+
1
>
termWidth
-
5
{
if
runewidth
.
StringWidth
(
state
.
wordBuffer
)
>
termWidth
-
10
{
if
runewidth
.
StringWidth
(
state
.
wordBuffer
)
>
termWidth
-
10
{
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
fmt
.
Printf
(
"%s%c"
,
state
.
wordBuffer
,
ch
)
state
.
wordBuffer
=
""
state
.
wordBuffer
=
""
...
@@ -1030,24 +1029,6 @@ func initializeKeypair() error {
...
@@ -1030,24 +1029,6 @@ func initializeKeypair() error {
return
nil
return
nil
}
}
//nolint:unused
func
waitForServer
(
ctx
context
.
Context
,
client
*
api
.
Client
)
error
{
// wait for the server to start
timeout
:=
time
.
After
(
5
*
time
.
Second
)
tick
:=
time
.
Tick
(
500
*
time
.
Millisecond
)
for
{
select
{
case
<-
timeout
:
return
errors
.
New
(
"timed out waiting for server to start"
)
case
<-
tick
:
if
err
:=
client
.
Heartbeat
(
ctx
);
err
==
nil
{
return
nil
// server has started
}
}
}
}
func
checkServerHeartbeat
(
cmd
*
cobra
.
Command
,
_
[]
string
)
error
{
func
checkServerHeartbeat
(
cmd
*
cobra
.
Command
,
_
[]
string
)
error
{
client
,
err
:=
api
.
ClientFromEnvironment
()
client
,
err
:=
api
.
ClientFromEnvironment
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cmd/interactive.go
View file @
89d99001
...
@@ -8,11 +8,11 @@ import (
...
@@ -8,11 +8,11 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"slices"
"sort"
"sort"
"strings"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
"golang.org/x/exp/slices"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/envconfig"
"github.com/ollama/ollama/envconfig"
...
...
cmd/interactive_test.go
View file @
89d99001
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"text/template"
"text/template"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/api"
)
)
...
@@ -85,11 +86,11 @@ MESSAGE assistant """Yes it is true, I am half horse, half shark."""
...
@@ -85,11 +86,11 @@ MESSAGE assistant """Yes it is true, I am half horse, half shark."""
`
`
tmpl
,
err
:=
template
.
New
(
""
)
.
Parse
(
expectedModelfile
)
tmpl
,
err
:=
template
.
New
(
""
)
.
Parse
(
expectedModelfile
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
err
=
tmpl
.
Execute
(
&
buf
,
opts
)
err
=
tmpl
.
Execute
(
&
buf
,
opts
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
buf
.
String
(),
mf
)
assert
.
Equal
(
t
,
buf
.
String
(),
mf
)
opts
.
ParentModel
=
"horseshark"
opts
.
ParentModel
=
"horseshark"
...
@@ -107,10 +108,10 @@ MESSAGE assistant """Yes it is true, I am half horse, half shark."""
...
@@ -107,10 +108,10 @@ MESSAGE assistant """Yes it is true, I am half horse, half shark."""
`
`
tmpl
,
err
=
template
.
New
(
""
)
.
Parse
(
expectedModelfile
)
tmpl
,
err
=
template
.
New
(
""
)
.
Parse
(
expectedModelfile
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
var
parentBuf
bytes
.
Buffer
var
parentBuf
bytes
.
Buffer
err
=
tmpl
.
Execute
(
&
parentBuf
,
opts
)
err
=
tmpl
.
Execute
(
&
parentBuf
,
opts
)
assert
.
Nil
(
t
,
err
)
require
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
parentBuf
.
String
(),
mf
)
assert
.
Equal
(
t
,
parentBuf
.
String
(),
mf
)
}
}
cmd/start.go
0 → 100644
View file @
89d99001
//go:build darwin || windows
package
cmd
import
(
"context"
"errors"
"time"
"github.com/ollama/ollama/api"
)
func
waitForServer
(
ctx
context
.
Context
,
client
*
api
.
Client
)
error
{
// wait for the server to start
timeout
:=
time
.
After
(
5
*
time
.
Second
)
tick
:=
time
.
Tick
(
500
*
time
.
Millisecond
)
for
{
select
{
case
<-
timeout
:
return
errors
.
New
(
"timed out waiting for server to start"
)
case
<-
tick
:
if
err
:=
client
.
Heartbeat
(
ctx
);
err
==
nil
{
return
nil
// server has started
}
}
}
}
convert/convert.go
View file @
89d99001
...
@@ -189,7 +189,7 @@ func LoadSentencePieceTokens(dirpath string, params *Params) (*Vocab, error) {
...
@@ -189,7 +189,7 @@ func LoadSentencePieceTokens(dirpath string, params *Params) (*Vocab, error) {
if
params
.
VocabSize
>
len
(
v
.
Tokens
)
{
if
params
.
VocabSize
>
len
(
v
.
Tokens
)
{
missingTokens
:=
params
.
VocabSize
-
len
(
v
.
Tokens
)
missingTokens
:=
params
.
VocabSize
-
len
(
v
.
Tokens
)
slog
.
Warn
(
fmt
.
Sprintf
(
"vocab is missing %d tokens"
,
missingTokens
))
slog
.
Warn
(
fmt
.
Sprintf
(
"vocab is missing %d tokens"
,
missingTokens
))
for
cnt
:=
0
;
cnt
<
missingTokens
;
cnt
++
{
for
cnt
:=
range
missingTokens
{
v
.
Tokens
=
append
(
v
.
Tokens
,
fmt
.
Sprintf
(
"<dummy%05d>"
,
cnt
+
1
))
v
.
Tokens
=
append
(
v
.
Tokens
,
fmt
.
Sprintf
(
"<dummy%05d>"
,
cnt
+
1
))
v
.
Scores
=
append
(
v
.
Scores
,
-
1
)
v
.
Scores
=
append
(
v
.
Scores
,
-
1
)
v
.
Types
=
append
(
v
.
Types
,
tokenTypeUserDefined
)
v
.
Types
=
append
(
v
.
Types
,
tokenTypeUserDefined
)
...
...
convert/gemma.go
View file @
89d99001
...
@@ -35,7 +35,6 @@ func addOnes(data []float32, vectorSize int) ([]float32, error) {
...
@@ -35,7 +35,6 @@ func addOnes(data []float32, vectorSize int) ([]float32, error) {
f32s
=
append
(
f32s
,
t
...
)
f32s
=
append
(
f32s
,
t
...
)
}
}
return
f32s
,
nil
return
f32s
,
nil
}
}
...
...
convert/llama.go
View file @
89d99001
...
@@ -119,11 +119,12 @@ func llamaRepack(name string, params *Params, data []float32, shape []uint64) ([
...
@@ -119,11 +119,12 @@ func llamaRepack(name string, params *Params, data []float32, shape []uint64) ([
}
}
var
heads
int
var
heads
int
if
strings
.
HasSuffix
(
name
,
"attn_q.weight"
)
{
switch
{
case
strings
.
HasSuffix
(
name
,
"attn_q.weight"
)
:
heads
=
params
.
AttentionHeads
heads
=
params
.
AttentionHeads
}
else
if
strings
.
HasSuffix
(
name
,
"attn_k.weight"
)
{
case
strings
.
HasSuffix
(
name
,
"attn_k.weight"
)
:
heads
=
cmp
.
Or
(
params
.
KeyValHeads
,
params
.
AttentionHeads
)
heads
=
cmp
.
Or
(
params
.
KeyValHeads
,
params
.
AttentionHeads
)
}
else
{
default
:
return
nil
,
fmt
.
Errorf
(
"unknown tensor name: %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"unknown tensor name: %s"
,
name
)
}
}
...
...
convert/safetensors.go
View file @
89d99001
...
@@ -120,7 +120,7 @@ func (m *SafetensorFormat) readTensors(fn string, offset uint64, params *Params)
...
@@ -120,7 +120,7 @@ func (m *SafetensorFormat) readTensors(fn string, offset uint64, params *Params)
Name
:
name
,
Name
:
name
,
Kind
:
kind
,
Kind
:
kind
,
Offset
:
offset
,
Offset
:
offset
,
Shape
:
shape
[
:
]
,
Shape
:
shape
,
}
}
t
.
WriterTo
=
safetensorWriterTo
{
t
.
WriterTo
=
safetensorWriterTo
{
...
...
convert/tokenizer.go
View file @
89d99001
...
@@ -85,11 +85,8 @@ func parseTokens(dirpath string) (pre string, tokens []Token, merges []string, e
...
@@ -85,11 +85,8 @@ func parseTokens(dirpath string) (pre string, tokens []Token, merges []string, e
sha256sum
:=
sha256
.
New
()
sha256sum
:=
sha256
.
New
()
for
_
,
pt
:=
range
t
.
PreTokenizer
.
PreTokenizers
{
for
_
,
pt
:=
range
t
.
PreTokenizer
.
PreTokenizers
{
switch
pt
.
Type
{
if
pt
.
Type
==
"Split"
&&
pt
.
Pattern
.
Regex
!=
""
{
case
"Split"
:
sha256sum
.
Write
([]
byte
(
pt
.
Pattern
.
Regex
))
if
pt
.
Pattern
.
Regex
!=
""
{
sha256sum
.
Write
([]
byte
(
pt
.
Pattern
.
Regex
))
}
}
}
}
}
...
...
Prev
1
2
3
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