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
d1f3f2c3
authored
Aug 27, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(token_counter): update token counting logic to handle media token conditions
parent
d92c9db6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
service/token_counter.go
+9
-4
No files found.
service/token_counter.go
View file @
d1f3f2c3
...
...
@@ -250,13 +250,18 @@ func getImageToken(fileMeta *types.FileMeta, model string, stream bool) (int, er
}
func
CountRequestToken
(
c
*
gin
.
Context
,
meta
*
types
.
TokenCountMeta
,
info
*
relaycommon
.
RelayInfo
)
(
int
,
error
)
{
if
meta
==
nil
{
return
0
,
errors
.
New
(
"token count meta is nil"
)
if
!
constant
.
GetMediaToken
{
return
0
,
nil
}
if
!
constant
.
GetMediaTokenNotStream
&&
!
info
.
IsStream
{
return
0
,
nil
}
if
info
.
RelayFormat
==
types
.
RelayFormatOpenAIRealtime
{
return
0
,
nil
}
if
meta
==
nil
{
return
0
,
errors
.
New
(
"token count meta is nil"
)
}
model
:=
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyOriginalModel
)
tkm
:=
0
...
...
@@ -276,7 +281,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
shouldFetchFiles
:=
true
if
info
.
RelayFormat
==
types
.
RelayFormat
OpenAIRealtime
||
info
.
RelayFormat
==
types
.
RelayFormat
Gemini
{
if
info
.
RelayFormat
==
types
.
RelayFormatGemini
{
shouldFetchFiles
=
false
}
...
...
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