From 38be53cf317e4b2cbac06b9589a3922b61eaaa54 Mon Sep 17 00:00:00 2001 From: buua436 <66937541+buua436@users.noreply.github.com> Date: Tue, 23 Sep 2025 19:59:39 +0800 Subject: [PATCH] fix: prevent list index out of range in chat streaming (#10238) ### What problem does this PR solve? issue: [Bug]: ERROR: list index out of range #10188 change: fix a potential list index out of range error in chat response parsing by adding explicit checks for empty choices. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- rag/llm/chat_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py index d0b422215..79304d27a 100644 --- a/rag/llm/chat_model.py +++ b/rag/llm/chat_model.py @@ -146,7 +146,7 @@ class Base(ABC): response = self.client.chat.completions.create(model=self.model_name, messages=history, **gen_conf, **kwargs) - if any([not response.choices, not response.choices[0].message, not response.choices[0].message.content]): + if (not response.choices or not response.choices[0].message or not response.choices[0].message.content): return "", 0 ans = response.choices[0].message.content.strip() if response.choices[0].finish_reason == "length":