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
8e3c5276
authored
Apr 26, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 规范claude返回格式
parent
483e1c46
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
8 deletions
+13
-8
dto/text_response.go
+8
-6
relay/channel/aws/relay-aws.go
+2
-0
relay/channel/claude/relay-claude.go
+2
-1
service/token_counter.go
+1
-1
No files found.
dto/text_response.go
View file @
8e3c5276
...
@@ -55,8 +55,9 @@ type OpenAIEmbeddingResponse struct {
...
@@ -55,8 +55,9 @@ type OpenAIEmbeddingResponse struct {
type
ChatCompletionsStreamResponseChoice
struct
{
type
ChatCompletionsStreamResponseChoice
struct
{
Delta
ChatCompletionsStreamResponseChoiceDelta
`json:"delta,omitempty"`
Delta
ChatCompletionsStreamResponseChoiceDelta
`json:"delta,omitempty"`
Logprobs
*
any
`json:"logprobs"`
FinishReason
*
string
`json:"finish_reason"`
FinishReason
*
string
`json:"finish_reason"`
Index
int
`json:"index
,omitempty
"`
Index
int
`json:"index"`
}
}
type
ChatCompletionsStreamResponseChoiceDelta
struct
{
type
ChatCompletionsStreamResponseChoiceDelta
struct
{
...
@@ -95,11 +96,12 @@ type FunctionCall struct {
...
@@ -95,11 +96,12 @@ type FunctionCall struct {
}
}
type
ChatCompletionsStreamResponse
struct
{
type
ChatCompletionsStreamResponse
struct
{
Id
string
`json:"id"`
Id
string
`json:"id"`
Object
string
`json:"object"`
Object
string
`json:"object"`
Created
int64
`json:"created"`
Created
int64
`json:"created"`
Model
string
`json:"model"`
Model
string
`json:"model"`
Choices
[]
ChatCompletionsStreamResponseChoice
`json:"choices"`
SystemFingerprint
*
string
`json:"system_fingerprint"`
Choices
[]
ChatCompletionsStreamResponseChoice
`json:"choices"`
}
}
type
ChatCompletionsStreamResponseSimple
struct
{
type
ChatCompletionsStreamResponseSimple
struct
{
...
...
relay/channel/aws/relay-aws.go
View file @
8e3c5276
...
@@ -156,6 +156,7 @@ func awsStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode i
...
@@ -156,6 +156,7 @@ func awsStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode i
var
usage
relaymodel
.
Usage
var
usage
relaymodel
.
Usage
var
id
string
var
id
string
var
model
string
var
model
string
createdTime
:=
common
.
GetTimestamp
()
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
c
.
Stream
(
func
(
w
io
.
Writer
)
bool
{
event
,
ok
:=
<-
stream
.
Events
()
event
,
ok
:=
<-
stream
.
Events
()
if
!
ok
{
if
!
ok
{
...
@@ -188,6 +189,7 @@ func awsStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode i
...
@@ -188,6 +189,7 @@ func awsStreamHandler(c *gin.Context, info *relaycommon.RelayInfo, requestMode i
if
response
.
Model
!=
""
{
if
response
.
Model
!=
""
{
model
=
response
.
Model
model
=
response
.
Model
}
}
response
.
Created
=
createdTime
response
.
Id
=
id
response
.
Id
=
id
response
.
Model
=
model
response
.
Model
=
model
...
...
relay/channel/claude/relay-claude.go
View file @
8e3c5276
...
@@ -181,9 +181,10 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) (*
...
@@ -181,9 +181,10 @@ func StreamResponseClaude2OpenAI(reqMode int, claudeResponse *ClaudeResponse) (*
response
.
Id
=
claudeResponse
.
Message
.
Id
response
.
Id
=
claudeResponse
.
Message
.
Id
response
.
Model
=
claudeResponse
.
Message
.
Model
response
.
Model
=
claudeResponse
.
Message
.
Model
claudeUsage
=
&
claudeResponse
.
Message
.
Usage
claudeUsage
=
&
claudeResponse
.
Message
.
Usage
}
else
if
claudeResponse
.
Type
==
"content_block_start"
{
choice
.
Delta
.
SetContentString
(
""
)
choice
.
Delta
.
SetContentString
(
""
)
choice
.
Delta
.
Role
=
"assistant"
choice
.
Delta
.
Role
=
"assistant"
}
else
if
claudeResponse
.
Type
==
"content_block_start"
{
return
nil
,
nil
}
else
if
claudeResponse
.
Type
==
"content_block_delta"
{
}
else
if
claudeResponse
.
Type
==
"content_block_delta"
{
choice
.
Index
=
claudeResponse
.
Index
choice
.
Index
=
claudeResponse
.
Index
choice
.
Delta
.
SetContentString
(
claudeResponse
.
Delta
.
Text
)
choice
.
Delta
.
SetContentString
(
claudeResponse
.
Delta
.
Text
)
...
...
service/token_counter.go
View file @
8e3c5276
...
@@ -232,7 +232,7 @@ func CountTokenInput(input any, model string, check bool) (int, error, bool) {
...
@@ -232,7 +232,7 @@ func CountTokenInput(input any, model string, check bool) (int, error, bool) {
func
CountTokenStreamChoices
(
messages
[]
dto
.
ChatCompletionsStreamResponseChoice
,
model
string
)
int
{
func
CountTokenStreamChoices
(
messages
[]
dto
.
ChatCompletionsStreamResponseChoice
,
model
string
)
int
{
tokens
:=
0
tokens
:=
0
for
_
,
message
:=
range
messages
{
for
_
,
message
:=
range
messages
{
tkm
,
_
,
_
:=
CountTokenInput
(
message
.
Delta
.
Content
,
model
,
false
)
tkm
,
_
,
_
:=
CountTokenInput
(
message
.
Delta
.
GetContentString
()
,
model
,
false
)
tokens
+=
tkm
tokens
+=
tkm
if
message
.
Delta
.
ToolCalls
!=
nil
{
if
message
.
Delta
.
ToolCalls
!=
nil
{
for
_
,
tool
:=
range
message
.
Delta
.
ToolCalls
{
for
_
,
tool
:=
range
message
.
Delta
.
ToolCalls
{
...
...
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