From 4ef4c1f9712752d2e7bbe33bafbacda11b5deb67 Mon Sep 17 00:00:00 2001 From: Chenjianyu Date: Fri, 29 Mar 2024 11:09:07 +0800 Subject: [PATCH] * add assistant for chat with ai. --- Makefile | 1 + .../xuan/im/ext/control/chatwithai.php | 14 +++++++++++++- .../xuan/im/ext/control/getaiassistant.php | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 xuanxuan/extension/xuan/im/ext/control/getaiassistant.php diff --git a/Makefile b/Makefile index 67b5d79097..1fc3d3407d 100644 --- a/Makefile +++ b/Makefile @@ -178,6 +178,7 @@ zentaoxx: echo "\$$config->xuanxuan->enabledMethods['im']['getaipermission'] = 'getAiPermission';" >> zentaoxx/config/ext/_0_xuanxuan.php echo "\$$config->xuanxuan->enabledMethods['im']['chatwithai'] = 'chatWithAi';" >> zentaoxx/config/ext/_0_xuanxuan.php echo "\$$config->xuanxuan->enabledMethods['im']['clearaichatcontext'] = 'clearAiChatContext';" >> zentaoxx/config/ext/_0_xuanxuan.php + echo "\$$config->xuanxuan->enabledMethods['im']['getaiassistant'] = 'getAiAssistant';" >> zentaoxx/config/ext/_0_xuanxuan.php find zentaoxx/extension/xuan/ -name '*.php' -exec sed -i -r 's|->ne(["'\'']0000-00-00 00:00:00["'\''])|->notZeroDatetime()|g; s|["'\'']\)->eq\(["'\'']0000-00-00( 00:00:00)?| is null|g; s|([=!]=) ?["'\'']0000-00-00( 00:00:00)?["'\'']|\1 null|g; s|([^!=]=) ?["'\'']0000-00-00( 00:00:00)?["'\'']|\1 null|g; s|(["'\''])(,.*)\)->eq\(["'\'']0000-00-00( 00:00:00)?["'\'']| is null\1\2|g; s|["'\'']0000-00-00 00:00:00["'\'']|null|g' {} + mkdir zentaoxx/misc; cp misc/cn2tw.php zentaoxx/misc; cd zentaoxx/misc; php cn2tw.php cp misc/en2other.php zentaoxx/misc; cd zentaoxx/misc; php en2other.php ../ diff --git a/extension/xuanxuan/extension/xuan/im/ext/control/chatwithai.php b/extension/xuanxuan/extension/xuan/im/ext/control/chatwithai.php index b1670355e9..3c687870e5 100644 --- a/extension/xuanxuan/extension/xuan/im/ext/control/chatwithai.php +++ b/extension/xuanxuan/extension/xuan/im/ext/control/chatwithai.php @@ -3,7 +3,7 @@ helper::import('../../control.php'); class myIm extends im { - public function chatWithAi($modelId, $userID = 0, $version = '', $device = 'desktop') + public function chatWithAi($modelId, $assistantId, $userID = 0, $version = '', $device = 'desktop') { $user = $this->im->user->getByID($userID); $user->rights = $this->loadModel('user')->authorize($user->account); @@ -31,6 +31,18 @@ class myIm extends im ); }, $context); + if(!empty($assistantId)) + { + $assistant = $this->ai->getAssistantById($assistantId); + if($assistant) + { + array_unshift($context, (object)array( + 'role' => 'system', + 'content' => $assistant->systemMessage, + )); + } + } + $messages = $this->ai->converse($modelId, $context); if(!$messages) diff --git a/xuanxuan/extension/xuan/im/ext/control/getaiassistant.php b/xuanxuan/extension/xuan/im/ext/control/getaiassistant.php new file mode 100644 index 0000000000..6052216fb6 --- /dev/null +++ b/xuanxuan/extension/xuan/im/ext/control/getaiassistant.php @@ -0,0 +1,17 @@ +loadModel('ai')->getAssistantsByModel($modelId); + + $output = new stdclass(); + $output->method = 'getaiassistant'; + $output->result = 'success'; + $output->data = $assistants; + + return $this->im->sendOutput($output, 'getaiassistantResponse'); + } +} \ No newline at end of file