mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
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)
This commit is contained in:
@ -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":
|
||||
|
||||
Reference in New Issue
Block a user