Skip to content

Commit

Permalink
fix: retry prompt tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Jan 2, 2025
1 parent ba1aad8 commit ef4c1a2
Show file tree
Hide file tree
Showing 3 changed files with 2,310 additions and 2,738 deletions.
1 change: 1 addition & 0 deletions relay/relay-text.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
var promptTokens int
if value, exists := c.Get("prompt_tokens"); exists {
promptTokens = value.(int)
relayInfo.PromptTokens = promptTokens
} else {
promptTokens, err = getPromptTokens(textRequest, relayInfo)
// count messages token error 计算promptTokens错误
Expand Down
14 changes: 7 additions & 7 deletions service/token_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
if !constant.GetMediaTokenNotStream && !stream {
return 256, nil
}
// 是否统计图片token
if !constant.GetMediaToken {
return 256, nil
}
if info.ChannelType == common.ChannelTypeGemini || info.ChannelType == common.ChannelTypeVertexAi || info.ChannelType == common.ChannelTypeAnthropic {
return 256, nil
}
// 同步One API的图片计费逻辑
if imageUrl.Detail == "auto" || imageUrl.Detail == "" {
imageUrl.Detail = "high"
Expand All @@ -109,6 +102,13 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
tileTokens = 5667
baseTokens = 2833
}
// 是否统计图片token
if !constant.GetMediaToken {
return 3 * baseTokens, nil
}
if info.ChannelType == common.ChannelTypeGemini || info.ChannelType == common.ChannelTypeVertexAi || info.ChannelType == common.ChannelTypeAnthropic {
return 3 * baseTokens, nil
}
var config image.Config
var err error
var format string
Expand Down
Loading

0 comments on commit ef4c1a2

Please sign in to comment.