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

Function CountTokenStreamChoices

service/token_counter.go:414–429  ·  view source on GitHub ↗
(messages []dto.ChatCompletionsStreamResponseChoice, model string)

Source from the content-addressed store, hash-verified

412}
413
414func CountTokenStreamChoices(messages []dto.ChatCompletionsStreamResponseChoice, model string) int {
415 tokens := 0
416 for _, message := range messages {
417 tkm := CountTokenInput(message.Delta.GetContentString(), model)
418 tokens += tkm
419 if message.Delta.ToolCalls != nil {
420 for _, tool := range message.Delta.ToolCalls {
421 tkm := CountTokenInput(tool.Function.Name, model)
422 tokens += tkm
423 tkm = CountTokenInput(tool.Function.Arguments, model)
424 tokens += tkm
425 }
426 }
427 }
428 return tokens
429}
430
431func CountTTSToken(text string, model string) int {
432 if strings.HasPrefix(model, "tts") {

Callers

nothing calls this directly

Calls 2

CountTokenInputFunction · 0.85
GetContentStringMethod · 0.80

Tested by

no test coverage detected