From 40e10fbd4eb7ff622082b625e2cd40d28e632f49 Mon Sep 17 00:00:00 2001 From: Chenjianyu Date: Mon, 25 Mar 2024 17:07:36 +0800 Subject: [PATCH] * check AI assistant name is duplicated or not. --- module/ai/control.php | 6 ++++++ module/ai/lang/de.php | 1 + module/ai/lang/en.php | 1 + module/ai/lang/fr.php | 1 + module/ai/lang/zh-cn.php | 1 + module/ai/model.php | 14 ++++++++++++++ 6 files changed, 24 insertions(+) diff --git a/module/ai/control.php b/module/ai/control.php index 6c0d741825..0526984319 100644 --- a/module/ai/control.php +++ b/module/ai/control.php @@ -358,6 +358,9 @@ class ai extends control } if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $exists = $this->ai->checkAssistantDuplicate($assistant->name, $assistant->modelId); + if($exists) return $this->send(array('result' => 'fail', 'message' => array('name' => $this->lang->ai->assistants->duplicateTip))); + if(empty($assistant->publish)) { $this->ai->createAssistant($assistant); @@ -405,6 +408,9 @@ class ai extends control } if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + $exists = $this->ai->checkAssistantDuplicate($assistant->name, $assistant->modelId); + if($exists) return $this->send(array('result' => 'fail', 'message' => array('name' => $this->lang->ai->assistants->duplicateTip))); + $assistant->id = $assistantId; $this->ai->updateAssistant($assistant); diff --git a/module/ai/lang/de.php b/module/ai/lang/de.php index 57fc5146d6..4955f01f0e 100644 --- a/module/ai/lang/de.php +++ b/module/ai/lang/de.php @@ -987,6 +987,7 @@ $lang->ai->assistants->publish = 'Publish'; $lang->ai->assistants->withdraw = 'Disable'; $lang->ai->assistants->confirmPublishTip = 'After publishing, it will be displayed in the AI dialogue and client dialogue in the lower right corner of ZenTao. Do you want to confirm the publication? '; $lang->ai->assistants->confirmWithdrawTip = 'After deactivation, front-end users will not be able to see this AI assistant. Do you confirm the deactivation? '; +$lang->ai->assistants->duplicateTip = 'Assistant names in the same language model cannot be same.'; $lang->ai->assistants->statusList = array(); $lang->ai->assistants->statusList['0'] = 'Unpublished'; diff --git a/module/ai/lang/en.php b/module/ai/lang/en.php index f9006bd186..9eeae59b8d 100644 --- a/module/ai/lang/en.php +++ b/module/ai/lang/en.php @@ -987,6 +987,7 @@ $lang->ai->assistants->publish = 'Publish'; $lang->ai->assistants->withdraw = 'Disable'; $lang->ai->assistants->confirmPublishTip = 'After publishing, it will be displayed in the AI dialogue and client dialogue in the lower right corner of ZenTao. Do you want to confirm the publication? '; $lang->ai->assistants->confirmWithdrawTip = 'After deactivation, front-end users will not be able to see this AI assistant. Do you confirm the deactivation? '; +$lang->ai->assistants->duplicateTip = 'Assistant names in the same language model cannot be same.'; $lang->ai->assistants->statusList = array(); $lang->ai->assistants->statusList['0'] = 'Unpublished'; diff --git a/module/ai/lang/fr.php b/module/ai/lang/fr.php index f9006bd186..9eeae59b8d 100644 --- a/module/ai/lang/fr.php +++ b/module/ai/lang/fr.php @@ -987,6 +987,7 @@ $lang->ai->assistants->publish = 'Publish'; $lang->ai->assistants->withdraw = 'Disable'; $lang->ai->assistants->confirmPublishTip = 'After publishing, it will be displayed in the AI dialogue and client dialogue in the lower right corner of ZenTao. Do you want to confirm the publication? '; $lang->ai->assistants->confirmWithdrawTip = 'After deactivation, front-end users will not be able to see this AI assistant. Do you confirm the deactivation? '; +$lang->ai->assistants->duplicateTip = 'Assistant names in the same language model cannot be same.'; $lang->ai->assistants->statusList = array(); $lang->ai->assistants->statusList['0'] = 'Unpublished'; diff --git a/module/ai/lang/zh-cn.php b/module/ai/lang/zh-cn.php index 4ee108fec2..778c49f357 100644 --- a/module/ai/lang/zh-cn.php +++ b/module/ai/lang/zh-cn.php @@ -987,6 +987,7 @@ $lang->ai->assistants->publish = '发布'; $lang->ai->assistants->withdraw = '停用'; $lang->ai->assistants->confirmPublishTip = '发布后将显示在禅道右下角AI对话和客户端对话中,是否确认发布?'; $lang->ai->assistants->confirmWithdrawTip = '停用后前台用户将无法看到此AI助手,是否确认停用?'; +$lang->ai->assistants->duplicateTip = '同一语言模型下的助手名称不可重复。'; $lang->ai->assistants->statusList = array(); $lang->ai->assistants->statusList['0'] = '未发布'; diff --git a/module/ai/model.php b/module/ai/model.php index 9aa44f7c76..fb44b7d398 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -2825,6 +2825,20 @@ class aiModel extends model return true; } + /** + * Find assistants name is duplicate. + * @param string $AssistantName + * @param int $modelId + * @access public + * @return bool + */ + public function checkAssistantDuplicate($AssistantName, $modelId) + { + return $this->dao->select('*')->from(TABLE_AI_ASSISTANT) + ->where('name')->eq($AssistantName) + ->andWhere('modelId')->eq($modelId) + ->fetch(); + } } /**