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
f69a4f71
authored
Aug 08, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enhance request handling to support tool calls and improve stream options
parent
e81113e4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
relay/channel/openai/adaptor.go
+1
-1
relay/channel/openai/relay-openai.go
+3
-0
service/convert.go
+10
-6
No files found.
relay/channel/openai/adaptor.go
View file @
f69a4f71
...
@@ -67,7 +67,7 @@ func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayIn
...
@@ -67,7 +67,7 @@ func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayIn
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
info
.
SupportStreamOptions
{
if
info
.
SupportStreamOptions
&&
info
.
IsStream
{
aiRequest
.
StreamOptions
=
&
dto
.
StreamOptions
{
aiRequest
.
StreamOptions
=
&
dto
.
StreamOptions
{
IncludeUsage
:
true
,
IncludeUsage
:
true
,
}
}
...
...
relay/channel/openai/relay-openai.go
View file @
f69a4f71
...
@@ -180,6 +180,9 @@ func OpenaiHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Respo
...
@@ -180,6 +180,9 @@ func OpenaiHandler(c *gin.Context, info *relaycommon.RelayInfo, resp *http.Respo
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
,
http
.
StatusInternalServerError
)
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeReadResponseBodyFailed
,
http
.
StatusInternalServerError
)
}
}
if
common
.
DebugEnabled
{
println
(
"upstream response body:"
,
string
(
responseBody
))
}
err
=
common
.
Unmarshal
(
responseBody
,
&
simpleResponse
)
err
=
common
.
Unmarshal
(
responseBody
,
&
simpleResponse
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeBadResponseBody
,
http
.
StatusInternalServerError
)
return
nil
,
types
.
NewOpenAIError
(
err
,
types
.
ErrorCodeBadResponseBody
,
http
.
StatusInternalServerError
)
...
...
service/convert.go
View file @
f69a4f71
...
@@ -401,23 +401,27 @@ func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relayco
...
@@ -401,23 +401,27 @@ func ResponseOpenAI2Claude(openAIResponse *dto.OpenAITextResponse, info *relayco
}
}
for
_
,
choice
:=
range
openAIResponse
.
Choices
{
for
_
,
choice
:=
range
openAIResponse
.
Choices
{
stopReason
=
stopReasonOpenAI2Claude
(
choice
.
FinishReason
)
stopReason
=
stopReasonOpenAI2Claude
(
choice
.
FinishReason
)
claudeContent
:=
dto
.
ClaudeMediaMessage
{}
if
choice
.
FinishReason
==
"tool_calls"
{
if
choice
.
FinishReason
==
"tool_calls"
{
for
_
,
toolUse
:=
range
choice
.
Message
.
ParseToolCalls
()
{
claudeContent
:=
dto
.
ClaudeMediaMessage
{}
claudeContent
.
Type
=
"tool_use"
claudeContent
.
Type
=
"tool_use"
claudeContent
.
Id
=
choice
.
Message
.
ToolCallId
claudeContent
.
Id
=
toolUse
.
ID
claudeContent
.
Name
=
choice
.
Message
.
ParseToolCalls
()[
0
]
.
Function
.
Name
claudeContent
.
Name
=
toolUse
.
Function
.
Name
var
mapParams
map
[
string
]
interface
{}
var
mapParams
map
[
string
]
interface
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
choice
.
Message
.
ParseToolCalls
()[
0
]
.
Function
.
Arguments
),
&
mapParams
);
err
==
nil
{
if
err
:=
common
.
Unmarshal
([]
byte
(
toolUse
.
Function
.
Arguments
),
&
mapParams
);
err
==
nil
{
claudeContent
.
Input
=
mapParams
claudeContent
.
Input
=
mapParams
}
else
{
}
else
{
claudeContent
.
Input
=
choice
.
Message
.
ParseToolCalls
()[
0
]
.
Function
.
Arguments
claudeContent
.
Input
=
toolUse
.
Function
.
Arguments
}
contents
=
append
(
contents
,
claudeContent
)
}
}
}
else
{
}
else
{
claudeContent
:=
dto
.
ClaudeMediaMessage
{}
claudeContent
.
Type
=
"text"
claudeContent
.
Type
=
"text"
claudeContent
.
SetText
(
choice
.
Message
.
StringContent
())
claudeContent
.
SetText
(
choice
.
Message
.
StringContent
())
}
contents
=
append
(
contents
,
claudeContent
)
contents
=
append
(
contents
,
claudeContent
)
}
}
}
claudeResponse
.
Content
=
contents
claudeResponse
.
Content
=
contents
claudeResponse
.
StopReason
=
stopReason
claudeResponse
.
StopReason
=
stopReason
claudeResponse
.
Usage
=
&
dto
.
ClaudeUsage
{
claudeResponse
.
Usage
=
&
dto
.
ClaudeUsage
{
...
...
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