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
5571ed52
Unverified
Commit
5571ed52
authored
Jul 12, 2023
by
Michael Yang
Committed by
GitHub
Jul 12, 2023
Browse files
Merge pull request #73 from jmorganca/generate-eof
fix eof error in generate
parents
5028de29
0944b01e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
20 deletions
+16
-20
cmd/cmd.go
cmd/cmd.go
+3
-4
llama/llama.go
llama/llama.go
+2
-2
server/models.go
server/models.go
+10
-13
server/routes.go
server/routes.go
+1
-1
No files found.
cmd/cmd.go
View file @
5571ed52
...
@@ -59,7 +59,7 @@ func pull(model string) error {
...
@@ -59,7 +59,7 @@ func pull(model string) error {
&
api
.
PullRequest
{
Model
:
model
},
&
api
.
PullRequest
{
Model
:
model
},
func
(
progress
api
.
PullProgress
)
error
{
func
(
progress
api
.
PullProgress
)
error
{
if
bar
==
nil
{
if
bar
==
nil
{
if
progress
.
Percent
=
=
100
{
if
progress
.
Percent
>
=
100
{
// already downloaded
// already downloaded
return
nil
return
nil
}
}
...
@@ -73,10 +73,9 @@ func pull(model string) error {
...
@@ -73,10 +73,9 @@ func pull(model string) error {
}
}
func
RunGenerate
(
_
*
cobra
.
Command
,
args
[]
string
)
error
{
func
RunGenerate
(
_
*
cobra
.
Command
,
args
[]
string
)
error
{
// join all args into a single prompt
prompt
:=
strings
.
Join
(
args
[
1
:
],
" "
)
if
len
(
args
)
>
1
{
if
len
(
args
)
>
1
{
return
generate
(
args
[
0
],
prompt
)
// join all args into a single prompt
return
generate
(
args
[
0
],
strings
.
Join
(
args
[
1
:
],
" "
))
}
}
if
term
.
IsTerminal
(
int
(
os
.
Stdin
.
Fd
()))
{
if
term
.
IsTerminal
(
int
(
os
.
Stdin
.
Fd
()))
{
...
...
llama/llama.go
View file @
5571ed52
...
@@ -199,10 +199,10 @@ func (llm *llama) generate(tokens []C.llama_token, fn func(string)) error {
...
@@ -199,10 +199,10 @@ func (llm *llama) generate(tokens []C.llama_token, fn func(string)) error {
token
,
err
:=
llm
.
sample
(
pastTokens
,
&
opts
)
token
,
err
:=
llm
.
sample
(
pastTokens
,
&
opts
)
switch
{
switch
{
case
err
!=
nil
:
return
err
case
errors
.
Is
(
err
,
io
.
EOF
)
:
case
errors
.
Is
(
err
,
io
.
EOF
)
:
return
nil
return
nil
case
err
!=
nil
:
return
err
}
}
fn
(
llm
.
detokenize
(
token
))
fn
(
llm
.
detokenize
(
token
))
...
...
server/models.go
View file @
5571ed52
...
@@ -119,25 +119,22 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
...
@@ -119,25 +119,22 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
}
}
defer
out
.
Close
()
defer
out
.
Close
()
totalSize
,
_
:=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
remaining
,
_
:=
strconv
.
ParseInt
(
resp
.
Header
.
Get
(
"Content-Length"
),
10
,
64
)
completed
:=
size
totalBytes
:=
size
total
:=
remaining
+
completed
totalSize
+=
size
for
{
for
{
n
,
err
:=
io
.
CopyN
(
out
,
resp
.
Body
,
8192
)
fn
(
total
,
completed
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
if
completed
>=
total
{
return
err
return
os
.
Rename
(
model
.
TempFile
(),
model
.
FullName
())
}
}
if
n
==
0
{
n
,
err
:=
io
.
CopyN
(
out
,
resp
.
Body
,
8192
)
break
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
io
.
EOF
)
{
return
err
}
}
totalBytes
+=
n
completed
+=
n
fn
(
totalSize
,
totalBytes
)
}
}
fn
(
totalSize
,
totalSize
)
return
os
.
Rename
(
model
.
TempFile
(),
model
.
FullName
())
}
}
server/routes.go
View file @
5571ed52
...
@@ -112,7 +112,7 @@ func pull(c *gin.Context) {
...
@@ -112,7 +112,7 @@ func pull(c *gin.Context) {
ch
<-
api
.
PullProgress
{
ch
<-
api
.
PullProgress
{
Total
:
total
,
Total
:
total
,
Completed
:
completed
,
Completed
:
completed
,
Percent
:
float64
(
total
)
/
float64
(
completed
)
*
100
,
Percent
:
float64
(
completed
)
/
float64
(
total
)
*
100
,
}
}
}
}
...
...
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