From d405e86890b9ab6f24a0d9a221f36ca05b7c9d85 Mon Sep 17 00:00:00 2001 From: "zhenjie.ye" Date: Mon, 3 Jun 2024 17:17:24 +0800 Subject: [PATCH] Fix streaming mode index out of range error --- chatblade/chat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/chatblade/chat.py b/chatblade/chat.py index cdd7fac..cbeb459 100644 --- a/chatblade/chat.py +++ b/chatblade/chat.py @@ -91,6 +91,8 @@ def map_from_stream(openai_gen): final one being the completed Message""" role, message = None, "" for update in openai_gen: + if not update.choices: + continue # Skip the iteration if choices is empty delta = [choice.delta for choice in update.choices][0] if delta.role: role = delta.role