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
743e957d
Commit
743e957d
authored
Jul 14, 2023
by
Michael Yang
Browse files
use filepath for os compat
parent
560f36e6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
13 deletions
+13
-13
cmd/cmd.go
cmd/cmd.go
+3
-3
server/models.go
server/models.go
+6
-6
server/routes.go
server/routes.go
+4
-4
No files found.
cmd/cmd.go
View file @
743e957d
...
...
@@ -9,7 +9,7 @@ import (
"net"
"net/http"
"os"
"path"
"path
/filepath
"
"strings"
"time"
...
...
@@ -27,7 +27,7 @@ func cacheDir() string {
panic
(
err
)
}
return
path
.
Join
(
home
,
".ollama"
)
return
file
path
.
Join
(
home
,
".ollama"
)
}
func
RunRun
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
...
...
@@ -209,7 +209,7 @@ func NewCLI() *cobra.Command {
},
PersistentPreRunE
:
func
(
_
*
cobra
.
Command
,
args
[]
string
)
error
{
// create the models directory and it's parent
return
os
.
MkdirAll
(
path
.
Join
(
cacheDir
(),
"models"
),
0
o700
)
return
os
.
MkdirAll
(
file
path
.
Join
(
cacheDir
(),
"models"
),
0
o700
)
},
}
...
...
server/models.go
View file @
743e957d
...
...
@@ -7,7 +7,7 @@ import (
"io"
"net/http"
"os"
"path"
"path
/filepath
"
"strconv"
)
...
...
@@ -32,14 +32,14 @@ func (m *Model) FullName() string {
panic
(
err
)
}
return
path
.
Join
(
home
,
".ollama"
,
"models"
,
m
.
Name
+
".bin"
)
return
file
path
.
Join
(
home
,
".ollama"
,
"models"
,
m
.
Name
+
".bin"
)
}
func
(
m
*
Model
)
TempFile
()
string
{
fullName
:=
m
.
FullName
()
return
path
.
Join
(
path
.
Dir
(
fullName
),
fmt
.
Sprintf
(
".%s.part"
,
path
.
Base
(
fullName
)),
return
file
path
.
Join
(
file
path
.
Dir
(
fullName
),
fmt
.
Sprintf
(
".%s.part"
,
file
path
.
Base
(
fullName
)),
)
}
...
...
@@ -118,7 +118,7 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
return
os
.
Rename
(
model
.
TempFile
(),
model
.
FullName
())
}
n
,
err
:=
io
.
CopyN
(
out
,
resp
.
Body
,
8192
)
n
,
err
:=
io
.
CopyN
(
out
,
resp
.
Body
,
8192
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
return
err
}
...
...
server/routes.go
View file @
743e957d
...
...
@@ -10,7 +10,7 @@ import (
"net"
"net/http"
"os"
"path"
"path
/filepath
"
"strings"
"text/template"
"time"
...
...
@@ -32,7 +32,7 @@ func cacheDir() string {
panic
(
err
)
}
return
path
.
Join
(
home
,
".ollama"
)
return
file
path
.
Join
(
home
,
".ollama"
)
}
func
generate
(
c
*
gin
.
Context
)
{
...
...
@@ -55,7 +55,7 @@ func generate(c *gin.Context) {
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"error"
:
err
.
Error
()})
return
}
req
.
Model
=
path
.
Join
(
cacheDir
(),
"models"
,
req
.
Model
+
".bin"
)
req
.
Model
=
file
path
.
Join
(
cacheDir
(),
"models"
,
req
.
Model
+
".bin"
)
}
templateNames
:=
make
([]
string
,
0
,
len
(
templates
.
Templates
()))
...
...
@@ -63,7 +63,7 @@ func generate(c *gin.Context) {
templateNames
=
append
(
templateNames
,
template
.
Name
())
}
match
,
_
:=
matchRankOne
(
path
.
Base
(
req
.
Model
),
templateNames
)
match
,
_
:=
matchRankOne
(
file
path
.
Base
(
req
.
Model
),
templateNames
)
if
template
:=
templates
.
Lookup
(
match
);
template
!=
nil
{
var
sb
strings
.
Builder
if
err
:=
template
.
Execute
(
&
sb
,
req
);
err
!=
nil
{
...
...
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