GYH
commited on
Commit
·
8a1455e
1
Parent(s):
4e0a78d
Update docnm_kwd to doc_name (#939)
Browse files### What problem does this PR solve?
Update docnm_kwd to doc_name
#908
### Type of change
- [x] Refactoring
- api/apps/api_app.py +16 -2
api/apps/api_app.py
CHANGED
|
@@ -203,6 +203,9 @@ def completion():
|
|
| 203 |
try:
|
| 204 |
for ans in chat(dia, msg, True, **req):
|
| 205 |
fillin_conv(ans)
|
|
|
|
|
|
|
|
|
|
| 206 |
yield "data:"+json.dumps({"retcode": 0, "retmsg": "", "data": ans}, ensure_ascii=False) + "\n\n"
|
| 207 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 208 |
except Exception as e:
|
|
@@ -225,6 +228,11 @@ def completion():
|
|
| 225 |
fillin_conv(ans)
|
| 226 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 227 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
return get_json_result(data=answer)
|
| 229 |
|
| 230 |
except Exception as e:
|
|
@@ -239,7 +247,13 @@ def get(conversation_id):
|
|
| 239 |
if not e:
|
| 240 |
return get_data_error_result(retmsg="Conversation not found!")
|
| 241 |
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
except Exception as e:
|
| 244 |
return server_error_response(e)
|
| 245 |
|
|
@@ -430,7 +444,7 @@ def list_kb_docs():
|
|
| 430 |
return server_error_response(e)
|
| 431 |
|
| 432 |
|
| 433 |
-
@manager.route('/document
|
| 434 |
# @login_required
|
| 435 |
def document_rm():
|
| 436 |
token = request.headers.get('Authorization').split()[1]
|
|
|
|
| 203 |
try:
|
| 204 |
for ans in chat(dia, msg, True, **req):
|
| 205 |
fillin_conv(ans)
|
| 206 |
+
for chunk_i in ans['reference'].get('chunks', []):
|
| 207 |
+
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
| 208 |
+
chunk_i.pop('docnm_kwd')
|
| 209 |
yield "data:"+json.dumps({"retcode": 0, "retmsg": "", "data": ans}, ensure_ascii=False) + "\n\n"
|
| 210 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 211 |
except Exception as e:
|
|
|
|
| 228 |
fillin_conv(ans)
|
| 229 |
API4ConversationService.append_message(conv.id, conv.to_dict())
|
| 230 |
break
|
| 231 |
+
|
| 232 |
+
for chunk_i in answer['reference'].get('chunks',[]):
|
| 233 |
+
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
| 234 |
+
chunk_i.pop('docnm_kwd')
|
| 235 |
+
|
| 236 |
return get_json_result(data=answer)
|
| 237 |
|
| 238 |
except Exception as e:
|
|
|
|
| 247 |
if not e:
|
| 248 |
return get_data_error_result(retmsg="Conversation not found!")
|
| 249 |
|
| 250 |
+
conv = conv.to_dict()
|
| 251 |
+
for referenct_i in conv['reference']:
|
| 252 |
+
for chunk_i in referenct_i['chunks']:
|
| 253 |
+
if 'docnm_kwd' in chunk_i.keys():
|
| 254 |
+
chunk_i['doc_name'] = chunk_i['docnm_kwd']
|
| 255 |
+
chunk_i.pop('docnm_kwd')
|
| 256 |
+
return get_json_result(data=conv)
|
| 257 |
except Exception as e:
|
| 258 |
return server_error_response(e)
|
| 259 |
|
|
|
|
| 444 |
return server_error_response(e)
|
| 445 |
|
| 446 |
|
| 447 |
+
@manager.route('/document', methods=['DELETE'])
|
| 448 |
# @login_required
|
| 449 |
def document_rm():
|
| 450 |
token = request.headers.get('Authorization').split()[1]
|