forked from phoenix/litellm-mirror
fix(utils.py): support streamingchoices in 'get_response_string
This commit is contained in:
parent
bae7377128
commit
c4b1540ce0
1 changed files with 7 additions and 3 deletions
|
@ -3896,12 +3896,16 @@ def get_formatted_prompt(
|
||||||
|
|
||||||
|
|
||||||
def get_response_string(response_obj: ModelResponse) -> str:
|
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 = ""
|
response_str = ""
|
||||||
for choice in _choices:
|
for choice in _choices:
|
||||||
if choice.message.content is not None:
|
if isinstance(choice, Choices):
|
||||||
response_str += choice.message.content
|
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
|
return response_str
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue