Fix:Update chat assistant with an empty dataset (#7354)

### 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)
This commit is contained in:
Qi 2025-04-28 15:19:21 +08:00 committed by GitHub
parent af393b0003
commit 53c59c47a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -165,27 +165,24 @@ def update(tenant_id, chat_id):
ids = req.get("dataset_ids") ids = req.get("dataset_ids")
if "show_quotation" in req: if "show_quotation" in req:
req["do_refer"] = req.pop("show_quotation") req["do_refer"] = req.pop("show_quotation")
if "dataset_ids" in req: if ids is not None:
if not ids: for kb_id in ids:
return get_error_data_result("`dataset_ids` can't be empty") kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id)
if ids: if not kbs:
for kb_id in ids: return get_error_data_result(f"You don't own the dataset {kb_id}")
kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) kbs = KnowledgebaseService.query(id=kb_id)
if not kbs: kb = kbs[0]
return get_error_data_result(f"You don't own the dataset {kb_id}") if kb.chunk_num == 0:
kbs = KnowledgebaseService.query(id=kb_id) return get_error_data_result(f"The dataset {kb_id} doesn't own parsed file")
kb = kbs[0]
if kb.chunk_num == 0: kbs = KnowledgebaseService.get_by_ids(ids)
return get_error_data_result(f"The dataset {kb_id} doesn't own parsed file") 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))
kbs = KnowledgebaseService.get_by_ids(ids) if len(embd_count) != 1:
embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs] # remove vendor suffix for comparison return get_result(
embd_count = list(set(embd_ids)) message='Datasets use different embedding models."',
if len(embd_count) != 1: code=settings.RetCode.AUTHENTICATION_ERROR)
return get_result( req["kb_ids"] = ids
message='Datasets use different embedding models."',
code=settings.RetCode.AUTHENTICATION_ERROR)
req["kb_ids"] = ids
llm = req.get("llm") llm = req.get("llm")
if llm: if llm:
if "model_name" in llm: if "model_name" in llm: