MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / CountTokenInput

Function CountTokenInput

service/token_counter.go:394–412  ·  view source on GitHub ↗
(input any, model string)

Source from the content-addressed store, hash-verified

392}
393
394func CountTokenInput(input any, model string) int {
395 switch v := input.(type) {
396 case string:
397 return CountTextToken(v, model)
398 case []string:
399 text := ""
400 for _, s := range v {
401 text += s
402 }
403 return CountTextToken(text, model)
404 case []interface{}:
405 text := ""
406 for _, item := range v {
407 text += fmt.Sprintf("%v", item)
408 }
409 return CountTextToken(text, model)
410 }
411 return CountTokenInput(fmt.Sprintf("%v", input), model)
412}
413
414func CountTokenStreamChoices(messages []dto.ChatCompletionsStreamResponseChoice, model string) int {
415 tokens := 0

Callers 9

getGeminiInputTokensFunction · 0.92
getEmbeddingPromptTokenFunction · 0.92
getInputTokensFunction · 0.92
getRerankPromptTokenFunction · 0.92
getPromptTokensFunction · 0.92
CountTokenChatRequestFunction · 0.85
CountTokenClaudeRequestFunction · 0.85
CountTokenRealtimeFunction · 0.85
CountTokenStreamChoicesFunction · 0.85

Calls 1

CountTextTokenFunction · 0.85

Tested by

no test coverage detected