diff --git a/aidial_assistant/model/model_client.py b/aidial_assistant/model/model_client.py index 198d3f5..3df3fea 100644 --- a/aidial_assistant/model/model_client.py +++ b/aidial_assistant/model/model_client.py @@ -98,21 +98,22 @@ async def agenerate( else discarded_messages ) - choice = chunk.choices[0] - delta = choice.delta - if delta.content: - yield delta.content - - if delta.tool_calls: - tool_calls_chunks.append( - [ - tool_call_chunk.dict() - for tool_call_chunk in delta.tool_calls - ] - ) - - if choice.finish_reason == "length": - finish_reason_length = True + if len(chunk.choices) > 0: + choice = chunk.choices[0] + delta = choice.delta + if delta.content: + yield delta.content + + if delta.tool_calls: + tool_calls_chunks.append( + [ + tool_call_chunk.dict() + for tool_call_chunk in delta.tool_calls + ] + ) + + if choice.finish_reason == "length": + finish_reason_length = True if finish_reason_length: raise ReasonLengthException()