Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
fix empty response when receiving runner error
Jeffrey Morgan32064a064660
diff --git a/docs/api.md b/docs/api.mdindex 329e6ae21..248de114f 100644--- a/docs/api.md+++ b/docs/api.md@@ -252,7 +252,7 @@ curl http://localhost:11434/api/generate -d '{"penalize_newline": true,"stop": ["\n", "user:"],"numa": false,- "num_ctx": 4,+ "num_ctx": 1024,"num_batch": 2,"num_gqa": 1,"num_gpu": 1,@@ -267,7 +267,7 @@ curl http://localhost:11434/api/generate -d '{"rope_frequency_base": 1.1,"rope_frequency_scale": 0.8,"num_thread": 8- }+ }}'```diff --git a/server/routes.go b/server/routes.goindex 8005d1cf7..3c3e77cc0 100644--- a/server/routes.go+++ b/server/routes.go@@ -300,19 +300,30 @@ func GenerateHandler(c *gin.Context) {}()if req.Stream != nil && !*req.Stream {- // Wait for the channel to close- var r api.GenerateResponse+ // Accumulate responses into the final response+ var final api.GenerateResponsevar sb strings.Builderfor 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+ }+ default:+ c.JSON(http.StatusInternalServerError, gin.H{"error": "unexpected error"})return}- sb.WriteString(r.Response)}- 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 close- var r api.ChatResponse+ // Accumulate responses into the final response+ var final api.ChatResponsevar sb strings.Builderfor resp := range ch {- var ok bool- if r, ok = resp.(api.ChatResponse); !ok {- c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})- return- }- if r.Message != nil {+ 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+ }+ 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}