MCPcopy Create free account
hub / github.com/WeixiangYAN/ClinicalLab / count_tokens

Method count_tokens

code/inference/evaluators/chatgpt.py:37–44  ·  view source on GitHub ↗
(self, prompt)

Source from the content-addressed store, hash-verified

35
36 @backoff.on_exception(backoff.expo, openai.error.RateLimitError)
37 def count_tokens(self, prompt):
38 try:
39 encoding = tiktoken.encoding_for_model(self.model)
40 except KeyError:
41 encoding = tiktoken.get_encoding('cl100k_base')
42 num_tokens = len(encoding.encode(prompt))
43
44 return num_tokens

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected