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
2df604bb
authored
Mar 02, 2026
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: default empty input_json_delta arguments to {} for tool call parsing
parent
da116177
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletions
+45
-1
relay/channel/claude/relay-claude.go
+7
-1
relay/channel/claude/relay_claude_test.go
+38
-0
No files found.
relay/channel/claude/relay-claude.go
View file @
2df604bb
...
...
@@ -451,11 +451,17 @@ func StreamResponseClaude2OpenAI(claudeResponse *dto.ClaudeResponse) *dto.ChatCo
choice
.
Delta
.
Content
=
claudeResponse
.
Delta
.
Text
switch
claudeResponse
.
Delta
.
Type
{
case
"input_json_delta"
:
arguments
:=
"{}"
if
claudeResponse
.
Delta
.
PartialJson
!=
nil
{
if
partial
:=
strings
.
TrimSpace
(
*
claudeResponse
.
Delta
.
PartialJson
);
partial
!=
""
{
arguments
=
partial
}
}
tools
=
append
(
tools
,
dto
.
ToolCallResponse
{
Type
:
"function"
,
Index
:
common
.
GetPointer
(
fcIdx
),
Function
:
dto
.
FunctionResponse
{
Arguments
:
*
claudeResponse
.
Delta
.
PartialJson
,
Arguments
:
arguments
,
},
})
case
"signature_delta"
:
...
...
relay/channel/claude/relay_claude_test.go
View file @
2df604bb
...
...
@@ -215,3 +215,41 @@ func TestRequestOpenAI2ClaudeMessage_AssistantToolCallWithMalformedArguments(t *
require
.
True
(
t
,
ok
)
assert
.
Empty
(
t
,
inputObj
)
}
func
TestStreamResponseClaude2OpenAI_EmptyInputJSONDeltaFallback
(
t
*
testing
.
T
)
{
empty
:=
""
resp
:=
&
dto
.
ClaudeResponse
{
Type
:
"content_block_delta"
,
Index
:
func
()
*
int
{
v
:=
1
;
return
&
v
}(),
Delta
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"input_json_delta"
,
PartialJson
:
&
empty
,
},
}
chunk
:=
StreamResponseClaude2OpenAI
(
resp
)
require
.
NotNil
(
t
,
chunk
)
require
.
Len
(
t
,
chunk
.
Choices
,
1
)
require
.
NotNil
(
t
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
)
require
.
Len
(
t
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
,
1
)
assert
.
Equal
(
t
,
"{}"
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
[
0
]
.
Function
.
Arguments
)
}
func
TestStreamResponseClaude2OpenAI_NonEmptyInputJSONDeltaPreserved
(
t
*
testing
.
T
)
{
partial
:=
`{"timezone":"Asia/Shanghai"}`
resp
:=
&
dto
.
ClaudeResponse
{
Type
:
"content_block_delta"
,
Index
:
func
()
*
int
{
v
:=
1
;
return
&
v
}(),
Delta
:
&
dto
.
ClaudeMediaMessage
{
Type
:
"input_json_delta"
,
PartialJson
:
&
partial
,
},
}
chunk
:=
StreamResponseClaude2OpenAI
(
resp
)
require
.
NotNil
(
t
,
chunk
)
require
.
Len
(
t
,
chunk
.
Choices
,
1
)
require
.
NotNil
(
t
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
)
require
.
Len
(
t
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
,
1
)
assert
.
Equal
(
t
,
partial
,
chunk
.
Choices
[
0
]
.
Delta
.
ToolCalls
[
0
]
.
Function
.
Arguments
)
}
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