fix(gemini): update response template to omit finishReason until known

This commit is contained in:
Luis Pater
2025-10-16 06:41:04 +08:00
parent c419264a70
commit eb2549a782

View File

@@ -97,8 +97,8 @@ func ConvertOpenAIResponseToGemini(_ context.Context, _ string, originalRequestR
var results []string var results []string
choices.ForEach(func(choiceIndex, choice gjson.Result) bool { choices.ForEach(func(choiceIndex, choice gjson.Result) bool {
// Base Gemini response template // Base Gemini response template without finishReason; set when known
template := `{"candidates":[{"content":{"parts":[],"role":"model"},"finishReason":"STOP","index":0}]}` template := `{"candidates":[{"content":{"parts":[],"role":"model"},"index":0}]}`
// Set model if available // Set model if available
if model := root.Get("model"); model.Exists() { if model := root.Get("model"); model.Exists() {
@@ -514,8 +514,8 @@ func tryParseNumber(s string) (interface{}, bool) {
func ConvertOpenAIResponseToGeminiNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string { func ConvertOpenAIResponseToGeminiNonStream(_ context.Context, _ string, originalRequestRawJSON, requestRawJSON, rawJSON []byte, _ *any) string {
root := gjson.ParseBytes(rawJSON) root := gjson.ParseBytes(rawJSON)
// Base Gemini response template // Base Gemini response template without finishReason; set when known
out := `{"candidates":[{"content":{"parts":[],"role":"model"},"finishReason":"STOP","index":0}]}` out := `{"candidates":[{"content":{"parts":[],"role":"model"},"index":0}]}`
// Set model if available // Set model if available
if model := root.Get("model"); model.Exists() { if model := root.Get("model"); model.Exists() {