MCPcopy Create free account
hub / github.com/astercloud/aster / Count

Method Count

pkg/context/token_counter.go:233–248  ·  view source on GitHub ↗

Count 实现 TokenCounter 接口

(ctx context.Context, text string)

Source from the content-addressed store, hash-verified

231
232// Count 实现 TokenCounter 接口
233func (c *SimpleTokenCounter) Count(ctx context.Context, text string) (int, error) {
234 if text == "" {
235 return 0, nil
236 }
237
238 // 基于字符数估算 Token
239 charCount := utf8.RuneCountInString(text)
240 tokenCount := int(float64(charCount) / c.config.CharsPerToken)
241
242 // 至少为 1 个 Token
243 if tokenCount == 0 && charCount > 0 {
244 tokenCount = 1
245 }
246
247 return tokenCount, nil
248}
249
250// CountBatch 实现 TokenCounter 接口
251func (c *SimpleTokenCounter) CountBatch(ctx context.Context, texts []string) ([]int, error) {

Callers 3

CountBatchMethod · 0.95
EstimateMessagesMethod · 0.95

Calls

no outgoing calls

Tested by 1