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
b364e9e3
authored
Apr 17, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: simplify model prefix checks and update message role for o-series models
parent
45e8e04d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
11 deletions
+11
-11
controller/channel-test.go
+1
-1
relay/channel/openai/adaptor.go
+9
-9
service/token_counter.go
+1
-1
No files found.
controller/channel-test.go
View file @
b364e9e3
...
...
@@ -186,7 +186,7 @@ func buildTestRequest(model string) *dto.GeneralOpenAIRequest {
return
testRequest
}
// 并非Embedding 模型
if
strings
.
HasPrefix
(
model
,
"o
1"
)
||
strings
.
HasPrefix
(
model
,
"o3
"
)
{
if
strings
.
HasPrefix
(
model
,
"o"
)
{
testRequest
.
MaxCompletionTokens
=
10
}
else
if
strings
.
Contains
(
model
,
"thinking"
)
{
if
!
strings
.
Contains
(
model
,
"claude"
)
{
...
...
relay/channel/openai/adaptor.go
View file @
b364e9e3
...
...
@@ -147,14 +147,12 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
if
info
.
ChannelType
!=
common
.
ChannelTypeOpenAI
&&
info
.
ChannelType
!=
common
.
ChannelTypeAzure
{
request
.
StreamOptions
=
nil
}
if
strings
.
HasPrefix
(
request
.
Model
,
"o
1"
)
||
strings
.
HasPrefix
(
request
.
Model
,
"o3
"
)
{
if
strings
.
HasPrefix
(
request
.
Model
,
"o"
)
{
if
request
.
MaxCompletionTokens
==
0
&&
request
.
MaxTokens
!=
0
{
request
.
MaxCompletionTokens
=
request
.
MaxTokens
request
.
MaxTokens
=
0
}
if
strings
.
HasPrefix
(
request
.
Model
,
"o3"
)
||
strings
.
HasPrefix
(
request
.
Model
,
"o1"
)
{
request
.
Temperature
=
nil
}
request
.
Temperature
=
nil
if
strings
.
HasSuffix
(
request
.
Model
,
"-high"
)
{
request
.
ReasoningEffort
=
"high"
request
.
Model
=
strings
.
TrimSuffix
(
request
.
Model
,
"-high"
)
...
...
@@ -167,11 +165,13 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
}
info
.
ReasoningEffort
=
request
.
ReasoningEffort
info
.
UpstreamModelName
=
request
.
Model
}
if
request
.
Model
==
"o1"
||
request
.
Model
==
"o1-2024-12-17"
||
strings
.
HasPrefix
(
request
.
Model
,
"o3"
)
{
//修改第一个Message的内容,将system改为developer
if
len
(
request
.
Messages
)
>
0
&&
request
.
Messages
[
0
]
.
Role
==
"system"
{
request
.
Messages
[
0
]
.
Role
=
"developer"
// o系列模型developer适配(o1-mini除外)
if
!
strings
.
HasPrefix
(
request
.
Model
,
"o1-mini"
)
{
//修改第一个Message的内容,将system改为developer
if
len
(
request
.
Messages
)
>
0
&&
request
.
Messages
[
0
]
.
Role
==
"system"
{
request
.
Messages
[
0
]
.
Role
=
"developer"
}
}
}
...
...
service/token_counter.go
View file @
b364e9e3
...
...
@@ -43,7 +43,7 @@ func InitTokenEncoders() {
}
else
{
tokenEncoderMap
[
model
]
=
defaultTokenEncoder
}
}
else
if
strings
.
HasPrefix
(
model
,
"o
1
"
)
{
}
else
if
strings
.
HasPrefix
(
model
,
"o"
)
{
tokenEncoderMap
[
model
]
=
o200kTokenEncoder
}
else
{
tokenEncoderMap
[
model
]
=
defaultTokenEncoder
...
...
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