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
cd1d43ae
authored
Mar 05, 2026
by
Seefs
Committed by
GitHub
Mar 05, 2026
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3120 from nekohy/main
feats: repair the thinking of claude to openrouter convert
parents
5bd67d0a
1b179862
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
3 deletions
+31
-3
dto/claude.go
+14
-0
relay/channel/openai/adaptor.go
+1
-0
relay/channel/openrouter/dto.go
+1
-0
service/convert.go
+15
-3
No files found.
dto/claude.go
View file @
cd1d43ae
...
@@ -218,6 +218,11 @@ type ClaudeRequest struct {
...
@@ -218,6 +218,11 @@ type ClaudeRequest struct {
ServiceTier
string
`json:"service_tier,omitempty"`
ServiceTier
string
`json:"service_tier,omitempty"`
}
}
// OutputConfigForEffort just for extract effort
type
OutputConfigForEffort
struct
{
Effort
string
`json:"effort,omitempty"`
}
// createClaudeFileSource 根据数据内容创建正确类型的 FileSource
// createClaudeFileSource 根据数据内容创建正确类型的 FileSource
func
createClaudeFileSource
(
data
string
)
*
types
.
FileSource
{
func
createClaudeFileSource
(
data
string
)
*
types
.
FileSource
{
if
strings
.
HasPrefix
(
data
,
"http://"
)
||
strings
.
HasPrefix
(
data
,
"https://"
)
{
if
strings
.
HasPrefix
(
data
,
"http://"
)
||
strings
.
HasPrefix
(
data
,
"https://"
)
{
...
@@ -409,6 +414,15 @@ func (c *ClaudeRequest) GetTools() []any {
...
@@ -409,6 +414,15 @@ func (c *ClaudeRequest) GetTools() []any {
}
}
}
}
func
(
c
*
ClaudeRequest
)
GetEfforts
()
string
{
var
OutputConfig
OutputConfigForEffort
if
err
:=
json
.
Unmarshal
(
c
.
OutputConfig
,
&
OutputConfig
);
err
==
nil
{
effort
:=
OutputConfig
.
Effort
return
effort
}
return
""
}
// ProcessTools 处理工具列表,支持类型断言
// ProcessTools 处理工具列表,支持类型断言
func
ProcessTools
(
tools
[]
any
)
([]
*
Tool
,
[]
*
ClaudeWebSearchTool
)
{
func
ProcessTools
(
tools
[]
any
)
([]
*
Tool
,
[]
*
ClaudeWebSearchTool
)
{
var
normalTools
[]
*
Tool
var
normalTools
[]
*
Tool
...
...
relay/channel/openai/adaptor.go
View file @
cd1d43ae
...
@@ -298,6 +298,7 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -298,6 +298,7 @@ func (a *Adaptor) ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayIn
}
}
reasoning
:=
openrouter
.
RequestReasoning
{
reasoning
:=
openrouter
.
RequestReasoning
{
Enabled
:
true
,
MaxTokens
:
*
thinking
.
BudgetTokens
,
MaxTokens
:
*
thinking
.
BudgetTokens
,
}
}
...
...
relay/channel/openrouter/dto.go
View file @
cd1d43ae
...
@@ -3,6 +3,7 @@ package openrouter
...
@@ -3,6 +3,7 @@ package openrouter
import
"encoding/json"
import
"encoding/json"
type
RequestReasoning
struct
{
type
RequestReasoning
struct
{
Enabled
bool
`json:"enabled"`
// One of the following (not both):
// One of the following (not both):
Effort
string
`json:"effort,omitempty"`
// Can be "high", "medium", or "low" (OpenAI-style)
Effort
string
`json:"effort,omitempty"`
// Can be "high", "medium", or "low" (OpenAI-style)
MaxTokens
int
`json:"max_tokens,omitempty"`
// Specific token limit (Anthropic-style)
MaxTokens
int
`json:"max_tokens,omitempty"`
// Specific token limit (Anthropic-style)
...
...
service/convert.go
View file @
cd1d43ae
...
@@ -34,16 +34,29 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
...
@@ -34,16 +34,29 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
isOpenRouter
:=
info
.
ChannelType
==
constant
.
ChannelTypeOpenRouter
isOpenRouter
:=
info
.
ChannelType
==
constant
.
ChannelTypeOpenRouter
if
claudeRequest
.
Thinking
!=
nil
&&
claudeRequest
.
Thinking
.
Type
==
"enabled"
{
if
isOpenRouter
{
if
isOpenRouter
{
reasoning
:=
openrouter
.
RequestReasoning
{
if
effort
:=
claudeRequest
.
GetEfforts
();
effort
!=
""
{
effortBytes
,
_
:=
json
.
Marshal
(
effort
)
openAIRequest
.
Verbosity
=
effortBytes
}
if
claudeRequest
.
Thinking
!=
nil
{
var
reasoning
openrouter
.
RequestReasoning
if
claudeRequest
.
Thinking
.
Type
==
"enabled"
{
reasoning
=
openrouter
.
RequestReasoning
{
Enabled
:
true
,
MaxTokens
:
claudeRequest
.
Thinking
.
GetBudgetTokens
(),
MaxTokens
:
claudeRequest
.
Thinking
.
GetBudgetTokens
(),
}
}
}
else
if
claudeRequest
.
Thinking
.
Type
==
"adaptive"
{
reasoning
=
openrouter
.
RequestReasoning
{
Enabled
:
true
,
}
}
reasoningJSON
,
err
:=
json
.
Marshal
(
reasoning
)
reasoningJSON
,
err
:=
json
.
Marshal
(
reasoning
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to marshal reasoning: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to marshal reasoning: %w"
,
err
)
}
}
openAIRequest
.
Reasoning
=
reasoningJSON
openAIRequest
.
Reasoning
=
reasoningJSON
}
}
else
{
}
else
{
thinkingSuffix
:=
"-thinking"
thinkingSuffix
:=
"-thinking"
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
thinkingSuffix
)
&&
if
strings
.
HasSuffix
(
info
.
OriginModelName
,
thinkingSuffix
)
&&
...
@@ -51,7 +64,6 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
...
@@ -51,7 +64,6 @@ func ClaudeToOpenAIRequest(claudeRequest dto.ClaudeRequest, info *relaycommon.Re
openAIRequest
.
Model
=
openAIRequest
.
Model
+
thinkingSuffix
openAIRequest
.
Model
=
openAIRequest
.
Model
+
thinkingSuffix
}
}
}
}
}
// Convert stop sequences
// Convert stop sequences
if
len
(
claudeRequest
.
StopSequences
)
==
1
{
if
len
(
claudeRequest
.
StopSequences
)
==
1
{
...
...
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