feat(translator): Pass through imageConfig

This commit is contained in:
hkfires
2025-10-09 13:50:43 +08:00
parent d45ebff66b
commit c5d7137d66
3 changed files with 18 additions and 0 deletions

View File

@@ -79,6 +79,12 @@ func ConvertOpenAIRequestToGeminiCLI(modelName string, inputRawJSON []byte, _ bo
out, _ = sjson.SetBytes(out, "request.generationConfig.topK", tkr.Num)
}
// Image config passthrough (e.g., aspectRatio)
// If the input carries generationConfig.imageConfig, preserve it in the Gemini CLI request.
if imgCfg := gjson.GetBytes(rawJSON, "generationConfig.imageConfig"); imgCfg.Exists() && imgCfg.IsObject() {
out, _ = sjson.SetRawBytes(out, "request.generationConfig.imageConfig", []byte(imgCfg.Raw))
}
// messages -> systemInstruction + contents
messages := gjson.GetBytes(rawJSON, "messages")
if messages.IsArray() {

View File

@@ -79,6 +79,12 @@ func ConvertOpenAIRequestToGemini(modelName string, inputRawJSON []byte, _ bool)
out, _ = sjson.SetBytes(out, "generationConfig.topK", tkr.Num)
}
// Image config passthrough (e.g., aspectRatio)
// If the input carries generationConfig.imageConfig, preserve it in the Gemini request.
if imgCfg := gjson.GetBytes(rawJSON, "generationConfig.imageConfig"); imgCfg.Exists() && imgCfg.IsObject() {
out, _ = sjson.SetRawBytes(out, "generationConfig.imageConfig", []byte(imgCfg.Raw))
}
// messages -> systemInstruction + contents
messages := gjson.GetBytes(rawJSON, "messages")
if messages.IsArray() {

View File

@@ -262,5 +262,11 @@ func ConvertOpenAIResponsesRequestToGemini(modelName string, inputRawJSON []byte
}
}
// Image config passthrough (e.g., aspectRatio)
// If the input carries generationConfig.imageConfig, preserve it in the Gemini request.
if imgCfg := root.Get("generationConfig.imageConfig"); imgCfg.Exists() && imgCfg.IsObject() {
out, _ = sjson.SetRaw(out, "generationConfig.imageConfig", imgCfg.Raw)
}
return []byte(out)
}