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
a36d6de8
authored
Mar 08, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Add prompt cache hit tokens support for DeepSeek channel #406
parent
5bed29e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
0 deletions
+7
-0
dto/openai_response.go
+1
-0
relay/channel/openai/relay-openai.go
+6
-0
No files found.
dto/openai_response.go
View file @
a36d6de8
...
@@ -166,6 +166,7 @@ type Usage struct {
...
@@ -166,6 +166,7 @@ type Usage struct {
PromptTokens
int
`json:"prompt_tokens"`
PromptTokens
int
`json:"prompt_tokens"`
CompletionTokens
int
`json:"completion_tokens"`
CompletionTokens
int
`json:"completion_tokens"`
TotalTokens
int
`json:"total_tokens"`
TotalTokens
int
`json:"total_tokens"`
PromptCacheHitTokens
int
`json:"prompt_cache_hit_tokens,omitempty"`
PromptTokensDetails
InputTokenDetails
`json:"prompt_tokens_details"`
PromptTokensDetails
InputTokenDetails
`json:"prompt_tokens_details"`
CompletionTokenDetails
OutputTokenDetails
`json:"completion_tokens_details"`
CompletionTokenDetails
OutputTokenDetails
`json:"completion_tokens_details"`
}
}
relay/channel/openai/relay-openai.go
View file @
a36d6de8
...
@@ -254,6 +254,12 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
...
@@ -254,6 +254,12 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
if
!
containStreamUsage
{
if
!
containStreamUsage
{
usage
,
_
=
service
.
ResponseText2Usage
(
responseTextBuilder
.
String
(),
info
.
UpstreamModelName
,
info
.
PromptTokens
)
usage
,
_
=
service
.
ResponseText2Usage
(
responseTextBuilder
.
String
(),
info
.
UpstreamModelName
,
info
.
PromptTokens
)
usage
.
CompletionTokens
+=
toolCount
*
7
usage
.
CompletionTokens
+=
toolCount
*
7
}
else
{
if
info
.
ChannelType
==
common
.
ChannelTypeDeepSeek
{
if
usage
.
PromptCacheHitTokens
!=
0
{
usage
.
PromptTokensDetails
.
CachedTokens
=
usage
.
PromptCacheHitTokens
}
}
}
}
if
info
.
ShouldIncludeUsage
&&
!
containStreamUsage
{
if
info
.
ShouldIncludeUsage
&&
!
containStreamUsage
{
...
...
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