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:
Michael Yang 2025-05-08 13:17:30 -07:00 committed by GitHub
parent 6e9a7a2568
commit 0d6e35d3c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 96 additions and 12 deletions

View file

@ -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) {