mirror of
https://github.com/ollama/ollama.git
synced 2025-05-11 18:36:41 +02:00
fix: stream accumulator exits early (#10593)
the stream accumulator exits as soon as it sees `api.ProgressResponse(status="success")` which isn't strictly correctly since some requests may have multiple successes, e.g. `/api/create` when the source model needs to be pulled.
This commit is contained in:
parent
6e9a7a2568
commit
0d6e35d3c6
2 changed files with 96 additions and 12 deletions
|
@ -1341,31 +1341,29 @@ func Serve(ln net.Listener) error {
|
|||
|
||||
func waitForStream(c *gin.Context, ch chan any) {
|
||||
c.Header("Content-Type", "application/json")
|
||||
var latest api.ProgressResponse
|
||||
for resp := range ch {
|
||||
switch r := resp.(type) {
|
||||
case api.ProgressResponse:
|
||||
if r.Status == "success" {
|
||||
c.JSON(http.StatusOK, r)
|
||||
return
|
||||
}
|
||||
latest = r
|
||||
case gin.H:
|
||||
status, ok := r["status"].(int)
|
||||
if !ok {
|
||||
status = http.StatusInternalServerError
|
||||
}
|
||||
if errorMsg, ok := r["error"].(string); ok {
|
||||
c.JSON(status, gin.H{"error": errorMsg})
|
||||
return
|
||||
} else {
|
||||
c.JSON(status, gin.H{"error": "unexpected error format in progress response"})
|
||||
return
|
||||
errorMsg, ok := r["error"].(string)
|
||||
if !ok {
|
||||
errorMsg = "unknown error"
|
||||
}
|
||||
c.JSON(status, gin.H{"error": errorMsg})
|
||||
return
|
||||
default:
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "unexpected progress response"})
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "unknown message type"})
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "unexpected end of progress response"})
|
||||
|
||||
c.JSON(http.StatusOK, latest)
|
||||
}
|
||||
|
||||
func streamResponse(c *gin.Context, ch chan any) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue