MCPcopy
hub / github.com/mudler/LocalAI / tokenizeTokenCount

Function tokenizeTokenCount

core/backend/tokenize.go:20–25  ·  view source on GitHub ↗

tokenizeTokenCount returns the number of tokens in a backend response, treating a nil response as zero. The gRPC client returns (nil, err) on failure, and the tracing block below runs before that error is returned — so the count must be read nil-safely here. Reading resp.Tokens on a nil resp previou

(resp *pb.TokenizationResponse)

Source from the content-addressed store, hash-verified

18// resp previously panicked the whole HTTP handler when tracing was enabled
19// (e.g. a transient tokenize failure during router probe-budget sizing).
20func tokenizeTokenCount(resp *pb.TokenizationResponse) int {
21 if resp == nil {
22 return 0
23 }
24 return len(resp.Tokens)
25}
26
27func ModelTokenize(s string, loader *model.ModelLoader, modelConfig config.ModelConfig, appConfig *config.ApplicationConfig) (schema.TokenizeResponse, error) {
28

Callers 2

ModelTokenizeFunction · 0.85
tokenize_test.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected