From 7e7d5121fbc0569d76cbdf7c073846852a52e54f Mon Sep 17 00:00:00 2001 From: liwenrui Date: Tue, 6 Jun 2023 13:30:17 +0800 Subject: [PATCH] * seperate view and edit pages of language model parameters, part of task #94375. --- module/ai/control.php | 73 +++++++++++++++++++++++++++ module/ai/lang/de.php | 4 +- module/ai/lang/en.php | 4 +- module/ai/lang/fr.php | 4 +- module/ai/lang/zh-cn.php | 2 + module/ai/view/editmodel.html.php | 66 +++++++++++++++++++++++++ module/ai/view/models.html.php | 82 ++++++++++++------------------- 7 files changed, 181 insertions(+), 54 deletions(-) create mode 100644 module/ai/control.php create mode 100644 module/ai/view/editmodel.html.php diff --git a/module/ai/control.php b/module/ai/control.php new file mode 100644 index 0000000000..13f1261c60 --- /dev/null +++ b/module/ai/control.php @@ -0,0 +1,73 @@ + + * @package ai + * @link http://www.zentao.net + */ +class ai extends control +{ + /** + * List models. + * + * TODO: not fully implemented yet, currently shows the only model config. + * + * @access public + * @return void + */ + public function models() + { + $modelConfig = new stdclass(); + $modelConfig->type = ''; + $modelConfig->key = ''; + $modelConfig->proxyType = ''; + $modelConfig->proxyAddr = ''; + $modelConfig->description = ''; + $modelConfig->status = ''; + + $storedModelConfig = $this->loadModel('setting')->getItems('owner=system&module=ai'); + foreach($storedModelConfig as $item) $modelConfig->{$item->key} = $item->value; + + $this->view->modelConfig = $modelConfig; + $this->view->title = $this->lang->ai->models->title; + $this->view->position[] = $this->lang->ai->models->common; + $this->display(); + } + + /** + * Edit model configuration, store in system.ai settings. + * + * @access public + * @return void + */ + public function editModel() + { + if(strtolower($this->server->request_method) == 'post') + { + $modelConfig = fixer::input('post')->get(); + $this->loadModel('setting')->setItems('system.ai', $modelConfig); + + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->inlink('models') . '#app=admin')); + } + + $modelConfig = new stdclass(); + $modelConfig->type = ''; + $modelConfig->key = ''; + $modelConfig->proxyType = ''; + $modelConfig->proxyAddr = ''; + $modelConfig->description = ''; + $modelConfig->status = ''; + + $storedModelConfig = $this->loadModel('setting')->getItems('owner=system&module=ai'); + foreach($storedModelConfig as $item) $modelConfig->{$item->key} = $item->value; + + $this->view->modelConfig = $modelConfig; + $this->view->title = $this->lang->ai->models->title; + $this->view->position[] = $this->lang->ai->models->common; + $this->display(); + } +} \ No newline at end of file diff --git a/module/ai/lang/de.php b/module/ai/lang/de.php index 89fcab1f34..cda33019e9 100644 --- a/module/ai/lang/de.php +++ b/module/ai/lang/de.php @@ -1,6 +1,6 @@ ai->models->proxyType = 'Proxy Type'; $lang->ai->models->proxyAddr = 'Proxy Address'; $lang->ai->models->description = 'Description'; $lang->ai->models->testConnection = 'Test Connection'; +$lang->ai->models->unconfigured = 'Unconfigured'; +$lang->ai->models->edit = 'Edit Parameters'; $lang->ai->models->statusList = array(); $lang->ai->models->statusList['on'] = 'Enable'; diff --git a/module/ai/lang/en.php b/module/ai/lang/en.php index 89fcab1f34..2fe15ab1c4 100644 --- a/module/ai/lang/en.php +++ b/module/ai/lang/en.php @@ -1,6 +1,6 @@ ai->models->proxyType = 'Proxy Type'; $lang->ai->models->proxyAddr = 'Proxy Address'; $lang->ai->models->description = 'Description'; $lang->ai->models->testConnection = 'Test Connection'; +$lang->ai->models->unconfigured = 'Unconfigured'; +$lang->ai->models->edit = 'Edit Parameters'; $lang->ai->models->statusList = array(); $lang->ai->models->statusList['on'] = 'Enable'; diff --git a/module/ai/lang/fr.php b/module/ai/lang/fr.php index 89fcab1f34..cd112a8169 100644 --- a/module/ai/lang/fr.php +++ b/module/ai/lang/fr.php @@ -1,6 +1,6 @@ ai->models->proxyType = 'Proxy Type'; $lang->ai->models->proxyAddr = 'Proxy Address'; $lang->ai->models->description = 'Description'; $lang->ai->models->testConnection = 'Test Connection'; +$lang->ai->models->unconfigured = 'Unconfigured'; +$lang->ai->models->edit = 'Edit Parameters'; $lang->ai->models->statusList = array(); $lang->ai->models->statusList['on'] = 'Enable'; diff --git a/module/ai/lang/zh-cn.php b/module/ai/lang/zh-cn.php index 6815d6021a..bb5bbb70ad 100644 --- a/module/ai/lang/zh-cn.php +++ b/module/ai/lang/zh-cn.php @@ -25,6 +25,8 @@ $lang->ai->models->proxyType = '代理类型'; $lang->ai->models->proxyAddr = '代理地址'; $lang->ai->models->description = '描述'; $lang->ai->models->testConnection = '测试连接'; +$lang->ai->models->unconfigured = '未配置'; +$lang->ai->models->edit = '编辑模型参数'; $lang->ai->models->statusList = array(); $lang->ai->models->statusList['on'] = '启用'; diff --git a/module/ai/view/editmodel.html.php b/module/ai/view/editmodel.html.php new file mode 100644 index 0000000000..c9819dadcf --- /dev/null +++ b/module/ai/view/editmodel.html.php @@ -0,0 +1,66 @@ + + * @package ai + * @link https://www.zentao.net + */ +?> + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
ai->models->type;?>
ai->models->typeList, $modelConfig->type, "class='form-control chosen'");?>
ai->models->apiKey;?>
key, "class='form-control'");?>
ai->models->proxyType;?> +
+
+
+ ai->models->proxyTypes, $modelConfig->proxyType, "class='form-control chosen' data-disable_search='true'");?> +
+
proxyType)) echo 'style="display: none;"'; ?>> +
+
ai->models->proxyAddr;?>
+
proxyAddr, "class='form-control'");?>
+
+
+
+
ai->models->description;?>description, "class='form-control'");?>
statusAB;?>ai->models->statusList, empty($modelConfig->status) ? 'on' : $modelConfig->status);?>
+ + ai->models->testConnection, '', 'btn btn-secondary btn-wide');?> +
+
+
+ + diff --git a/module/ai/view/models.html.php b/module/ai/view/models.html.php index afcca441b5..596ec43b42 100644 --- a/module/ai/view/models.html.php +++ b/module/ai/view/models.html.php @@ -11,56 +11,36 @@ ?>
-
- - - - - - - - - - - - - - - - - - - - - - - - -
ai->models->type;?>
ai->models->typeList, $modelConfig->type, "class='form-control chosen'");?>
ai->models->apiKey;?>
key, "class='form-control'");?>
ai->models->proxyType;?> -
-
-
- ai->models->proxyTypes, $modelConfig->proxyType, "class='form-control chosen' data-disable_search='true'");?> -
-
proxyType)) echo 'style="display: none;"'; ?>> -
-
ai->models->proxyAddr;?>
-
proxyAddr, "class='form-control'");?>
-
-
-
-
ai->models->description;?>description, "class='form-control'");?>
statusAB;?>ai->models->statusList, empty($modelConfig->status) ? 'on' : $modelConfig->status);?>
- - ai->models->testConnection, '', 'btn btn-secondary btn-wide');?> -
-
+ + + + + + + + + + + + + + proxyType)) echo 'style="display: none;"'; ?>> + + + + + + + + + + + + + + +
ai->models->type;?>ai->models->typeList, $modelConfig->type, $lang->ai->models->unconfigured);?>
ai->models->apiKey;?>key;?>
ai->models->proxyType;?>ai->models->proxyTypes, $modelConfig->proxyType, $lang->ai->models->unconfigured);?>
ai->models->proxyAddr;?>proxyAddr;?>
ai->models->description;?>description;?>
statusAB;?>ai->models->statusList, $modelConfig->status, $lang->ai->models->statusList['off']);?>
+ ai->models->edit, inlink('editmodel') . '#app=admin', 'self', '', 'btn btn-primary btn-wide');?> +
-