fix(gemini): trim "data:" prefix in raw JSON and resolve variable shadowing in stream translation

This commit is contained in:
Luis Pater
2025-09-23 21:22:41 +08:00
parent 361a69f4de
commit b018072914
2 changed files with 6 additions and 2 deletions

View File

@@ -95,13 +95,13 @@ func (e *GeminiWebExecutor) ExecuteStream(ctx context.Context, auth *cliproxyaut
defer mutex.Unlock() defer mutex.Unlock()
} }
for _, line := range lines { for _, line := range lines {
lines := sdktranslator.TranslateStream(ctx, to, from, req.Model, bytes.Clone(opts.OriginalRequest), req.Payload, bytes.Clone([]byte(line)), &param) lines = sdktranslator.TranslateStream(ctx, to, from, req.Model, bytes.Clone(opts.OriginalRequest), req.Payload, bytes.Clone([]byte(line)), &param)
for _, l := range lines { for _, l := range lines {
out <- cliproxyexecutor.StreamChunk{Payload: []byte(l)} out <- cliproxyexecutor.StreamChunk{Payload: []byte(l)}
} }
} }
for _, line := range done { for _, line := range done {
lines := sdktranslator.TranslateStream(ctx, to, from, req.Model, bytes.Clone(opts.OriginalRequest), req.Payload, bytes.Clone([]byte(line)), &param) lines = sdktranslator.TranslateStream(ctx, to, from, req.Model, bytes.Clone(opts.OriginalRequest), req.Payload, bytes.Clone([]byte(line)), &param)
for _, l := range lines { for _, l := range lines {
out <- cliproxyexecutor.StreamChunk{Payload: []byte(l)} out <- cliproxyexecutor.StreamChunk{Payload: []byte(l)}
} }

View File

@@ -42,6 +42,10 @@ func ConvertGeminiResponseToOpenAI(_ context.Context, _ string, originalRequestR
} }
} }
if bytes.HasPrefix(rawJSON, []byte("data:")) {
rawJSON = bytes.TrimSpace(rawJSON[5:])
}
if bytes.Equal(rawJSON, []byte("[DONE]")) { if bytes.Equal(rawJSON, []byte("[DONE]")) {
return []string{} return []string{}
} }