fix(utils.py): support streamingchoices in 'get_response_string

This commit is contained in:
Krrish Dholakia 2024-06-22 15:45:52 -07:00
parent bae7377128
commit c4b1540ce0

View file

@ -3896,12 +3896,16 @@ def get_formatted_prompt(
def get_response_string(response_obj: ModelResponse) -> str:
_choices: List[Choices] = response_obj.choices # type: ignore
_choices: List[Union[Choices, StreamingChoices]] = response_obj.choices
response_str = ""
for choice in _choices:
if choice.message.content is not None:
response_str += choice.message.content
if isinstance(choice, Choices):
if choice.message.content is not None:
response_str += choice.message.content
elif isinstance(choice, StreamingChoices):
if choice.delta.content is not None:
response_str += choice.delta.content
return response_str