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
16afc5b3
authored
Jan 02, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: retry prompt tokens
parent
a835920f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
7 deletions
+8
-7
relay/relay-text.go
+1
-0
service/token_counter.go
+7
-7
web/pnpm-lock.yaml
+0
-0
No files found.
relay/relay-text.go
View file @
16afc5b3
...
@@ -112,6 +112,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
...
@@ -112,6 +112,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
var
promptTokens
int
var
promptTokens
int
if
value
,
exists
:=
c
.
Get
(
"prompt_tokens"
);
exists
{
if
value
,
exists
:=
c
.
Get
(
"prompt_tokens"
);
exists
{
promptTokens
=
value
.
(
int
)
promptTokens
=
value
.
(
int
)
relayInfo
.
PromptTokens
=
promptTokens
}
else
{
}
else
{
promptTokens
,
err
=
getPromptTokens
(
textRequest
,
relayInfo
)
promptTokens
,
err
=
getPromptTokens
(
textRequest
,
relayInfo
)
// count messages token error 计算promptTokens错误
// count messages token error 计算promptTokens错误
...
...
service/token_counter.go
View file @
16afc5b3
...
@@ -92,13 +92,6 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
...
@@ -92,13 +92,6 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
if
!
constant
.
GetMediaTokenNotStream
&&
!
stream
{
if
!
constant
.
GetMediaTokenNotStream
&&
!
stream
{
return
256
,
nil
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的图片计费逻辑
// 同步One API的图片计费逻辑
if
imageUrl
.
Detail
==
"auto"
||
imageUrl
.
Detail
==
""
{
if
imageUrl
.
Detail
==
"auto"
||
imageUrl
.
Detail
==
""
{
imageUrl
.
Detail
=
"high"
imageUrl
.
Detail
=
"high"
...
@@ -109,6 +102,13 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
...
@@ -109,6 +102,13 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
tileTokens
=
5667
tileTokens
=
5667
baseTokens
=
2833
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
config
image
.
Config
var
err
error
var
err
error
var
format
string
var
format
string
...
...
web/pnpm-lock.yaml
View file @
16afc5b3
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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