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
ae8b8b34
authored
Oct 13, 2025
by
Seefs
Committed by
GitHub
Oct 13, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2035 from Inblac/devpre
fix(convert): 修复 OpenAI 转 Claude 流时 thinking 块的格式问题
parents
f6bf150d
b6f35273
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
9 deletions
+12
-9
dto/claude.go
+1
-1
relay/channel/claude/relay-claude.go
+9
-6
service/convert.go
+2
-2
No files found.
dto/claude.go
View file @
ae8b8b34
...
...
@@ -24,7 +24,7 @@ type ClaudeMediaMessage struct {
StopReason
*
string
`json:"stop_reason,omitempty"`
PartialJson
*
string
`json:"partial_json,omitempty"`
Role
string
`json:"role,omitempty"`
Thinking
string
`json:"thinking,omitempty"`
Thinking
*
string
`json:"thinking,omitempty"`
Signature
string
`json:"signature,omitempty"`
Delta
string
`json:"delta,omitempty"`
CacheControl
json
.
RawMessage
`json:"cache_control,omitempty"`
...
...
relay/channel/claude/relay-claude.go
View file @
ae8b8b34
...
...
@@ -477,8 +477,7 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *dto.ClaudeResponse
signatureContent
:=
"
\n
"
choice
.
Delta
.
ReasoningContent
=
&
signatureContent
case
"thinking_delta"
:
thinkingContent
:=
claudeResponse
.
Delta
.
Thinking
choice
.
Delta
.
ReasoningContent
=
&
thinkingContent
choice
.
Delta
.
ReasoningContent
=
claudeResponse
.
Delta
.
Thinking
}
}
}
else
if
claudeResponse
.
Type
==
"message_delta"
{
...
...
@@ -513,7 +512,9 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *dto.ClaudeResponse) *dto
var
responseThinking
string
if
len
(
claudeResponse
.
Content
)
>
0
{
responseText
=
claudeResponse
.
Content
[
0
]
.
GetText
()
responseThinking
=
claudeResponse
.
Content
[
0
]
.
Thinking
if
claudeResponse
.
Content
[
0
]
.
Thinking
!=
nil
{
responseThinking
=
*
claudeResponse
.
Content
[
0
]
.
Thinking
}
}
tools
:=
make
([]
dto
.
ToolCallResponse
,
0
)
thinkingContent
:=
""
...
...
@@ -545,7 +546,9 @@ func ResponseClaude2OpenAI(reqMode int, claudeResponse *dto.ClaudeResponse) *dto
})
case
"thinking"
:
// 加密的不管, 只输出明文的推理过程
thinkingContent
=
message
.
Thinking
if
message
.
Thinking
!=
nil
{
thinkingContent
=
*
message
.
Thinking
}
case
"text"
:
responseText
=
message
.
GetText
()
}
...
...
@@ -598,8 +601,8 @@ func FormatClaudeResponseInfo(requestMode int, claudeResponse *dto.ClaudeRespons
if
claudeResponse
.
Delta
.
Text
!=
nil
{
claudeInfo
.
ResponseText
.
WriteString
(
*
claudeResponse
.
Delta
.
Text
)
}
if
claudeResponse
.
Delta
.
Thinking
!=
""
{
claudeInfo
.
ResponseText
.
WriteString
(
claudeResponse
.
Delta
.
Thinking
)
if
claudeResponse
.
Delta
.
Thinking
!=
nil
{
claudeInfo
.
ResponseText
.
WriteString
(
*
claudeResponse
.
Delta
.
Thinking
)
}
}
else
if
claudeResponse
.
Type
==
"message_delta"
{
// 最终的usage获取
...
...
service/convert.go
View file @
ae8b8b34
...
...
@@ -352,7 +352,7 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
Type
:
"content_block_start"
,
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"thinking"
,
Thinking
:
""
,
Thinking
:
common
.
GetPointer
[
string
](
""
)
,
},
})
}
...
...
@@ -360,7 +360,7 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
// text delta
claudeResponse
.
Delta
=
&
dto
.
ClaudeMediaMessage
{
Type
:
"thinking_delta"
,
Thinking
:
reasoning
,
Thinking
:
&
reasoning
,
}
}
else
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
!=
relaycommon
.
LastMessageTypeText
{
...
...
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