Myth
Kevin Hu
commited on
Commit
·
17b116d
1
Parent(s):
d3dad46
fix: Fix for Empty Reference Array Causing Errors (#1652)
Browse files### 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 <[email protected]>
- api/apps/api_app.py +5 -2
api/apps/api_app.py
CHANGED
@@ -199,8 +199,11 @@ def completion():
|
|
199 |
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
|
200 |
|
201 |
def rename_field(ans):
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
204 |
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
205 |
chunk_i.pop('docnm_kwd')
|
206 |
|
|
|
199 |
conv.message[-1] = {"role": "assistant", "content": ans["answer"]}
|
200 |
|
201 |
def rename_field(ans):
|
202 |
+
reference = ans['reference']
|
203 |
+
if not isinstance(reference, dict):
|
204 |
+
return
|
205 |
+
for chunk_i in reference.get('chunks', []):
|
206 |
+
if 'docnm_kwd' in chunk_i:
|
207 |
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
208 |
chunk_i.pop('docnm_kwd')
|
209 |
|