mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
fix: Fix for Empty Reference Array Causing Errors (#1652)
### What problem does this PR solve?
This pull request addresses an issue where the reference is an empty
array ([]) in specific cases, leading to errors in the application. When
the reference is empty, the code attempts to call the get method on a
list, resulting in the following error message:
``` json
{"retcode": 500, "retmsg": "'list' object has no attribute 'get'", "data": {"answer": "**ERROR**: 'list' object has no attribute 'get'", "reference": []}}
```
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
@ -199,8 +199,11 @@ def completion():
|
|||||||
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
|
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
|
||||||
|
|
||||||
def rename_field(ans):
|
def rename_field(ans):
|
||||||
for chunk in ans.get('reference', []):
|
reference = ans['reference']
|
||||||
for chunk_i in chunk.get('chunks', []):
|
if not isinstance(reference, dict):
|
||||||
|
return
|
||||||
|
for chunk_i in reference.get('chunks', []):
|
||||||
|
if 'docnm_kwd' in chunk_i:
|
||||||
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
||||||
chunk_i.pop('docnm_kwd')
|
chunk_i.pop('docnm_kwd')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user