mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Merge pull request #1294 from Darley-Wey/fix/claude2gemini
fix: skip empty text parts and messages to avoid Gemini API error
This commit is contained in:
@@ -155,10 +155,13 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
clientContentJSON, _ = sjson.SetRaw(clientContentJSON, "parts.-1", partJSON)
|
clientContentJSON, _ = sjson.SetRaw(clientContentJSON, "parts.-1", partJSON)
|
||||||
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "text" {
|
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "text" {
|
||||||
prompt := contentResult.Get("text").String()
|
prompt := contentResult.Get("text").String()
|
||||||
partJSON := `{}`
|
// Skip empty text parts to avoid Gemini API error:
|
||||||
if prompt != "" {
|
// "required oneof field 'data' must have one initialized field"
|
||||||
partJSON, _ = sjson.Set(partJSON, "text", prompt)
|
if prompt == "" {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
partJSON := `{}`
|
||||||
|
partJSON, _ = sjson.Set(partJSON, "text", prompt)
|
||||||
clientContentJSON, _ = sjson.SetRaw(clientContentJSON, "parts.-1", partJSON)
|
clientContentJSON, _ = sjson.SetRaw(clientContentJSON, "parts.-1", partJSON)
|
||||||
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
} else if contentTypeResult.Type == gjson.String && contentTypeResult.String() == "tool_use" {
|
||||||
// NOTE: Do NOT inject dummy thinking blocks here.
|
// NOTE: Do NOT inject dummy thinking blocks here.
|
||||||
@@ -285,6 +288,13 @@ func ConvertClaudeRequestToAntigravity(modelName string, inputRawJSON []byte, _
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip messages with empty parts array to avoid Gemini API error:
|
||||||
|
// "required oneof field 'data' must have one initialized field"
|
||||||
|
partsCheck := gjson.Get(clientContentJSON, "parts")
|
||||||
|
if !partsCheck.IsArray() || len(partsCheck.Array()) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
contentsJSON, _ = sjson.SetRaw(contentsJSON, "-1", clientContentJSON)
|
contentsJSON, _ = sjson.SetRaw(contentsJSON, "-1", clientContentJSON)
|
||||||
hasContents = true
|
hasContents = true
|
||||||
} else if contentsResult.Type == gjson.String {
|
} else if contentsResult.Type == gjson.String {
|
||||||
|
|||||||
Reference in New Issue
Block a user