Fix issue of ask API. (#5400)

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Kevin Hu
2025-02-26 19:45:22 +08:00
committed by GitHub
parent f372bd8809
commit fa76974e24
3 changed files with 21 additions and 15 deletions

View File

@ -23,6 +23,8 @@ from api.db.services.dialog_service import DialogService, chat
from api.utils import get_uuid
import json
from rag.prompts import chunks_format
class ConversationService(CommonService):
model = Conversation
@ -53,19 +55,7 @@ def structure_answer(conv, ans, message_id, session_id):
reference = {}
ans["reference"] = {}
def get_value(d, k1, k2):
return d.get(k1, d.get(k2))
chunk_list = [{
"id": get_value(chunk, "chunk_id", "id"),
"content": get_value(chunk, "content", "content_with_weight"),
"document_id": get_value(chunk, "doc_id", "document_id"),
"document_name": get_value(chunk, "docnm_kwd", "document_name"),
"dataset_id": get_value(chunk, "kb_id", "dataset_id"),
"image_id": get_value(chunk, "image_id", "img_id"),
"positions": get_value(chunk, "positions", "position_int"),
"url": chunk.get("url")
} for chunk in reference.get("chunks", [])]
chunk_list = chunks_format(reference)
reference["chunks"] = chunk_list
ans["id"] = message_id