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
06376322
"example/vscode:/vscode.git/clone" did not exist on "88c36f836f44e290e6e3b8e8c42ab0ff6138ebc1"
Commit
06376322
authored
Jul 06, 2023
by
Michael Yang
Committed by
Jeffrey Morgan
Jul 06, 2023
Browse files
simple pull response
parent
dd960d1d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
15 deletions
+12
-15
api/client.go
api/client.go
+1
-14
server/routes.go
server/routes.go
+11
-1
No files found.
api/client.go
View file @
06376322
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"fmt"
"fmt"
"io"
"io"
"net/http"
"net/http"
"strings"
"sync"
"sync"
)
)
...
@@ -140,20 +139,8 @@ func (c *Client) Pull(ctx context.Context, req *PullRequest, callback func(progr
...
@@ -140,20 +139,8 @@ func (c *Client) Pull(ctx context.Context, req *PullRequest, callback func(progr
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
wg
.
Add
(
1
)
if
err
:=
c
.
stream
(
ctx
,
http
.
MethodPost
,
"/api/pull"
,
req
,
func
(
progressBytes
[]
byte
)
{
if
err
:=
c
.
stream
(
ctx
,
http
.
MethodPost
,
"/api/pull"
,
req
,
func
(
progressBytes
[]
byte
)
{
/*
Events have the following format for progress:
event:progress
data:{"total":123,"completed":123,"percent":0.1}
Need to parse out the data part and unmarshal it.
*/
eventParts
:=
strings
.
Split
(
string
(
progressBytes
),
"data:"
)
if
len
(
eventParts
)
<
2
{
// no data part, ignore
return
}
eventData
:=
eventParts
[
1
]
var
progress
PullProgress
var
progress
PullProgress
if
err
:=
json
.
Unmarshal
(
[]
byte
(
eventData
)
,
&
progress
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
progressBytes
,
&
progress
);
err
!=
nil
{
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
return
return
}
}
...
...
server/routes.go
View file @
06376322
...
@@ -120,7 +120,17 @@ func Serve(ln net.Listener) error {
...
@@ -120,7 +120,17 @@ func Serve(ln net.Listener) error {
if
!
ok
{
if
!
ok
{
return
false
return
false
}
}
c
.
SSEvent
(
"progress"
,
progress
)
bts
,
err
:=
json
.
Marshal
(
progress
)
if
err
!=
nil
{
return
false
}
bts
=
append
(
bts
,
'\n'
)
if
_
,
err
:=
w
.
Write
(
bts
);
err
!=
nil
{
return
false
}
return
true
return
true
})
})
})
})
...
...
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