INNER CODE UNIT · Python
reduce_choice
hyperonym/basaran · basaran/choice.py:40
def reduce_choice(choices):
"""Merge a list of choices into a single choice object."""
buffer = []
index = 0
finish_reason = None
tokens = []
token_logprobs = []
top_logprobs = []
text_offset = []
# All choice objects are expected to have the same shape.
for choice in choices:
buffer.append(choice["text"])
index = choice["index"]
finish_reason = choice["finish_reason"]
logprobs = choice["logprobs"]
if logprobs is not None:
tokens += logprobs["tokens"]