diff --git a/api/apps/api_app.py b/api/apps/api_app.py index 5376ef0ed..27e1606de 100644 --- a/api/apps/api_app.py +++ b/api/apps/api_app.py @@ -345,7 +345,7 @@ def completion(): @manager.route('/conversation/', methods=['GET']) # noqa: F821 # @login_required -def get(conversation_id): +def get_conversation(conversation_id): token = request.headers.get('Authorization').split()[1] objs = APIToken.query(token=token) if not objs: @@ -548,6 +548,31 @@ def list_chunks(): return get_json_result(data=res) +@manager.route('/get_chunk/', methods=['GET']) # noqa: F821 +# @login_required +def get_chunk(chunk_id): + from rag.nlp import search + token = request.headers.get('Authorization').split()[1] + objs = APIToken.query(token=token) + if not objs: + return get_json_result( + data=False, message='Authentication error: API key is invalid!"', code=settings.RetCode.AUTHENTICATION_ERROR) + try: + tenant_id = objs[0].tenant_id + kb_ids = KnowledgebaseService.get_kb_ids(tenant_id) + chunk = settings.docStoreConn.get(chunk_id, search.index_name(tenant_id), kb_ids) + if chunk is None: + return server_error_response(Exception("Chunk not found")) + k = [] + for n in chunk.keys(): + if re.search(r"(_vec$|_sm_|_tks|_ltks)", n): + k.append(n) + for n in k: + del chunk[n] + + return get_json_result(data=chunk) + except Exception as e: + return server_error_response(e) @manager.route('/list_kb_docs', methods=['POST']) # noqa: F821 # @login_required