mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(utils.py): support streamingchoices in 'get_response_string
This commit is contained in:
parent
1e4f8744e6
commit
e2332051a1
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