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
7601f7f9
authored
Jun 06, 2025
by
Calcium-Ion
Committed by
GitHub
Jun 06, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1167 from RedwindA/feat/2.5-pro-thinkingBudget
Feat: 2.5-pro thinkingBudget
parents
508188ca
d84da74a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
relay/channel/gemini/relay-gemini.go
+29
-16
No files found.
relay/channel/gemini/relay-gemini.go
View file @
7601f7f9
...
...
@@ -57,22 +57,35 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest, info *relaycommon
}
if
model_setting
.
GetGeminiSettings
()
.
ThinkingAdapterEnabled
{
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
"-thinking"
)
{
// 如果模型名以 gemini-2.5-pro 开头,不设置 ThinkingBudget
if
strings
.
HasPrefix
(
info
.
OriginModelName
,
"gemini-2.5-pro"
)
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
GeminiThinkingConfig
{
IncludeThoughts
:
true
,
}
}
else
{
budgetTokens
:=
model_setting
.
GetGeminiSettings
()
.
ThinkingAdapterBudgetTokensPercentage
*
float64
(
geminiRequest
.
GenerationConfig
.
MaxOutputTokens
)
if
budgetTokens
==
0
||
budgetTokens
>
24576
{
budgetTokens
=
24576
}
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
GeminiThinkingConfig
{
ThinkingBudget
:
common
.
GetPointer
(
int
(
budgetTokens
)),
IncludeThoughts
:
true
,
}
}
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
"-thinking"
)
{
// 硬编码不支持 ThinkingBudget 的旧模型
unsupportedModels
:=
[]
string
{
"gemini-2.5-pro-preview-05-06"
,
"gemini-2.5-pro-preview-03-25"
,
}
isUnsupported
:=
false
for
_
,
unsupportedModel
:=
range
unsupportedModels
{
if
strings
.
HasPrefix
(
info
.
OriginModelName
,
unsupportedModel
)
{
isUnsupported
=
true
break
}
}
if
isUnsupported
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
GeminiThinkingConfig
{
IncludeThoughts
:
true
,
}
}
else
{
budgetTokens
:=
model_setting
.
GetGeminiSettings
()
.
ThinkingAdapterBudgetTokensPercentage
*
float64
(
geminiRequest
.
GenerationConfig
.
MaxOutputTokens
)
if
budgetTokens
==
0
||
budgetTokens
>
24576
{
budgetTokens
=
24576
}
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
GeminiThinkingConfig
{
ThinkingBudget
:
common
.
GetPointer
(
int
(
budgetTokens
)),
IncludeThoughts
:
true
,
}
}
}
else
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
"-nothinking"
)
{
geminiRequest
.
GenerationConfig
.
ThinkingConfig
=
&
GeminiThinkingConfig
{
ThinkingBudget
:
common
.
GetPointer
(
0
),
...
...
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