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
07137e6b
authored
Aug 15, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: update token type handling and improve token counting logic
parent
8eb17f24
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
3 deletions
+9
-3
common/sys_log.go
+0
-0
dto/claude.go
+1
-1
service/token_counter.go
+8
-2
No files found.
common/
logger
.go
→
common/
sys_log
.go
View file @
07137e6b
File moved
dto/claude.go
View file @
07137e6b
...
...
@@ -204,7 +204,7 @@ type ClaudeRequest struct {
func
(
c
*
ClaudeRequest
)
GetTokenCountMeta
()
*
types
.
TokenCountMeta
{
var
tokenCountMeta
=
types
.
TokenCountMeta
{
TokenType
:
types
.
TokenTypeT
extNumb
er
,
TokenType
:
types
.
TokenTypeT
okeniz
er
,
MaxTokens
:
int
(
c
.
MaxTokens
),
}
...
...
service/token_counter.go
View file @
07137e6b
...
...
@@ -251,9 +251,15 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
if
info
.
RelayFormat
==
types
.
RelayFormatOpenAIRealtime
{
return
0
,
nil
}
model
:=
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyOriginalModel
)
tkm
:=
CountTextToken
(
meta
.
CombineText
,
model
)
tkm
:=
0
if
meta
.
TokenType
==
types
.
TokenTypeTextNumber
{
tkm
+=
utf8
.
RuneCountInString
(
meta
.
CombineText
)
}
else
{
tkm
+=
CountTextToken
(
meta
.
CombineText
,
model
)
}
if
info
.
RelayFormat
==
types
.
RelayFormatOpenAI
{
tkm
+=
meta
.
ToolsCount
*
8
...
...
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