fix: use camelCase systemInstruction in OpenAI-to-Gemini translators
The Gemini v1internal (cloudcode-pa) and Antigravity Manager endpoints require camelCase "systemInstruction" in request JSON. The current snake_case "system_instruction" causes system prompts to be silently ignored when routing through these endpoints. Replace all "system_instruction" JSON keys with "systemInstruction" in chat-completions and responses request translators.
This commit is contained in:
@@ -147,21 +147,21 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
|
|||||||
content := m.Get("content")
|
content := m.Get("content")
|
||||||
|
|
||||||
if (role == "system" || role == "developer") && len(arr) > 1 {
|
if (role == "system" || role == "developer") && len(arr) > 1 {
|
||||||
// system -> system_instruction as a user message style
|
// system -> systemInstruction as a user message style
|
||||||
if content.Type == gjson.String {
|
if content.Type == gjson.String {
|
||||||
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
|
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
|
||||||
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), content.String())
|
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), content.String())
|
||||||
systemPartIndex++
|
systemPartIndex++
|
||||||
} else if content.IsObject() && content.Get("type").String() == "text" {
|
} else if content.IsObject() && content.Get("type").String() == "text" {
|
||||||
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
|
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
|
||||||
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), content.Get("text").String())
|
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), content.Get("text").String())
|
||||||
systemPartIndex++
|
systemPartIndex++
|
||||||
} else if content.IsArray() {
|
} else if content.IsArray() {
|
||||||
contents := content.Array()
|
contents := content.Array()
|
||||||
if len(contents) > 0 {
|
if len(contents) > 0 {
|
||||||
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
|
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
|
||||||
for j := 0; j < len(contents); j++ {
|
for j := 0; j < len(contents); j++ {
|
||||||
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), contents[j].Get("text").String())
|
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), contents[j].Get("text").String())
|
||||||
systemPartIndex++
|
systemPartIndex++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
|
|||||||
if instructions := root.Get("instructions"); instructions.Exists() {
|
if instructions := root.Get("instructions"); instructions.Exists() {
|
||||||
systemInstr := `{"parts":[{"text":""}]}`
|
systemInstr := `{"parts":[{"text":""}]}`
|
||||||
systemInstr, _ = sjson.Set(systemInstr, "parts.0.text", instructions.String())
|
systemInstr, _ = sjson.Set(systemInstr, "parts.0.text", instructions.String())
|
||||||
out, _ = sjson.SetRaw(out, "system_instruction", systemInstr)
|
out, _ = sjson.SetRaw(out, "systemInstruction", systemInstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert input messages to Gemini contents format
|
// Convert input messages to Gemini contents format
|
||||||
@@ -119,7 +119,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
|
|||||||
if strings.EqualFold(itemRole, "system") {
|
if strings.EqualFold(itemRole, "system") {
|
||||||
if contentArray := item.Get("content"); contentArray.Exists() {
|
if contentArray := item.Get("content"); contentArray.Exists() {
|
||||||
systemInstr := ""
|
systemInstr := ""
|
||||||
if systemInstructionResult := gjson.Get(out, "system_instruction"); systemInstructionResult.Exists() {
|
if systemInstructionResult := gjson.Get(out, "systemInstruction"); systemInstructionResult.Exists() {
|
||||||
systemInstr = systemInstructionResult.Raw
|
systemInstr = systemInstructionResult.Raw
|
||||||
} else {
|
} else {
|
||||||
systemInstr = `{"parts":[]}`
|
systemInstr = `{"parts":[]}`
|
||||||
@@ -140,7 +140,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
|
|||||||
}
|
}
|
||||||
|
|
||||||
if systemInstr != `{"parts":[]}` {
|
if systemInstr != `{"parts":[]}` {
|
||||||
out, _ = sjson.SetRaw(out, "system_instruction", systemInstr)
|
out, _ = sjson.SetRaw(out, "systemInstruction", systemInstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user