Skip to content

Commit 2e9907c

Browse files
authored
Merge pull request router-for-me#1959 from thebtf/fix/system-instruction-camelcase
fix: use camelCase systemInstruction in OpenAI-to-Gemini translators
2 parents 4f48e52 + 338321e commit 2e9907c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

internal/translator/gemini/openai/chat-completions/gemini_openai_request.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,21 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
147147
content := m.Get("content")
148148

149149
if (role == "system" || role == "developer") && len(arr) > 1 {
150-
// system -> system_instruction as a user message style
150+
// system -> systemInstruction as a user message style
151151
if content.Type == gjson.String {
152-
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
153-
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), content.String())
152+
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
153+
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), content.String())
154154
systemPartIndex++
155155
} else if content.IsObject() && content.Get("type").String() == "text" {
156-
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
157-
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), content.Get("text").String())
156+
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
157+
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), content.Get("text").String())
158158
systemPartIndex++
159159
} else if content.IsArray() {
160160
contents := content.Array()
161161
if len(contents) > 0 {
162-
out, _ = sjson.SetBytes(out, "system_instruction.role", "user")
162+
out, _ = sjson.SetBytes(out, "systemInstruction.role", "user")
163163
for j := 0; j < len(contents); j++ {
164-
out, _ = sjson.SetBytes(out, fmt.Sprintf("system_instruction.parts.%d.text", systemPartIndex), contents[j].Get("text").String())
164+
out, _ = sjson.SetBytes(out, fmt.Sprintf("systemInstruction.parts.%d.text", systemPartIndex), contents[j].Get("text").String())
165165
systemPartIndex++
166166
}
167167
}

internal/translator/gemini/openai/responses/gemini_openai-responses_request.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
2626
if instructions := root.Get("instructions"); instructions.Exists() {
2727
systemInstr := `{"parts":[{"text":""}]}`
2828
systemInstr, _ = sjson.Set(systemInstr, "parts.0.text", instructions.String())
29-
out, _ = sjson.SetRaw(out, "system_instruction", systemInstr)
29+
out, _ = sjson.SetRaw(out, "systemInstruction", systemInstr)
3030
}
3131

3232
// Convert input messages to Gemini contents format
@@ -119,7 +119,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
119119
if strings.EqualFold(itemRole, "system") {
120120
if contentArray := item.Get("content"); contentArray.Exists() {
121121
systemInstr := ""
122-
if systemInstructionResult := gjson.Get(out, "system_instruction"); systemInstructionResult.Exists() {
122+
if systemInstructionResult := gjson.Get(out, "systemInstruction"); systemInstructionResult.Exists() {
123123
systemInstr = systemInstructionResult.Raw
124124
} else {
125125
systemInstr = `{"parts":[]}`
@@ -140,7 +140,7 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
140140
}
141141

142142
if systemInstr != `{"parts":[]}` {
143-
out, _ = sjson.SetRaw(out, "system_instruction", systemInstr)
143+
out, _ = sjson.SetRaw(out, "systemInstruction", systemInstr)
144144
}
145145
}
146146
continue

0 commit comments

Comments
 (0)