Просмотр исходного кода

feat: Add prompt cache hit tokens support for DeepSeek channel #406

1808837298@qq.com 1 год назад
Родитель
Сommit
a9bfcb0daf
2 измененных файлов с 7 добавлено и 0 удалено
  1. 1 0
      dto/openai_response.go
  2. 6 0
      relay/channel/openai/relay-openai.go

+ 1 - 0
dto/openai_response.go

@@ -166,6 +166,7 @@ type Usage struct {
 	PromptTokens           int                `json:"prompt_tokens"`
 	CompletionTokens       int                `json:"completion_tokens"`
 	TotalTokens            int                `json:"total_tokens"`
+	PromptCacheHitTokens   int                `json:"prompt_cache_hit_tokens,omitempty"`
 	PromptTokensDetails    InputTokenDetails  `json:"prompt_tokens_details"`
 	CompletionTokenDetails OutputTokenDetails `json:"completion_tokens_details"`
 }

+ 6 - 0
relay/channel/openai/relay-openai.go

@@ -254,6 +254,12 @@ func OaiStreamHandler(c *gin.Context, resp *http.Response, info *relaycommon.Rel
 	if !containStreamUsage {
 		usage, _ = service.ResponseText2Usage(responseTextBuilder.String(), info.UpstreamModelName, info.PromptTokens)
 		usage.CompletionTokens += toolCount * 7
+	} else {
+		if info.ChannelType == common.ChannelTypeDeepSeek {
+			if usage.PromptCacheHitTokens != 0 {
+				usage.PromptTokensDetails.CachedTokens = usage.PromptCacheHitTokens
+			}
+		}
 	}
 
 	if info.ShouldIncludeUsage && !containStreamUsage {