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
246c3fa4
authored
Dec 06, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add gemini tool_calls finish reason
parent
6cc34fba
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
21 additions
and
15 deletions
+21
-15
constant/finish_reason.go
+6
-0
relay/channel/baidu/relay-baidu.go
+2
-2
relay/channel/gemini/relay-gemini.go
+4
-2
relay/channel/palm/relay-palm.go
+2
-2
relay/channel/tencent/relay-tencent.go
+2
-2
relay/channel/xunfei/relay-xunfei.go
+3
-3
relay/channel/zhipu/relay-zhipu.go
+2
-2
relay/common/relay_utils.go
+0
-2
No files found.
constant/finish_reason.go
0 → 100644
View file @
246c3fa4
package
constant
var
(
FinishReasonStop
=
"stop"
FinishReasonToolCalls
=
"tool_calls"
)
relay/channel/baidu/relay-baidu.go
View file @
246c3fa4
...
...
@@ -9,8 +9,8 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
"strings"
"sync"
...
...
@@ -75,7 +75,7 @@ func streamResponseBaidu2OpenAI(baiduResponse *BaiduChatStreamResponse) *dto.Cha
var
choice
dto
.
ChatCompletionsStreamResponseChoice
choice
.
Delta
.
SetContentString
(
baiduResponse
.
Result
)
if
baiduResponse
.
IsEnd
{
choice
.
FinishReason
=
&
relaycommon
.
StopFinishReason
choice
.
FinishReason
=
&
constant
.
FinishReasonStop
}
response
:=
dto
.
ChatCompletionsStreamResponse
{
Id
:
baiduResponse
.
Id
,
...
...
relay/channel/gemini/relay-gemini.go
View file @
246c3fa4
...
...
@@ -8,6 +8,7 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
...
...
@@ -186,10 +187,11 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
Role
:
"assistant"
,
Content
:
content
,
},
FinishReason
:
relaycommon
.
StopFinishReason
,
FinishReason
:
constant
.
FinishReasonStop
,
}
if
len
(
candidate
.
Content
.
Parts
)
>
0
{
if
candidate
.
Content
.
Parts
[
0
]
.
FunctionCall
!=
nil
{
choice
.
FinishReason
=
constant
.
FinishReasonToolCalls
choice
.
Message
.
ToolCalls
=
getToolCalls
(
&
candidate
)
}
else
{
choice
.
Message
.
SetStringContent
(
candidate
.
Content
.
Parts
[
0
]
.
Text
)
...
...
@@ -262,7 +264,7 @@ func GeminiChatStreamHandler(c *gin.Context, resp *http.Response, info *relaycom
}
}
response
:=
service
.
GenerateStopResponse
(
id
,
createAt
,
info
.
UpstreamModelName
,
relaycommon
.
StopFinishReason
)
response
:=
service
.
GenerateStopResponse
(
id
,
createAt
,
info
.
UpstreamModelName
,
constant
.
FinishReasonStop
)
service
.
ObjectData
(
c
,
response
)
usage
.
TotalTokens
=
usage
.
PromptTokens
+
usage
.
CompletionTokens
...
...
relay/channel/palm/relay-palm.go
View file @
246c3fa4
...
...
@@ -7,8 +7,8 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
)
...
...
@@ -63,7 +63,7 @@ func streamResponsePaLM2OpenAI(palmResponse *PaLMChatResponse) *dto.ChatCompleti
if
len
(
palmResponse
.
Candidates
)
>
0
{
choice
.
Delta
.
SetContentString
(
palmResponse
.
Candidates
[
0
]
.
Content
)
}
choice
.
FinishReason
=
&
relaycommon
.
StopFinishReason
choice
.
FinishReason
=
&
constant
.
FinishReasonStop
var
response
dto
.
ChatCompletionsStreamResponse
response
.
Object
=
"chat.completion.chunk"
response
.
Model
=
"palm2"
...
...
relay/channel/tencent/relay-tencent.go
View file @
246c3fa4
...
...
@@ -12,8 +12,8 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
"strconv"
"strings"
...
...
@@ -81,7 +81,7 @@ func streamResponseTencent2OpenAI(TencentResponse *TencentChatResponse) *dto.Cha
var
choice
dto
.
ChatCompletionsStreamResponseChoice
choice
.
Delta
.
SetContentString
(
TencentResponse
.
Choices
[
0
]
.
Delta
.
Content
)
if
TencentResponse
.
Choices
[
0
]
.
FinishReason
==
"stop"
{
choice
.
FinishReason
=
&
relaycommon
.
StopFinishReason
choice
.
FinishReason
=
&
constant
.
FinishReasonStop
}
response
.
Choices
=
append
(
response
.
Choices
,
choice
)
}
...
...
relay/channel/xunfei/relay-xunfei.go
View file @
246c3fa4
...
...
@@ -12,8 +12,8 @@ import (
"net/http"
"net/url"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
"strings"
"time"
...
...
@@ -67,7 +67,7 @@ func responseXunfei2OpenAI(response *XunfeiChatResponse) *dto.OpenAITextResponse
Role
:
"assistant"
,
Content
:
content
,
},
FinishReason
:
relaycommon
.
StopFinishReason
,
FinishReason
:
constant
.
FinishReasonStop
,
}
fullTextResponse
:=
dto
.
OpenAITextResponse
{
Object
:
"chat.completion"
,
...
...
@@ -89,7 +89,7 @@ func streamResponseXunfei2OpenAI(xunfeiResponse *XunfeiChatResponse) *dto.ChatCo
var
choice
dto
.
ChatCompletionsStreamResponseChoice
choice
.
Delta
.
SetContentString
(
xunfeiResponse
.
Payload
.
Choices
.
Text
[
0
]
.
Content
)
if
xunfeiResponse
.
Payload
.
Choices
.
Status
==
2
{
choice
.
FinishReason
=
&
relaycommon
.
StopFinishReason
choice
.
FinishReason
=
&
constant
.
FinishReasonStop
}
response
:=
dto
.
ChatCompletionsStreamResponse
{
Object
:
"chat.completion.chunk"
,
...
...
relay/channel/zhipu/relay-zhipu.go
View file @
246c3fa4
...
...
@@ -8,8 +8,8 @@ import (
"io"
"net/http"
"one-api/common"
"one-api/constant"
"one-api/dto"
relaycommon
"one-api/relay/common"
"one-api/service"
"strings"
"sync"
...
...
@@ -139,7 +139,7 @@ func streamResponseZhipu2OpenAI(zhipuResponse string) *dto.ChatCompletionsStream
func
streamMetaResponseZhipu2OpenAI
(
zhipuResponse
*
ZhipuStreamMetaResponse
)
(
*
dto
.
ChatCompletionsStreamResponse
,
*
dto
.
Usage
)
{
var
choice
dto
.
ChatCompletionsStreamResponseChoice
choice
.
Delta
.
SetContentString
(
""
)
choice
.
FinishReason
=
&
relaycommon
.
StopFinishReason
choice
.
FinishReason
=
&
constant
.
FinishReasonStop
response
:=
dto
.
ChatCompletionsStreamResponse
{
Id
:
zhipuResponse
.
RequestId
,
Object
:
"chat.completion.chunk"
,
...
...
relay/common/relay_utils.go
View file @
246c3fa4
...
...
@@ -10,8 +10,6 @@ import (
"strings"
)
var
StopFinishReason
=
"stop"
func
GetFullRequestURL
(
baseURL
string
,
requestURL
string
,
channelType
int
)
string
{
fullRequestURL
:=
fmt
.
Sprintf
(
"%s%s"
,
baseURL
,
requestURL
)
...
...
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