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
23de62ec
authored
Feb 26, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: claude tool call format #795 #766
parent
c3b0e57e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
8 deletions
+14
-8
dto/openai_response.go
+1
-1
relay/channel/gemini/relay-gemini.go
+7
-7
relay/constant/api_type.go
+3
-0
relay/relay_adaptor.go
+3
-0
No files found.
dto/openai_response.go
View file @
23de62ec
...
...
@@ -107,7 +107,7 @@ type FunctionCall struct {
Name
string
`json:"name,omitempty"`
// call function with arguments in JSON format
Parameters
any
`json:"parameters,omitempty"`
// request
Arguments
string
`json:"arguments
,omitempty
"`
Arguments
string
`json:"arguments"`
}
type
ChatCompletionsStreamResponse
struct
{
...
...
relay/channel/gemini/relay-gemini.go
View file @
23de62ec
...
...
@@ -368,7 +368,7 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
Choices
:
make
([]
dto
.
OpenAITextResponseChoice
,
0
,
len
(
response
.
Candidates
)),
}
content
,
_
:=
json
.
Marshal
(
""
)
is
_tool_c
all
:=
false
is
ToolC
all
:=
false
for
_
,
candidate
:=
range
response
.
Candidates
{
choice
:=
dto
.
OpenAITextResponseChoice
{
Index
:
int
(
candidate
.
Index
),
...
...
@@ -380,12 +380,12 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
}
if
len
(
candidate
.
Content
.
Parts
)
>
0
{
var
texts
[]
string
var
tool
_c
alls
[]
dto
.
ToolCall
var
tool
C
alls
[]
dto
.
ToolCall
for
_
,
part
:=
range
candidate
.
Content
.
Parts
{
if
part
.
FunctionCall
!=
nil
{
choice
.
FinishReason
=
constant
.
FinishReasonToolCalls
if
call
:=
getToolCall
(
&
part
);
call
!=
nil
{
tool
_calls
=
append
(
tool_c
alls
,
*
call
)
tool
Calls
=
append
(
toolC
alls
,
*
call
)
}
}
else
{
if
part
.
ExecutableCode
!=
nil
{
...
...
@@ -400,9 +400,9 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
}
}
}
if
len
(
tool
_c
alls
)
>
0
{
choice
.
Message
.
SetToolCalls
(
tool
_c
alls
)
is
_tool_c
all
=
true
if
len
(
tool
C
alls
)
>
0
{
choice
.
Message
.
SetToolCalls
(
tool
C
alls
)
is
ToolC
all
=
true
}
choice
.
Message
.
SetStringContent
(
strings
.
Join
(
texts
,
"
\n
"
))
...
...
@@ -418,7 +418,7 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
choice
.
FinishReason
=
constant
.
FinishReasonContentFilter
}
}
if
is
_tool_c
all
{
if
is
ToolC
all
{
choice
.
FinishReason
=
constant
.
FinishReasonToolCalls
}
...
...
relay/constant/api_type.go
View file @
23de62ec
...
...
@@ -30,6 +30,7 @@ const (
APITypeMokaAI
APITypeVolcEngine
APITypeBaiduV2
APITypeOpenRouter
APITypeDummy
// this one is only for count, do not add any channel after this
)
...
...
@@ -86,6 +87,8 @@ func ChannelType2APIType(channelType int) (int, bool) {
apiType
=
APITypeVolcEngine
case
common
.
ChannelTypeBaiduV2
:
apiType
=
APITypeBaiduV2
case
common
.
ChannelTypeOpenRouter
:
apiType
=
APITypeOpenRouter
}
if
apiType
==
-
1
{
return
APITypeOpenAI
,
false
...
...
relay/relay_adaptor.go
View file @
23de62ec
...
...
@@ -18,6 +18,7 @@ import (
"one-api/relay/channel/mokaai"
"one-api/relay/channel/ollama"
"one-api/relay/channel/openai"
"one-api/relay/channel/openrouter"
"one-api/relay/channel/palm"
"one-api/relay/channel/perplexity"
"one-api/relay/channel/siliconflow"
...
...
@@ -83,6 +84,8 @@ func GetAdaptor(apiType int) channel.Adaptor {
return
&
volcengine
.
Adaptor
{}
case
constant
.
APITypeBaiduV2
:
return
&
baidu_v2
.
Adaptor
{}
case
constant
.
APITypeOpenRouter
:
return
&
openrouter
.
Adaptor
{}
}
return
nil
}
...
...
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