diff --git a/module/group/lang/de.php b/module/group/lang/de.php index 282c1f97e0..f96469f0f9 100644 --- a/module/group/lang/de.php +++ b/module/group/lang/de.php @@ -554,6 +554,7 @@ $lang->group->package->deleteRoadmap = 'Delete Roadmap'; $lang->group->package->deleteDemandPool = 'Delete Demand Pool'; $lang->group->package->exportDatatable = 'Export Datatable'; $lang->group->package->ai = 'AI'; +$lang->group->package->aiChatting = 'AI Chat'; $lang->group->package->executePrompt = 'Execute Prompts'; $lang->group->package->manageLLM = 'Manage Models'; $lang->group->package->browsePrompt = 'Browse Prompts'; diff --git a/module/group/lang/en.php b/module/group/lang/en.php index 941b43fcab..6535c40483 100644 --- a/module/group/lang/en.php +++ b/module/group/lang/en.php @@ -558,6 +558,7 @@ $lang->group->package->deleteRoadmap = 'Delete Roadmap'; $lang->group->package->deleteDemandPool = 'Delete Demand Pool'; $lang->group->package->exportDatatable = 'Export Datatable'; $lang->group->package->ai = 'AI'; +$lang->group->package->aiChatting = 'AI Chat'; $lang->group->package->executePrompt = 'Execute Prompts'; $lang->group->package->manageLLM = 'Manage Models'; $lang->group->package->browsePrompt = 'Browse Prompts'; diff --git a/module/group/lang/fr.php b/module/group/lang/fr.php index c7b9158e50..5d3c72e796 100644 --- a/module/group/lang/fr.php +++ b/module/group/lang/fr.php @@ -554,6 +554,7 @@ $lang->group->package->deleteRoadmap = 'Delete Roadmap'; $lang->group->package->deleteDemandPool = 'Delete Demand Pool'; $lang->group->package->exportDatatable = 'Export Datatable'; $lang->group->package->ai = 'AI'; +$lang->group->package->aiChatting = 'AI Chat'; $lang->group->package->executePrompt = 'Execute Prompts'; $lang->group->package->manageLLM = 'Manage Models'; $lang->group->package->browsePrompt = 'Browse Prompts'; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index 3a3c441397..751348074e 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -1860,6 +1860,7 @@ $lang->resource->ai->prompts = 'promptBrowse'; $lang->resource->ai->promptView = 'promptView'; $lang->resource->ai->promptExecute = 'promptExecute'; $lang->resource->ai->promptExecutionReset = 'promptExecutionReset'; +$lang->resource->ai->chat = 'chat'; $lang->api->methodOrder[0] = 'index'; $lang->api->methodOrder[5] = 'createLib'; diff --git a/module/group/lang/zh-cn.php b/module/group/lang/zh-cn.php index 4f880f78ff..e38d87f5c0 100644 --- a/module/group/lang/zh-cn.php +++ b/module/group/lang/zh-cn.php @@ -558,6 +558,7 @@ $lang->group->package->deleteRoadmap = '删除产品路标'; $lang->group->package->deleteDemandPool = '删除需求池'; $lang->group->package->exportDatatable = '导出数据表'; $lang->group->package->ai = 'AI'; +$lang->group->package->aiChatting = 'AI 聊天'; $lang->group->package->executePrompt = '执行提词'; $lang->group->package->manageLLM = '语言模型管理'; $lang->group->package->browsePrompt = '浏览提词'; diff --git a/module/group/packagemanager.php b/module/group/packagemanager.php index a80f3f7743..ef7696cab6 100644 --- a/module/group/packagemanager.php +++ b/module/group/packagemanager.php @@ -3774,6 +3774,12 @@ $config->group->package->exportDatatable->subset = 'dataview'; $config->group->package->exportDatatable->privs = array(); $config->group->package->exportDatatable->privs['dataview-export'] = array('edition' => 'biz,max,ipd', 'vision' => 'rnd', 'order' => 30, 'depend' => array('dataview-browse', 'dataview-query'), 'recommend' => array()); +$config->group->package->aiChatting = new stdclass(); +$config->group->package->aiChatting->order = 2020; +$config->group->package->aiChatting->subset = 'ai'; +$config->group->package->aiChatting->privs = array(); +$config->group->package->aiChatting->privs['ai-chat'] = array('edition' => 'open,biz,max,ipd', 'vision' => 'rnd,lite,or', 'order' => 10, 'depend' => array(), 'recommend' => array()); + $config->group->package->executePrompt = new stdclass(); $config->group->package->executePrompt->order = 2040; $config->group->package->executePrompt->subset = 'ai'; From 9fee9e10748632abd2dd396cfacee3e99e31db9f Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 1 Nov 2023 14:55:57 +0800 Subject: [PATCH 02/23] * fix chatting with baidu ernie. --- module/ai/config.php | 4 ++-- module/ai/model.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/module/ai/config.php b/module/ai/config.php index b8f1f1af96..9b84ceb986 100644 --- a/module/ai/config.php +++ b/module/ai/config.php @@ -57,9 +57,9 @@ $config->ai->ernie->params = new stdclass(); $config->ai->ernie->params->chat = new stdclass(); $config->ai->ernie->params->function = new stdclass(); $config->ai->ernie->params->chat->required = array('messages'); -$config->ai->ernie->params->chat->optional = array('temperature', 'top_p', 'penalty_score', 'stream', 'user_id'); +$config->ai->ernie->params->chat->optional = array('temperature', 'top_p', 'penalty_score', 'stream', 'system', 'user_id'); $config->ai->ernie->params->function->required = array('messages', 'functions'); -$config->ai->ernie->params->function->optional = array('temperature', 'top_p', 'penalty_score', 'stream', 'user_id'); +$config->ai->ernie->params->function->optional = array('temperature', 'top_p', 'penalty_score', 'stream', 'system', 'user_id'); $config->ai->ernie->model = new stdclass(); $config->ai->ernie->model->chat = 'ernie-bot-turbo'; diff --git a/module/ai/model.php b/module/ai/model.php index 4d605d7281..04b1606b22 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -469,6 +469,15 @@ class aiModel extends model */ public function converse($messages, $options = array()) { + /* Filter system message out for ERNIE. */ + if($this->config->ai->models[$this->modelConfig->type] == 'ernie') + { + $systemMessage = current(array_filter($messages, function($message) { return $message->role == 'system'; })); + if(!empty($systemMessage)) $options['system'] = $systemMessage->content; + + $messages = array_values(array_filter($messages, function($message) { return $message->role == 'assistant' || $message->role == 'user'; })); + } + $data = compact('messages'); if(!empty($options)) From 5c79bbfa8d75efe41e3f1a38eed041ccd0ed8cab Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 1 Nov 2023 15:15:29 +0800 Subject: [PATCH 03/23] * use stored azure cred. --- module/ai/config.php | 4 ++-- module/ai/model.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module/ai/config.php b/module/ai/config.php index 9b84ceb986..a0e49248ec 100644 --- a/module/ai/config.php +++ b/module/ai/config.php @@ -15,8 +15,8 @@ $config->ai->openai->api->openai->version = 'v1'; / $config->ai->openai->api->openai->format = 'https://api.openai.com/%s/%s'; // OpenAI API format, args: API version, API name. $config->ai->openai->api->openai->authFormat = 'Authorization: Bearer %s'; // OpenAI API auth header format. $config->ai->openai->api->azure = new stdclass(); -$config->ai->openai->api->azure->resource = 'openai-at-zentao'; // your Azure OpenAI resource name, required. -$config->ai->openai->api->azure->deployment = 'the-first-gpt'; // your Azure OpenAI deployment name, required. +$config->ai->openai->api->azure->resource = ''; // Azure OpenAI resource name, required. +$config->ai->openai->api->azure->deployment = ''; // Azure OpenAI deployment name, required. $config->ai->openai->api->azure->apiVersion = '2023-07-01-preview'; // Azure OpenAI API version, required. $config->ai->openai->api->azure->format = 'https://%s.openai.azure.com/openai/deployments/%s/%s?api-version=%s'; // Azure API format, args: resource name, deployment name, API name, API version. $config->ai->openai->api->azure->authFormat = 'api-key: %s'; // Azure API auth header format. diff --git a/module/ai/model.php b/module/ai/model.php index 04b1606b22..3fcf5ad837 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -96,7 +96,7 @@ class aiModel extends model { if($modelVendor == 'azure') { - $url = sprintf($this->config->ai->openai->api->azure->format, $this->config->ai->openai->api->azure->resource, $this->config->ai->openai->api->azure->deployment, $this->config->ai->openai->api->methods[$type], $this->config->ai->openai->api->azure->apiVersion); + $url = sprintf($this->config->ai->openai->api->azure->format, $this->modelConfig->resource, $this->modelConfig->deployment, $this->config->ai->openai->api->methods[$type], $this->config->ai->openai->api->azure->apiVersion); } else { From e14cfdcebb003a37e26adc4f8251d3f268fc7f93 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Mon, 6 Nov 2023 16:27:13 +0800 Subject: [PATCH 04/23] * merge ai chat with xuan. --- module/index/lang/de.php | 4 + module/index/lang/en.php | 4 + module/index/lang/fr.php | 4 + module/index/lang/vi.php | 4 + module/index/lang/zh-cn.php | 4 + module/index/lang/zh-tw.php | 4 + module/index/view/chatview.html.php | 89 +++++++++++++++++++ module/index/view/index.html.php | 1 + .../ext/view/index.xuanxuan.html.hook.php | 13 --- 9 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 module/index/view/chatview.html.php diff --git a/module/index/lang/de.php b/module/index/lang/de.php index 4f1d780868..1179993a12 100644 --- a/module/index/lang/de.php +++ b/module/index/lang/de.php @@ -15,3 +15,7 @@ $lang->index->upgrade = 'Upgrade'; $lang->index->log = 'Log'; $lang->index->detailed = 'Details'; $lang->index->website = 'Please visit the official website'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = 'Chat'; +$lang->index->chat->ai = 'AI'; diff --git a/module/index/lang/en.php b/module/index/lang/en.php index b2b1f44449..ff408d4072 100644 --- a/module/index/lang/en.php +++ b/module/index/lang/en.php @@ -15,3 +15,7 @@ $lang->index->upgrade = 'Upgrade'; $lang->index->log = 'Log'; $lang->index->detailed = 'Details'; $lang->index->website = 'Visit ZenTao official website'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = 'Chat'; +$lang->index->chat->ai = 'AI'; diff --git a/module/index/lang/fr.php b/module/index/lang/fr.php index 4f1d780868..1179993a12 100644 --- a/module/index/lang/fr.php +++ b/module/index/lang/fr.php @@ -15,3 +15,7 @@ $lang->index->upgrade = 'Upgrade'; $lang->index->log = 'Log'; $lang->index->detailed = 'Details'; $lang->index->website = 'Please visit the official website'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = 'Chat'; +$lang->index->chat->ai = 'AI'; diff --git a/module/index/lang/vi.php b/module/index/lang/vi.php index 4f1d780868..1179993a12 100644 --- a/module/index/lang/vi.php +++ b/module/index/lang/vi.php @@ -15,3 +15,7 @@ $lang->index->upgrade = 'Upgrade'; $lang->index->log = 'Log'; $lang->index->detailed = 'Details'; $lang->index->website = 'Please visit the official website'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = 'Chat'; +$lang->index->chat->ai = 'AI'; diff --git a/module/index/lang/zh-cn.php b/module/index/lang/zh-cn.php index 823c4281b4..bca9b500c8 100644 --- a/module/index/lang/zh-cn.php +++ b/module/index/lang/zh-cn.php @@ -15,3 +15,7 @@ $lang->index->upgrade = '升级'; $lang->index->log = '查看版本更新日志 >'; $lang->index->detailed = '详情'; $lang->index->website = '请访问官网'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = '聊天'; +$lang->index->chat->ai = 'AI 对话'; diff --git a/module/index/lang/zh-tw.php b/module/index/lang/zh-tw.php index d28d0333ca..23648b7d03 100644 --- a/module/index/lang/zh-tw.php +++ b/module/index/lang/zh-tw.php @@ -15,3 +15,7 @@ $lang->index->upgrade = '升級'; $lang->index->log = '查看版本更新日誌 >'; $lang->index->detailed = '詳情'; $lang->index->website = '請訪問官網'; + +$lang->index->chat = new stdclass(); +$lang->index->chat->chat = '聊天'; +$lang->index->chat->ai = 'AI 對話'; diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php new file mode 100644 index 0000000000..e395a0aea8 --- /dev/null +++ b/module/index/view/chatview.html.php @@ -0,0 +1,89 @@ + + * @package index + * @link https://www.zentao.net + */ +?> + + + diff --git a/module/index/view/index.html.php b/module/index/view/index.html.php index 32777b58d2..eadd67a4ba 100644 --- a/module/index/view/index.html.php +++ b/module/index/view/index.html.php @@ -152,6 +152,7 @@ js::set('showFeatures', $showFeatures); + searchAB);?> searchObjects)) . ',');?> index->search);?> diff --git a/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php b/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php index b9c0fb5e72..030c11722d 100644 --- a/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php +++ b/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php @@ -96,21 +96,8 @@ Xuanxuan.setGlobalOptions( lang: lang }); -$(function() { - /* Create chat button */ - var $chatBtn = $(''); - $chatBtn.insertBefore('#globalSearchDiv').on('click', toggleXuanClient); -}); - /* Create client instance */ window.xuan = new Xuanxuan(xuanConfig); - -/* Hide xuan popover on click page */ -$(document).on('click', function(e) -{ - if(!window.xuan.shown || $(e.target).closest('#xx-embed-container,#chatBtn').length) return; - window.xuan.hide(); -}); From 8da88e8bc84288f8a1187c4fb1dd3e7b3debaf5a Mon Sep 17 00:00:00 2001 From: liwenrui Date: Mon, 6 Nov 2023 16:44:35 +0800 Subject: [PATCH 05/23] * widen chat area. --- module/index/view/chatview.html.php | 21 ++++++++++--------- .../ext/view/index.xuanxuan.html.hook.php | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php index e395a0aea8..c8a3ae0d3c 100644 --- a/module/index/view/chatview.html.php +++ b/module/index/view/chatview.html.php @@ -12,20 +12,20 @@
@@ -49,16 +49,17 @@ { clearInterval(xuanFrameWaitLoop); tries = 0; - const chatsMenuWaitLoop = setInterval(function() + const chatsViewWaitLoop = setInterval(function() { if(document.querySelector('#xx-embed-container iframe').contentDocument.querySelector('.app-chats-menu')) { - clearInterval(chatsMenuWaitLoop); - document.querySelector('#xx-embed-container iframe').contentDocument.querySelector('.app-chats-menu').style.top = '48px'; + clearInterval(chatsViewWaitLoop); + document.querySelector('#xx-embed-container iframe').contentDocument.querySelector('.app-chats-menu').style.cssText = 'width: 330px !important; top: 48px;'; + document.querySelector('#xx-embed-container iframe').contentDocument.querySelector('.app-chats-cache').style.cssText = 'right: 330px !important;'; } else { - if(++tries > 20) clearInterval(chatsMenuWaitLoop); + if(++tries > 20) clearInterval(chatsViewWaitLoop); } }, 200); } diff --git a/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php b/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php index 030c11722d..f4b1058550 100644 --- a/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php +++ b/xuanxuan/extension/xuan/index/ext/view/index.xuanxuan.html.hook.php @@ -54,9 +54,9 @@ if(isset($this->config->xuanxuan->turnon) && $this->config->xuanxuan->turnon && #chatNoticeBadge.show {opacity: 1; transform: scale(1);} #xx-embed-container {bottom: 40px!important; z-index: 1010!important;} #xx-embed-container .xx-embed-has-animation {transition: min-width .5s ease-out, min-height .5s ease-out, transform, opacity!important;} -#xx-embed-container .xx-embed {width: 280px; height: 100%; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)!important;} +#xx-embed-container .xx-embed {width: 330px; height: 100%; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)!important;} #xx-embed-container .xx-embed.xx-embed-hidden, -#xx-embed-container .xx-embed.xx-embed-collapsed {width: 280px!important; height: 100%!important; opacity: .7; pointer-events: none; transform: translateY(100%); display: block!important;} +#xx-embed-container .xx-embed.xx-embed-collapsed {width: 330px!important; height: 100%!important; opacity: .7; pointer-events: none; transform: translateY(100%); display: block!important;} #xx-embed-container .xx-embed.has-chat-view {min-width: 1000px!important;} #xx-embed-container .xx-embed-body {min-height: initial!important;} @@ -88,7 +88,7 @@ function handleXuanRouteChange(route) Xuanxuan.setGlobalOptions( { position: 'right', - width: 280, + width: 330, preload: true, showHeader: false, onNotice: handleXuanNoticeChange, From 3d43ef1367958d841ddceb85565fd1d82d3f9473 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Mon, 6 Nov 2023 17:16:11 +0800 Subject: [PATCH 06/23] * show help for unconfigured chat views. --- module/index/lang/de.php | 3 +++ module/index/lang/en.php | 3 +++ module/index/lang/fr.php | 3 +++ module/index/lang/vi.php | 3 +++ module/index/lang/zh-cn.php | 3 +++ module/index/lang/zh-tw.php | 3 +++ module/index/view/chatview.html.php | 13 +++++++++++-- 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/module/index/lang/de.php b/module/index/lang/de.php index 1179993a12..7dc0fc1256 100644 --- a/module/index/lang/de.php +++ b/module/index/lang/de.php @@ -19,3 +19,6 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; +$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; +$lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; diff --git a/module/index/lang/en.php b/module/index/lang/en.php index ff408d4072..46dfdb1722 100644 --- a/module/index/lang/en.php +++ b/module/index/lang/en.php @@ -19,3 +19,6 @@ $lang->index->website = 'Visit ZenTao official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; +$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; +$lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; diff --git a/module/index/lang/fr.php b/module/index/lang/fr.php index 1179993a12..7dc0fc1256 100644 --- a/module/index/lang/fr.php +++ b/module/index/lang/fr.php @@ -19,3 +19,6 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; +$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; +$lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; diff --git a/module/index/lang/vi.php b/module/index/lang/vi.php index 1179993a12..7dc0fc1256 100644 --- a/module/index/lang/vi.php +++ b/module/index/lang/vi.php @@ -19,3 +19,6 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; +$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; +$lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; diff --git a/module/index/lang/zh-cn.php b/module/index/lang/zh-cn.php index bca9b500c8..4c7f554d6f 100644 --- a/module/index/lang/zh-cn.php +++ b/module/index/lang/zh-cn.php @@ -19,3 +19,6 @@ $lang->index->website = '请访问官网'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = '聊天'; $lang->index->chat->ai = 'AI 对话'; +$lang->index->chat->unconfiguredFormat = '尚未配置 %s 功能,%s。'; +$lang->index->chat->goConfigureFormat = '点击前往 %s 配置页面 进行功能配置'; +$lang->index->chat->contactAdminForHelp = '请联系管理员进行功能配置'; diff --git a/module/index/lang/zh-tw.php b/module/index/lang/zh-tw.php index 23648b7d03..dff0ce4fa4 100644 --- a/module/index/lang/zh-tw.php +++ b/module/index/lang/zh-tw.php @@ -19,3 +19,6 @@ $lang->index->website = '請訪問官網'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = '聊天'; $lang->index->chat->ai = 'AI 對話'; +$lang->index->chat->unconfiguredFormat = '尚未配置 %s 功能,%s。'; +$lang->index->chat->goConfigureFormat = '點擊前往 %s 配置頁面 進行功能配置'; +$lang->index->chat->contactAdminForHelp = '請聯繫管理員進行功能配置'; diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php index c8a3ae0d3c..47e8ba6a06 100644 --- a/module/index/view/chatview.html.php +++ b/module/index/view/chatview.html.php @@ -20,6 +20,7 @@ #xuan-chat-view #xx-embed-container {position: absolute; bottom: 0; left: 0; right: 0; top: 0;} #ai-chat-view {position: fixed; right: 0; width: 330px; bottom: 40px; top: 50px; outline: 1px solid #eee;} #ai-chat-frame {height: 100%; width: 100%;} + .unconfigured {position: absolute; width: 330px; padding: 20px; right: 0; top: 50px; bottom: 0; background: #fff; outline: 1px solid #eee;}
@@ -28,9 +29,17 @@ index->chat->ai; ?>
-
+
+ config->xuanxuan->turnon) || !$this->config->xuanxuan->turnon || $this->loadModel('im')->getXxdStatus() != 'online'): ?> +
index->chat->unconfiguredFormat, $lang->index->chat->chat, (common::hasPriv('setting', 'xuanxuan') ? sprintf($lang->index->chat->goConfigureFormat, helper::createLink('setting', 'xuanxuan'), $lang->index->chat->chat) : $lang->index->chat->contactAdminForHelp)); ?>
+ +
- + loadModel('ai')->isModelConfigured() && commonModel::hasPriv('ai', 'chat')): ?> + + +
index->chat->unconfiguredFormat, $lang->index->chat->ai, (common::hasPriv('ai', 'models') ? sprintf($lang->index->chat->goConfigureFormat, helper::createLink('ai', 'models'), $lang->index->chat->ai) : $lang->index->chat->contactAdminForHelp)); ?>
+
From 36323d82f11d85136c6d9c81730007d0573b4982 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 08:44:35 +0800 Subject: [PATCH 17/23] * tweak chat reset button styles. --- module/ai/css/chat.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module/ai/css/chat.css b/module/ai/css/chat.css index 14b303f331..18cf44c8d2 100644 --- a/module/ai/css/chat.css +++ b/module/ai/css/chat.css @@ -12,14 +12,14 @@ body {background-color: #fff; background-image: url("data:image/svg+xml,%3csvg x .message-container-assistant .message-content {background: #f1f1f1; padding: 8px; border-radius: 8px 8px 8px 0;} .message-container-error .message-content {background: #ffdddd; padding: 2px 8px; border-radius: 8px;} -.chat-input {display: flex; justify-content: space-between; bottom: 0; width: calc(100% - 16px); margin: 8px;} +.chat-input {display: flex; justify-content: space-between; align-items: flex-end; bottom: 0; width: calc(100% - 16px); margin: 8px;} .chat-input textarea {flex: 1; margin-right: 4px; line-height: 1.5; height: 40px; min-height: 40px; padding: 9px 36px 9px 12px; border: 1px solid transparent; border-radius: 8px; background: linear-gradient(#fff, #fff) padding-box, linear-gradient(225deg, #ff2070, #9670ff, #258dff) border-box; outline: none; -webkit-appearance: none; -moz-appearance: none; appearance: none; resize: none;} .chat-input input[type=submit] {position: absolute; left: 236px; bottom: 12px; width: 40px; height: 40px; padding: 0; border: none; border-radius: 4px; outline: none; background: linear-gradient(225deg, #ff2070, #9670ff, #258dff); mask-image: url('data:image/svg+xml;utf8,'); -webkit-mask-image: url('data:image/svg+xml;utf8,'); mask-position: center; -webkit-mask-position: center; mask-origin: padding-box; -webkit-mask-origin: padding-box; background-repeat: no-repeat; background-position: center; background-size: 16px 15px; mask-size: 16px 15px; -webkit-mask-size: 16px 15px; cursor: pointer;} .chat-input input[type=submit].disabled {cursor: unset; opacity: 0.5;} .chat-input input[type=submit]:not(.disabled):hover {transform: scale(1.1);} .chat-input textarea.has-scrollbar + input[type=submit] {left: 228px; width: 36px; mask-position: 20px 12.5px; -webkit-mask-position: 20px 12.5px; background-position: 20px 12.5px;} .chat-input textarea.busy, .chat-input input[type=submit].busy {cursor: wait; opacity: 0.5;} -#reset {border: none; background: none; color: #9ea3b0; border-radius: 4px;} +#reset {height: 40px; border: none; background: none; color: #9ea3b0; border-radius: 4px;} #reset.disabled {cursor: unset; opacity: 0.5;} #reset:not(.disabled):hover {color: #737a8c;} #reset.busy, #retry.busy {cursor: wait; opacity: 0.5;} From 7c090149c6aab0eaf4c223991d4f2068c30d85ce Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 09:57:59 +0800 Subject: [PATCH 18/23] * add backdrop click handler to hide chat view. --- module/index/view/chatview.html.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php index 76d08db65f..1be28d9dbb 100644 --- a/module/index/view/chatview.html.php +++ b/module/index/view/chatview.html.php @@ -120,5 +120,13 @@ /* Switch to xuan chat view if AI is unavailable. */ if(isXuanAvailable && !(isAIConfigured && hasAIChatPriv)) $('#chat-switch .chat-switch-item[data-value="chat"]').trigger('click'); + + /* Handle backdrop click, hide chat view. */ + $(document).on('click', function(e) + { + if($('#chat-container').is(':hidden')) return; + if($(e.target).closest('#chat-switch,#ai-chat-view,#xx-embed,#chatBtn').length) return; + $('#chat-container').hide(); + }); }); From f19f0c325d207670d0dd58597a4076b6d52f6fd8 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 11:04:07 +0800 Subject: [PATCH 19/23] * check if model is enabled when checking ai configurations. --- module/ai/model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/ai/model.php b/module/ai/model.php index 3fcf5ad837..9bf5f87ae1 100644 --- a/module/ai/model.php +++ b/module/ai/model.php @@ -65,7 +65,7 @@ class aiModel extends model $modelConfig = new stdclass(); $storedModelConfig = $this->loadModel('setting')->getItems('owner=system&module=ai'); foreach($storedModelConfig as $item) $modelConfig->{$item->key} = $item->value; - return !empty($modelConfig->key); + return $modelConfig->status == 'on' && !empty($modelConfig->key); } /** From 0541236ccd91a5a437c98590583296decdba6529 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 11:08:14 +0800 Subject: [PATCH 20/23] * skip submitting form when input is marked busy. --- module/ai/js/chat.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/module/ai/js/chat.js b/module/ai/js/chat.js index 0586f338a7..9882c8aac7 100644 --- a/module/ai/js/chat.js +++ b/module/ai/js/chat.js @@ -47,6 +47,8 @@ $(function() /* Send message on enter, allowing linebreak inputs. */ if((e.keyCode == 13 || e.keyCode == 10)) { + if($(this).hasClass('busy')) return; + if(e.ctrlKey || e.metaKey) { $('textarea[name=message]').val($('textarea[name=message]').val() + '\n'); From 1780c0730431a09dea575272d017c2a4645f8ddd Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 11:15:29 +0800 Subject: [PATCH 21/23] * fix typo in formatter. --- module/index/lang/de.php | 2 +- module/index/lang/en.php | 2 +- module/index/lang/fr.php | 2 +- module/index/lang/vi.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/index/lang/de.php b/module/index/lang/de.php index 0de4c10559..d053c1d1f5 100644 --- a/module/index/lang/de.php +++ b/module/index/lang/de.php @@ -19,7 +19,7 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; -$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->unconfiguredFormat = '%s is currently not configured. %s.'; $lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; $lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; $lang->index->chat->unauthorized = 'You are not authorized to access AI chatting. Please contact an administrator for permission.'; diff --git a/module/index/lang/en.php b/module/index/lang/en.php index 4a6aceab4d..7af2e9d11c 100644 --- a/module/index/lang/en.php +++ b/module/index/lang/en.php @@ -19,7 +19,7 @@ $lang->index->website = 'Visit ZenTao official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; -$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->unconfiguredFormat = '%s is currently not configured. %s.'; $lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; $lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; $lang->index->chat->unauthorized = 'You are not authorized to access AI chatting. Please contact an administrator for permission.'; diff --git a/module/index/lang/fr.php b/module/index/lang/fr.php index 0de4c10559..d053c1d1f5 100644 --- a/module/index/lang/fr.php +++ b/module/index/lang/fr.php @@ -19,7 +19,7 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; -$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->unconfiguredFormat = '%s is currently not configured. %s.'; $lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; $lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; $lang->index->chat->unauthorized = 'You are not authorized to access AI chatting. Please contact an administrator for permission.'; diff --git a/module/index/lang/vi.php b/module/index/lang/vi.php index 0de4c10559..d053c1d1f5 100644 --- a/module/index/lang/vi.php +++ b/module/index/lang/vi.php @@ -19,7 +19,7 @@ $lang->index->website = 'Please visit the official website'; $lang->index->chat = new stdclass(); $lang->index->chat->chat = 'Chat'; $lang->index->chat->ai = 'AI'; -$lang->index->chat->unconfiguredFormat = '% is currently not configured. %s.'; +$lang->index->chat->unconfiguredFormat = '%s is currently not configured. %s.'; $lang->index->chat->goConfigureFormat = 'To configure the function, click to navigate to %s configuration'; $lang->index->chat->contactAdminForHelp = 'Please contact an administrator for assistance'; $lang->index->chat->unauthorized = 'You are not authorized to access AI chatting. Please contact an administrator for permission.'; From 5a7c6ec89b40d4195e223563a015523935f69a31 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 11:19:50 +0800 Subject: [PATCH 22/23] * fix ai configure link. --- module/index/view/chatview.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php index 1be28d9dbb..ccaca9e96c 100644 --- a/module/index/view/chatview.html.php +++ b/module/index/view/chatview.html.php @@ -46,7 +46,7 @@
-
index->chat->unconfiguredFormat, $lang->index->chat->ai, (common::hasPriv('ai', 'models') ? sprintf($lang->index->chat->goConfigureFormat, helper::createLink('ai', 'models'), $lang->index->chat->ai) : $lang->index->chat->contactAdminForHelp)); ?>
+
index->chat->unconfiguredFormat, $lang->index->chat->ai, (common::hasPriv('ai', 'models') ? sprintf($lang->index->chat->goConfigureFormat, helper::createLink('ai', 'models') . '#app=admin', $lang->index->chat->ai) : $lang->index->chat->contactAdminForHelp)); ?>
index->chat->unauthorized; ?>
From 24f7e9ef1136ec3e3261743db97a830cdb785f38 Mon Sep 17 00:00:00 2001 From: liwenrui Date: Wed, 8 Nov 2023 11:29:50 +0800 Subject: [PATCH 23/23] * cancel hover color style on chat switches. --- module/index/view/chatview.html.php | 1 + 1 file changed, 1 insertion(+) diff --git a/module/index/view/chatview.html.php b/module/index/view/chatview.html.php index ccaca9e96c..cc8e151201 100644 --- a/module/index/view/chatview.html.php +++ b/module/index/view/chatview.html.php @@ -23,6 +23,7 @@ #chat-switch {position: absolute; width: 330px; height: 52px; right: 0; background: #fff; display: flex; justify-content: center; align-items: center; border-bottom: 1px solid #eee; z-index: 20;} .chat-switch-bg {display: flex; justify-content: center; align-items: center; background-color: #eff5ff; border-radius: 16px;} .chat-switch-item {width: 96px; padding: 4px 0; border-radius: 16px; text-align: center; color: #838a9c; position: relative; user-select: none;} + .chat-switch-item:hover {color: #838a9c;} .chat-switch-item.active {font-weight: bold; color: #fff; background-color: #5999fc;} .chat-switch-item.has-notice::after {content: ''; position: absolute; right: 26px; top: 4px; width: 6px; height: 6px; border-radius: 50%; background-color: #ff535d;} #xuan-chat-view {position: absolute; width: 100%; height: 100%; z-index: 10; display: none;}