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
63e7fb69
authored
Aug 15, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/alpha' into alpha
parents
893104a1
30e46793
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
relay/channel/openai/adaptor.go
+35
-0
No files found.
relay/channel/openai/adaptor.go
View file @
63e7fb69
...
@@ -237,6 +237,8 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -237,6 +237,8 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
}
}
request
.
Reasoning
=
marshal
request
.
Reasoning
=
marshal
}
}
// 清空多余的ReasoningEffort
request
.
ReasoningEffort
=
""
}
else
{
}
else
{
if
len
(
request
.
Reasoning
)
==
0
{
if
len
(
request
.
Reasoning
)
==
0
{
// 适配 OpenAI 的 ReasoningEffort 格式
// 适配 OpenAI 的 ReasoningEffort 格式
...
@@ -254,7 +256,40 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -254,7 +256,40 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
}
}
}
}
}
}
request
.
ReasoningEffort
=
""
}
}
// https://docs.anthropic.com/en/api/openai-sdk#extended-thinking-support
// 没有做排除3.5Haiku等,要出问题再加吧,最佳兼容性(不是
if
request
.
THINKING
!=
nil
&&
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"anthropic"
)
{
var
thinking
dto
.
Thinking
// Claude标准Thinking格式
if
err
:=
json
.
Unmarshal
(
request
.
THINKING
,
&
thinking
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error Unmarshal thinking: %w"
,
err
)
}
// 只有当 thinking.Type 是 "enabled" 时才处理
if
thinking
.
Type
==
"enabled"
{
// 检查 BudgetTokens 是否为 nil
if
thinking
.
BudgetTokens
==
nil
{
return
nil
,
fmt
.
Errorf
(
"BudgetTokens is nil when thinking is enabled"
)
}
reasoning
:=
openrouter
.
RequestReasoning
{
MaxTokens
:
*
thinking
.
BudgetTokens
,
}
marshal
,
err
:=
common
.
Marshal
(
reasoning
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"error marshalling reasoning: %w"
,
err
)
}
request
.
Reasoning
=
marshal
}
// 清空 THINKING
request
.
THINKING
=
nil
}
}
}
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o"
)
||
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"gpt-5"
)
{
if
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"o"
)
||
strings
.
HasPrefix
(
info
.
UpstreamModelName
,
"gpt-5"
)
{
if
request
.
MaxCompletionTokens
==
0
&&
request
.
MaxTokens
!=
0
{
if
request
.
MaxCompletionTokens
==
0
&&
request
.
MaxTokens
!=
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