@@ -247,8 +247,31 @@ def _asdict(self) -> Mapping[str, Any]:
247247
248248@dataclass (frozen = True )
249249class CompletionResponse :
250+ """
251+ Describes a completion response
252+
253+ Parameters:
254+ model_version:
255+ Model name and version (if any) of the used model for inference.
256+ completions:
257+ List of completions; may contain only one entry if no more are requested (see parameter n).
258+ num_tokens_prompt_total:
259+ Number of tokens combined across all completion tasks.
260+ In particular, if you set best_of or n to a number larger than 1 then we report the
261+ combined prompt token count for all best_of or n tasks.
262+ num_tokens_generated:
263+ Number of tokens combined across all completion tasks.
264+ If multiple completions are returned or best_of is set to a value greater than 1 then
265+ this value contains the combined generated token count.
266+ optimized_prompt:
267+ Describes prompt after optimizations. This field is only returned if the flag
268+ `disable_optimizations` flag is not set and the prompt has actually changed.
269+ """
270+
250271 model_version : str
251272 completions : Sequence [CompletionResult ]
273+ num_tokens_prompt_total : int
274+ num_tokens_generated : int
252275 optimized_prompt : Optional [Prompt ] = None
253276
254277 @staticmethod
@@ -259,6 +282,8 @@ def from_json(json: Dict[str, Any]) -> "CompletionResponse":
259282 completions = [
260283 CompletionResult .from_json (item ) for item in json ["completions" ]
261284 ],
285+ num_tokens_prompt_total = json ["num_tokens_prompt_total" ],
286+ num_tokens_generated = json ["num_tokens_generated" ],
262287 optimized_prompt = Prompt .from_json (optimized_prompt_json )
263288 if optimized_prompt_json
264289 else None ,
0 commit comments