mirror of
https://github.com/likelovewant/ollama-for-amd.git
synced 2025-12-21 22:33:56 +00: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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user