From 53c59c47a13bab9b7c8c56898e4d38325daa276b Mon Sep 17 00:00:00 2001 From: Qi <18705192873@163.com> Date: Mon, 28 Apr 2025 15:19:21 +0800 Subject: [PATCH] Fix:Update chat assistant with an empty dataset (#7354) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? When updating a chat assistant using API,if the dataset attached by the current chat assistant is not empty,setting dataset to null("dataset_ids":[]) will cause update failure:'dataset_ids' can't be empty ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/chat.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/api/apps/sdk/chat.py b/api/apps/sdk/chat.py index d41e44533..18e1cf83f 100644 --- a/api/apps/sdk/chat.py +++ b/api/apps/sdk/chat.py @@ -165,27 +165,24 @@ def update(tenant_id, chat_id): ids = req.get("dataset_ids") if "show_quotation" in req: req["do_refer"] = req.pop("show_quotation") - if "dataset_ids" in req: - if not ids: - return get_error_data_result("`dataset_ids` can't be empty") - if ids: - for kb_id in ids: - kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) - if not kbs: - return get_error_data_result(f"You don't own the dataset {kb_id}") - kbs = KnowledgebaseService.query(id=kb_id) - kb = kbs[0] - if kb.chunk_num == 0: - return get_error_data_result(f"The dataset {kb_id} doesn't own parsed file") - - kbs = KnowledgebaseService.get_by_ids(ids) - embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs] # remove vendor suffix for comparison - embd_count = list(set(embd_ids)) - if len(embd_count) != 1: - return get_result( - message='Datasets use different embedding models."', - code=settings.RetCode.AUTHENTICATION_ERROR) - req["kb_ids"] = ids + if ids is not None: + for kb_id in ids: + kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) + if not kbs: + return get_error_data_result(f"You don't own the dataset {kb_id}") + kbs = KnowledgebaseService.query(id=kb_id) + kb = kbs[0] + if kb.chunk_num == 0: + return get_error_data_result(f"The dataset {kb_id} doesn't own parsed file") + + kbs = KnowledgebaseService.get_by_ids(ids) + embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs] # remove vendor suffix for comparison + embd_count = list(set(embd_ids)) + if len(embd_count) != 1: + return get_result( + message='Datasets use different embedding models."', + code=settings.RetCode.AUTHENTICATION_ERROR) + req["kb_ids"] = ids llm = req.get("llm") if llm: if "model_name" in llm: