fix(gemini): handle "[DONE]" chunk, trim "data:" prefix, and remove session_id from requests

- Adjusted stream handling to skip "[DONE]" chunks.
- Ensured "data:" prefix is trimmed for non-prefixed input in translation.
- Removed `session_id` from request bodies before processing.
This commit is contained in:
Luis Pater
2025-09-24 23:34:46 +08:00
parent 68be2f023f
commit 48bbd9e214
4 changed files with 39 additions and 7 deletions

View File

@@ -193,7 +193,14 @@ func (h *GeminiCLIAPIHandler) forwardCLIStream(c *gin.Context, flusher http.Flus
return
}
if alt == "" {
_, _ = c.Writer.Write([]byte("data: "))
if bytes.Equal(chunk, []byte("data: [DONE]")) || bytes.Equal(chunk, []byte("[DONE]")) {
continue
}
if !bytes.HasPrefix(chunk, []byte("data:")) {
_, _ = c.Writer.Write([]byte("data: "))
}
_, _ = c.Writer.Write(chunk)
_, _ = c.Writer.Write([]byte("\n\n"))
} else {