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
92aca977
authored
Feb 11, 2026
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: refactor extra_body handling for improved configuration parsing
parent
3a28a415
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
9 deletions
+52
-9
relay/channel/gemini/relay-gemini.go
+52
-9
No files found.
relay/channel/gemini/relay-gemini.go
View file @
92aca977
...
...
@@ -229,13 +229,14 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
// patch extra_body
if
len
(
textRequest
.
ExtraBody
)
>
0
{
if
!
strings
.
HasSuffix
(
info
.
UpstreamModelName
,
"-nothinking"
)
{
var
extraBody
map
[
string
]
interface
{}
if
err
:=
common
.
Unmarshal
(
textRequest
.
ExtraBody
,
&
extraBody
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid extra body: %w"
,
err
)
}
// eg. {"google":{"thinking_config":{"thinking_budget":5324,"include_thoughts":true}}}
if
googleBody
,
ok
:=
extraBody
[
"google"
]
.
(
map
[
string
]
interface
{});
ok
{
if
!
strings
.
HasSuffix
(
info
.
UpstreamModelName
,
"-nothinking"
)
{
adaptorWithExtraBody
=
true
// check error param name like thinkingConfig, should be thinking_config
if
_
,
hasErrorParam
:=
googleBody
[
"thinkingConfig"
];
hasErrorParam
{
...
...
@@ -247,15 +248,58 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
if
_
,
hasErrorParam
:=
thinkingConfig
[
"thinkingBudget"
];
hasErrorParam
{
return
nil
,
errors
.
New
(
"extra_body.google.thinking_config.thinkingBudget is not supported, use extra_body.google.thinking_config.thinking_budget instead"
)
}
if
budget
,
ok
:=
thinkingConfig
[
"thinking_budget"
]
.
(
float64
);
ok
{
budgetInt
:=
int
(
budget
)
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
dto
.
GeminiThinkingConfig
{
ThinkingBudget
:
common
.
GetPointer
(
budgetInt
),
IncludeThoughts
:
true
,
var
hasThinkingConfig
bool
var
tempThinkingConfig
dto
.
GeminiThinkingConfig
if
thinkingBudget
,
exists
:=
thinkingConfig
[
"thinking_budget"
];
exists
{
switch
v
:=
thinkingBudget
.
(
type
)
{
case
float64
:
budgetInt
:=
int
(
v
)
tempThinkingConfig
.
ThinkingBudget
=
common
.
GetPointer
(
budgetInt
)
if
budgetInt
>
0
{
// 有正数预算
tempThinkingConfig
.
IncludeThoughts
=
true
}
else
{
// 存在但为0或负数,禁用思考
tempThinkingConfig
.
IncludeThoughts
=
false
}
hasThinkingConfig
=
true
default
:
return
nil
,
errors
.
New
(
"extra_body.google.thinking_config.thinking_budget must be an integer"
)
}
}
if
includeThoughts
,
exists
:=
thinkingConfig
[
"include_thoughts"
];
exists
{
if
v
,
ok
:=
includeThoughts
.
(
bool
);
ok
{
tempThinkingConfig
.
IncludeThoughts
=
v
hasThinkingConfig
=
true
}
else
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
dto
.
GeminiThinkingConfig
{
IncludeThoughts
:
true
,
return
nil
,
errors
.
New
(
"extra_body.google.thinking_config.include_thoughts must be a boolean"
)
}
}
if
thinkingLevel
,
exists
:=
thinkingConfig
[
"thinking_level"
];
exists
{
if
v
,
ok
:=
thinkingLevel
.
(
string
);
ok
{
tempThinkingConfig
.
ThinkingLevel
=
v
hasThinkingConfig
=
true
}
else
{
return
nil
,
errors
.
New
(
"extra_body.google.thinking_config.thinking_level must be a string"
)
}
}
if
hasThinkingConfig
{
// 避免 panic: 仅在获得配置时分配,防止后续赋值时空指针
if
geminiRequest
.
GenerationConfig
.
ThinkingConfig
==
nil
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
tempThinkingConfig
}
else
{
// 如果已分配,则合并内容
if
tempThinkingConfig
.
ThinkingBudget
!=
nil
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
.
ThinkingBudget
=
tempThinkingConfig
.
ThinkingBudget
}
geminiRequest
.
GenerationConfig
.
ThinkingConfig
.
IncludeThoughts
=
tempThinkingConfig
.
IncludeThoughts
if
tempThinkingConfig
.
ThinkingLevel
!=
""
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
.
ThinkingLevel
=
tempThinkingConfig
.
ThinkingLevel
}
}
}
}
}
...
...
@@ -294,7 +338,6 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
}
}
}
}
if
!
adaptorWithExtraBody
{
ThinkingAdaptor
(
&
geminiRequest
,
info
,
textRequest
)
...
...
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