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
574ee8a2
authored
Feb 05, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Claude stream block index/type transitions
parent
eaee7a99
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
+27
-8
service/convert.go
+27
-8
No files found.
service/convert.go
View file @
574ee8a2
...
@@ -252,8 +252,9 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -252,8 +252,9 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
claudeResponses
=
append
(
claudeResponses
,
resp
)
claudeResponses
=
append
(
claudeResponses
,
resp
)
// 首块包含工具 delta,则追加 input_json_delta
// 首块包含工具 delta,则追加 input_json_delta
if
toolCall
.
Function
.
Arguments
!=
""
{
if
toolCall
.
Function
.
Arguments
!=
""
{
idx
:=
0
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Inde
x
,
Index
:
&
i
d
x
,
Type
:
"content_block_delta"
,
Type
:
"content_block_delta"
,
Delta
:
&
dto
.
ClaudeMediaMessage
{
Delta
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"input_json_delta"
,
Type
:
"input_json_delta"
,
...
@@ -270,16 +271,22 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -270,16 +271,22 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
content
:=
openAIResponse
.
Choices
[
0
]
.
Delta
.
GetContentString
()
content
:=
openAIResponse
.
Choices
[
0
]
.
Delta
.
GetContentString
()
if
reasoning
!=
""
{
if
reasoning
!=
""
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeTools
||
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeText
{
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
info
.
ClaudeConvertInfo
.
Index
++
}
idx
:=
info
.
ClaudeConvertInfo
.
Index
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Inde
x
,
Index
:
&
i
d
x
,
Type
:
"content_block_start"
,
Type
:
"content_block_start"
,
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"thinking"
,
Type
:
"thinking"
,
Thinking
:
common
.
GetPointer
[
string
](
""
),
Thinking
:
common
.
GetPointer
[
string
](
""
),
},
},
})
})
idx2
:=
idx
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Index
,
Index
:
&
i
dx2
,
Type
:
"content_block_delta"
,
Type
:
"content_block_delta"
,
Delta
:
&
dto
.
ClaudeMediaMessage
{
Delta
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"thinking_delta"
,
Type
:
"thinking_delta"
,
...
@@ -288,16 +295,22 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -288,16 +295,22 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
})
})
info
.
ClaudeConvertInfo
.
LastMessagesType
=
relaycommon
.
LastMessageTypeThinking
info
.
ClaudeConvertInfo
.
LastMessagesType
=
relaycommon
.
LastMessageTypeThinking
}
else
if
content
!=
""
{
}
else
if
content
!=
""
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeTools
||
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeThinking
{
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
info
.
ClaudeConvertInfo
.
Index
++
}
idx
:=
info
.
ClaudeConvertInfo
.
Index
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Inde
x
,
Index
:
&
i
d
x
,
Type
:
"content_block_start"
,
Type
:
"content_block_start"
,
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"text"
,
Type
:
"text"
,
Text
:
common
.
GetPointer
[
string
](
""
),
Text
:
common
.
GetPointer
[
string
](
""
),
},
},
})
})
idx2
:=
idx
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Index
,
Index
:
&
i
dx2
,
Type
:
"content_block_delta"
,
Type
:
"content_block_delta"
,
Delta
:
&
dto
.
ClaudeMediaMessage
{
Delta
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"text_delta"
,
Type
:
"text_delta"
,
...
@@ -422,8 +435,13 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -422,8 +435,13 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
if
reasoning
!=
""
||
textContent
!=
""
{
if
reasoning
!=
""
||
textContent
!=
""
{
if
reasoning
!=
""
{
if
reasoning
!=
""
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
!=
relaycommon
.
LastMessageTypeThinking
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
!=
relaycommon
.
LastMessageTypeThinking
{
if
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeText
||
info
.
ClaudeConvertInfo
.
LastMessagesType
==
relaycommon
.
LastMessageTypeTools
{
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
info
.
ClaudeConvertInfo
.
Index
++
}
idx
:=
info
.
ClaudeConvertInfo
.
Index
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Inde
x
,
Index
:
&
i
d
x
,
Type
:
"content_block_start"
,
Type
:
"content_block_start"
,
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"thinking"
,
Type
:
"thinking"
,
...
@@ -442,8 +460,9 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -442,8 +460,9 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
claudeResponses
=
append
(
claudeResponses
,
generateStopBlock
(
info
.
ClaudeConvertInfo
.
Index
))
info
.
ClaudeConvertInfo
.
Index
++
info
.
ClaudeConvertInfo
.
Index
++
}
}
idx
:=
info
.
ClaudeConvertInfo
.
Index
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
claudeResponses
=
append
(
claudeResponses
,
&
dto
.
ClaudeResponse
{
Index
:
&
i
nfo
.
ClaudeConvertInfo
.
Inde
x
,
Index
:
&
i
d
x
,
Type
:
"content_block_start"
,
Type
:
"content_block_start"
,
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
ContentBlock
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"text"
,
Type
:
"text"
,
...
@@ -462,7 +481,7 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
...
@@ -462,7 +481,7 @@ func StreamResponseOpenAI2Claude(openAIResponse *dto.ChatCompletionsStreamRespon
}
}
}
}
claudeResponse
.
Index
=
&
info
.
ClaudeConvertInfo
.
Index
claudeResponse
.
Index
=
common
.
GetPointer
[
int
](
info
.
ClaudeConvertInfo
.
Index
)
if
!
isEmpty
&&
claudeResponse
.
Delta
!=
nil
{
if
!
isEmpty
&&
claudeResponse
.
Delta
!=
nil
{
claudeResponses
=
append
(
claudeResponses
,
&
claudeResponse
)
claudeResponses
=
append
(
claudeResponses
,
&
claudeResponse
)
}
}
...
...
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