Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5d05cd9d
authored
Nov 30, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(gemini): add validation and conversion for imageConfig parameters in extra_body
parent
d4fbe1ce
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
0 deletions
+34
-0
relay/channel/gemini/relay-gemini.go
+34
-0
No files found.
relay/channel/gemini/relay-gemini.go
View file @
5d05cd9d
...
@@ -208,6 +208,7 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
...
@@ -208,6 +208,7 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
adaptorWithExtraBody
:=
false
adaptorWithExtraBody
:=
false
// patch extra_body
if
len
(
textRequest
.
ExtraBody
)
>
0
{
if
len
(
textRequest
.
ExtraBody
)
>
0
{
if
!
strings
.
HasSuffix
(
info
.
UpstreamModelName
,
"-nothinking"
)
{
if
!
strings
.
HasSuffix
(
info
.
UpstreamModelName
,
"-nothinking"
)
{
var
extraBody
map
[
string
]
interface
{}
var
extraBody
map
[
string
]
interface
{}
...
@@ -239,6 +240,39 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
...
@@ -239,6 +240,39 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
}
}
}
}
}
}
// check error param name like imageConfig, should be image_config
if
_
,
hasErrorParam
:=
googleBody
[
"imageConfig"
];
hasErrorParam
{
return
nil
,
errors
.
New
(
"extra_body.google.imageConfig is not supported, use extra_body.google.image_config instead"
)
}
if
imageConfig
,
ok
:=
googleBody
[
"image_config"
]
.
(
map
[
string
]
interface
{});
ok
{
// check error param name like aspectRatio, should be aspect_ratio
if
_
,
hasErrorParam
:=
imageConfig
[
"aspectRatio"
];
hasErrorParam
{
return
nil
,
errors
.
New
(
"extra_body.google.image_config.aspectRatio is not supported, use extra_body.google.image_config.aspect_ratio instead"
)
}
// check error param name like imageSize, should be image_size
if
_
,
hasErrorParam
:=
imageConfig
[
"imageSize"
];
hasErrorParam
{
return
nil
,
errors
.
New
(
"extra_body.google.image_config.imageSize is not supported, use extra_body.google.image_config.image_size instead"
)
}
// convert snake_case to camelCase for Gemini API
geminiImageConfig
:=
make
(
map
[
string
]
interface
{})
if
aspectRatio
,
ok
:=
imageConfig
[
"aspect_ratio"
];
ok
{
geminiImageConfig
[
"aspectRatio"
]
=
aspectRatio
}
if
imageSize
,
ok
:=
imageConfig
[
"image_size"
];
ok
{
geminiImageConfig
[
"imageSize"
]
=
imageSize
}
if
len
(
geminiImageConfig
)
>
0
{
imageConfigBytes
,
err
:=
common
.
Marshal
(
geminiImageConfig
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to marshal image_config: %w"
,
err
)
}
geminiRequest
.
GenerationConfig
.
ImageConfig
=
imageConfigBytes
}
}
}
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment