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
660b129b
authored
Aug 08, 2025
by
HynoR
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: sync gpt-5 model ratio and support new reasoning effort
parent
85032b3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
19 deletions
+31
-19
relay/channel/openai/adaptor.go
+27
-19
setting/ratio_setting/model_ratio.go
+4
-0
No files found.
relay/channel/openai/adaptor.go
View file @
660b129b
...
@@ -35,6 +35,21 @@ type Adaptor struct {
...
@@ -35,6 +35,21 @@ type Adaptor struct {
ResponseFormat
string
ResponseFormat
string
}
}
// parseReasoningEffortFromModelSuffix 从模型名称中解析推理级别
// support OAI models: o1-mini/o3-mini/o4-mini/o1/o3 etc...
// minimal effort only available in gpt-5
func
parseReasoningEffortFromModelSuffix
(
model
string
)
(
string
,
string
)
{
effortSuffixes
:=
[]
string
{
"-high"
,
"-minimal"
,
"-low"
,
"-medium"
}
for
_
,
suffix
:=
range
effortSuffixes
{
if
strings
.
HasSuffix
(
model
,
suffix
)
{
effort
:=
strings
.
TrimPrefix
(
suffix
,
"-"
)
originModel
:=
strings
.
TrimSuffix
(
model
,
suffix
)
return
effort
,
originModel
}
}
return
""
,
model
}
func
(
a
*
Adaptor
)
ConvertGeminiRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
*
dto
.
GeminiChatRequest
)
(
any
,
error
)
{
func
(
a
*
Adaptor
)
ConvertGeminiRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
*
dto
.
GeminiChatRequest
)
(
any
,
error
)
{
// 使用 service.GeminiToOpenAIRequest 转换请求格式
// 使用 service.GeminiToOpenAIRequest 转换请求格式
openaiRequest
,
err
:=
service
.
GeminiToOpenAIRequest
(
request
,
info
)
openaiRequest
,
err
:=
service
.
GeminiToOpenAIRequest
(
request
,
info
)
...
@@ -197,16 +212,14 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -197,16 +212,14 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
request
.
MaxTokens
=
0
request
.
MaxTokens
=
0
}
}
request
.
Temperature
=
nil
request
.
Temperature
=
nil
if
strings
.
HasSuffix
(
request
.
Model
,
"-high"
)
{
request
.
ReasoningEffort
=
"high"
// 转换模型推理力度后缀
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-high"
)
effort
,
originModel
:=
parseReasoningEffortFromModelSuffix
(
request
.
Model
)
}
else
if
strings
.
HasSuffix
(
request
.
Model
,
"-low"
)
{
if
effort
!=
""
{
request
.
ReasoningEffort
=
"low"
request
.
ReasoningEffort
=
effort
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-low"
)
request
.
Model
=
originModel
}
else
if
strings
.
HasSuffix
(
request
.
Model
,
"-medium"
)
{
request
.
ReasoningEffort
=
"medium"
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-medium"
)
}
}
info
.
ReasoningEffort
=
request
.
ReasoningEffort
info
.
ReasoningEffort
=
request
.
ReasoningEffort
info
.
UpstreamModelName
=
request
.
Model
info
.
UpstreamModelName
=
request
.
Model
...
@@ -423,16 +436,11 @@ func detectImageMimeType(filename string) string {
...
@@ -423,16 +436,11 @@ func detectImageMimeType(filename string) string {
}
}
func
(
a
*
Adaptor
)
ConvertOpenAIResponsesRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
OpenAIResponsesRequest
)
(
any
,
error
)
{
func
(
a
*
Adaptor
)
ConvertOpenAIResponsesRequest
(
c
*
gin
.
Context
,
info
*
relaycommon
.
RelayInfo
,
request
dto
.
OpenAIResponsesRequest
)
(
any
,
error
)
{
// 模型后缀转换 reasoning effort
// 转换模型推理力度后缀
if
strings
.
HasSuffix
(
request
.
Model
,
"-high"
)
{
effort
,
originModel
:=
parseReasoningEffortFromModelSuffix
(
request
.
Model
)
request
.
Reasoning
.
Effort
=
"high"
if
effort
!=
""
{
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-high"
)
request
.
Reasoning
.
Effort
=
effort
}
else
if
strings
.
HasSuffix
(
request
.
Model
,
"-low"
)
{
request
.
Model
=
originModel
request
.
Reasoning
.
Effort
=
"low"
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-low"
)
}
else
if
strings
.
HasSuffix
(
request
.
Model
,
"-medium"
)
{
request
.
Reasoning
.
Effort
=
"medium"
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-medium"
)
}
}
return
request
,
nil
return
request
,
nil
}
}
...
...
setting/ratio_setting/model_ratio.go
View file @
660b129b
...
@@ -449,6 +449,10 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) {
...
@@ -449,6 +449,10 @@ func getHardcodedCompletionModelRatio(name string) (float64, bool) {
}
}
return
4
,
true
return
4
,
true
}
}
// gpt-5 匹配
if
strings
.
HasPrefix
(
name
,
"gpt-5"
)
{
return
8
,
true
}
// gpt-4.5-preview匹配
// gpt-4.5-preview匹配
if
strings
.
HasPrefix
(
name
,
"gpt-4.5-preview"
)
{
if
strings
.
HasPrefix
(
name
,
"gpt-4.5-preview"
)
{
return
2
,
true
return
2
,
true
...
...
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