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
32064a06
"vscode:/vscode.git/clone" did not exist on "38898931205ae23aa6fa6c8b90281e034b4b6f1e"
Commit
32064a06
authored
Dec 10, 2023
by
Jeffrey Morgan
Browse files
fix empty response when receiving runner error
parent
d9a250e9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
20 deletions
+40
-20
docs/api.md
docs/api.md
+2
-2
server/routes.go
server/routes.go
+38
-18
No files found.
docs/api.md
View file @
32064a06
...
...
@@ -252,7 +252,7 @@ curl http://localhost:11434/api/generate -d '{
"penalize_newline": true,
"stop": ["\n", "user:"],
"numa": false,
"num_ctx": 4,
"num_ctx":
102
4,
"num_batch": 2,
"num_gqa": 1,
"num_gpu": 1,
...
...
server/routes.go
View file @
32064a06
...
...
@@ -300,19 +300,30 @@ func GenerateHandler(c *gin.Context) {
}()
if
req
.
Stream
!=
nil
&&
!*
req
.
Stream
{
//
Wait for the channel to clo
se
var
r
api
.
GenerateResponse
//
Accumulate responses into the final respon
se
var
final
api
.
GenerateResponse
var
sb
strings
.
Builder
for
resp
:=
range
ch
{
var
ok
bool
if
r
,
ok
=
resp
.
(
api
.
GenerateResponse
);
!
ok
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
r
:=
resp
.
(
type
)
{
case
api
.
GenerateResponse
:
sb
.
WriteString
(
r
.
Response
)
final
=
r
case
gin
.
H
:
if
errorMsg
,
ok
:=
r
[
"error"
]
.
(
string
);
ok
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
errorMsg
})
return
}
else
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"unexpected error format in response"
})
return
}
sb
.
WriteString
(
r
.
Response
)
default
:
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"unexpected error"
})
return
}
r
.
Response
=
sb
.
String
()
c
.
JSON
(
http
.
StatusOK
,
r
)
}
final
.
Response
=
sb
.
String
()
c
.
JSON
(
http
.
StatusOK
,
final
)
return
}
...
...
@@ -1008,21 +1019,30 @@ func ChatHandler(c *gin.Context) {
}()
if
req
.
Stream
!=
nil
&&
!*
req
.
Stream
{
//
Wait for the channel to clo
se
var
r
api
.
ChatResponse
//
Accumulate responses into the final respon
se
var
final
api
.
ChatResponse
var
sb
strings
.
Builder
for
resp
:=
range
ch
{
var
ok
bool
if
r
,
ok
=
resp
.
(
api
.
ChatResponse
);
!
ok
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
err
.
Error
()})
switch
r
:=
resp
.
(
type
)
{
case
api
.
ChatResponse
:
sb
.
WriteString
(
r
.
Message
.
Content
)
final
=
r
case
gin
.
H
:
if
errorMsg
,
ok
:=
r
[
"error"
]
.
(
string
);
ok
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
errorMsg
})
return
}
else
{
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"unexpected error format in response"
})
return
}
if
r
.
Message
!=
nil
{
sb
.
WriteString
(
r
.
Message
.
Content
)
default
:
c
.
JSON
(
http
.
StatusInternalServerError
,
gin
.
H
{
"error"
:
"unexpected error"
})
return
}
}
r
.
Message
=
&
api
.
Message
{
Role
:
"assistant"
,
Content
:
sb
.
String
()}
c
.
JSON
(
http
.
StatusOK
,
r
)
final
.
Message
=
&
api
.
Message
{
Role
:
"assistant"
,
Content
:
sb
.
String
()}
c
.
JSON
(
http
.
StatusOK
,
final
)
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