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
orangecat
ollama
Commits
61dd87bd
"vscode:/vscode.git/clone" did not exist on "9bbd4600a669e366633da31069aeada58d7b1382"
Commit
61dd87bd
authored
Jul 07, 2023
by
Bruce MacDonald
Browse files
if directory cannot be resolved, do not fail
parent
b24be8c6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
2 deletions
+43
-2
api/types.go
api/types.go
+1
-0
cmd/cmd.go
cmd/cmd.go
+5
-0
server/routes.go
server/routes.go
+37
-2
No files found.
api/types.go
View file @
61dd87bd
...
@@ -26,6 +26,7 @@ type PullProgress struct {
...
@@ -26,6 +26,7 @@ type PullProgress struct {
Total
int64
`json:"total"`
Total
int64
`json:"total"`
Completed
int64
`json:"completed"`
Completed
int64
`json:"completed"`
Percent
float64
`json:"percent"`
Percent
float64
`json:"percent"`
Error
Error
`json:"error"`
}
}
type
GenerateRequest
struct
{
type
GenerateRequest
struct
{
...
...
cmd/cmd.go
View file @
61dd87bd
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"fmt"
"fmt"
"log"
"log"
"net"
"net"
"net/http"
"os"
"os"
"path"
"path"
"strings"
"strings"
...
@@ -50,6 +51,10 @@ func pull(model string) error {
...
@@ -50,6 +51,10 @@ func pull(model string) error {
context
.
Background
(),
context
.
Background
(),
&
api
.
PullRequest
{
Model
:
model
},
&
api
.
PullRequest
{
Model
:
model
},
func
(
progress
api
.
PullProgress
)
error
{
func
(
progress
api
.
PullProgress
)
error
{
if
progress
.
Error
.
Code
==
http
.
StatusBadGateway
{
// couldn't pull the model from the directory, proceed in offline mode
return
nil
}
if
bar
==
nil
&&
progress
.
Percent
==
100
{
if
bar
==
nil
&&
progress
.
Percent
==
100
{
// already downloaded
// already downloaded
return
nil
return
nil
...
...
server/routes.go
View file @
61dd87bd
...
@@ -3,12 +3,14 @@ package server
...
@@ -3,12 +3,14 @@ package server
import
(
import
(
"embed"
"embed"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"io"
"io"
"log"
"log"
"math"
"math"
"net"
"net"
"net/http"
"net/http"
"os"
"path"
"path"
"runtime"
"runtime"
"strings"
"strings"
...
@@ -25,6 +27,15 @@ import (
...
@@ -25,6 +27,15 @@ import (
var
templatesFS
embed
.
FS
var
templatesFS
embed
.
FS
var
templates
=
template
.
Must
(
template
.
ParseFS
(
templatesFS
,
"templates/*.prompt"
))
var
templates
=
template
.
Must
(
template
.
ParseFS
(
templatesFS
,
"templates/*.prompt"
))
func
cacheDir
()
string
{
home
,
err
:=
os
.
UserHomeDir
()
if
err
!=
nil
{
panic
(
err
)
}
return
path
.
Join
(
home
,
".ollama"
)
}
func
generate
(
c
*
gin
.
Context
)
{
func
generate
(
c
*
gin
.
Context
)
{
var
req
api
.
GenerateRequest
var
req
api
.
GenerateRequest
req
.
ModelOptions
=
api
.
DefaultModelOptions
req
.
ModelOptions
=
api
.
DefaultModelOptions
...
@@ -34,12 +45,25 @@ func generate(c *gin.Context) {
...
@@ -34,12 +45,25 @@ func generate(c *gin.Context) {
return
return
}
}
if
remoteModel
,
_
:=
getRemote
(
req
.
Model
);
remoteModel
!=
nil
{
remoteModel
,
err
:=
getRemote
(
req
.
Model
)
if
err
!=
nil
{
// couldn't check the directory, proceed in offline mode
_
,
err
:=
os
.
Stat
(
req
.
Model
)
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"message"
:
err
.
Error
()})
return
}
// couldn't find the model file, try setting the model to the cache directory
req
.
Model
=
path
.
Join
(
cacheDir
(),
"models"
,
req
.
Model
+
".bin"
)
}
}
if
remoteModel
!=
nil
{
req
.
Model
=
remoteModel
.
FullName
()
req
.
Model
=
remoteModel
.
FullName
()
}
}
modelOpts
:=
getModelOpts
(
req
)
modelOpts
:=
getModelOpts
(
req
)
modelOpts
.
NGPULayers
=
1
// hard-code this for now
modelOpts
.
NGPULayers
=
1
// hard-code this for now
model
,
err
:=
llama
.
New
(
req
.
Model
,
modelOpts
)
model
,
err
:=
llama
.
New
(
req
.
Model
,
modelOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -118,6 +142,17 @@ func Serve(ln net.Listener) error {
...
@@ -118,6 +142,17 @@ func Serve(ln net.Listener) error {
go
func
()
{
go
func
()
{
defer
close
(
progressCh
)
defer
close
(
progressCh
)
if
err
:=
pull
(
req
.
Model
,
progressCh
);
err
!=
nil
{
if
err
:=
pull
(
req
.
Model
,
progressCh
);
err
!=
nil
{
var
opError
*
net
.
OpError
if
errors
.
As
(
err
,
&
opError
)
{
result
:=
api
.
PullProgress
{
Error
:
api
.
Error
{
Code
:
http
.
StatusBadGateway
,
Message
:
"failed to get models from directory"
,
},
}
c
.
JSON
(
http
.
StatusBadGateway
,
result
)
return
}
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"message"
:
err
.
Error
()})
c
.
JSON
(
http
.
StatusBadRequest
,
gin
.
H
{
"message"
:
err
.
Error
()})
return
return
}
}
...
...
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