MCPcopy Create free account
hub / github.com/AsyncFuncAI/deepwiki-open / get_probabilities

Function get_probabilities

api/openai_client.py:105–117  ·  view source on GitHub ↗

r"""Get the probabilities of each token in the completion.

(completion: ChatCompletion)

Source from the content-addressed store, hash-verified

103
104
105def get_probabilities(completion: ChatCompletion) -> List[List[TokenLogProb]]:
106 r"""Get the probabilities of each token in the completion."""
107 log_probs = []
108 for c in completion.choices:
109 content = c.logprobs.content
110 print(content)
111 log_probs_for_choice = []
112 for openai_token_logprob in content:
113 token = openai_token_logprob.token
114 logprob = openai_token_logprob.logprob
115 log_probs_for_choice.append(TokenLogProb(token=token, logprob=logprob))
116 log_probs.append(log_probs_for_choice)
117 return log_probs
118
119
120class OpenAIClient(ModelClient):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected