(input any, model string)
| 392 | } |
| 393 | |
| 394 | func 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 | |
| 414 | func CountTokenStreamChoices(messages []dto.ChatCompletionsStreamResponseChoice, model string) int { |
| 415 | tokens := 0 |
no test coverage detected