Parcourir la source

Feat: Add API to support get chunk by id (#7522)

### What problem does this PR solve?
https://github.com/infiniflow/ragflow/issues/7519
### Type of change
- [x] New Feature (non-breaking change which adds functionality)

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
tags/v0.19.0
Stephen Hu il y a 5 mois
Parent
révision
3827c47515
Aucun compte lié à l'adresse e-mail de l'auteur
1 fichiers modifiés avec 26 ajouts et 1 suppressions
  1. 26
    1
      api/apps/api_app.py

+ 26
- 1
api/apps/api_app.py Voir le fichier

@@ -345,7 +345,7 @@ def completion():

@manager.route('/conversation/<conversation_id>', 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/<chunk_id>', 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

Chargement…
Annuler
Enregistrer