in 3_optimization-design-ptn/03_prompt-optimization/promptwizard/glue/common/llm/llm_mgr.py [0:0]
def get_tokens_used(llm_handle: LLM) -> Dict[str, int]:
"""
For a given LLM, output the number of tokens used.
:param llm_handle: Handle to a single LLM
:return: Dict of token-type and count of tokens used
"""
token_counter = get_token_counter(llm_handle)
if token_counter:
return {
LLMLiterals.EMBEDDING_TOKEN_COUNT: token_counter.total_embedding_token_count,
LLMLiterals.PROMPT_LLM_TOKEN_COUNT: token_counter.prompt_llm_token_count,
LLMLiterals.COMPLETION_LLM_TOKEN_COUNT: token_counter.completion_llm_token_count,
LLMLiterals.TOTAL_LLM_TOKEN_COUNT: token_counter.total_llm_token_count,
}
return None