+ prompt creation and list, task #94381,94384.

This commit is contained in:
liwenrui
2023-06-15 14:49:59 +08:00
parent 494f896b33
commit 589fd1bd20
11 changed files with 279 additions and 38 deletions
+2
View File
@@ -377,6 +377,8 @@ define('TABLE_PRIVLANG', '`' . $config->db->prefix . 'privlang`');
define('TABLE_PRIVMANAGER', '`' . $config->db->prefix . 'privmanager`');
define('TABLE_PRIVRELATION', '`' . $config->db->prefix . 'privrelation`');
define('TABLE_PROMPT', '`' . $config->db->prefix . 'prompt`');
$config->objectTables['product'] = TABLE_PRODUCT;
$config->objectTables['productplan'] = TABLE_PRODUCTPLAN;
$config->objectTables['story'] = TABLE_STORY;
+23
View File
@@ -0,0 +1,23 @@
CREATE TABLE IF NOT EXISTS `zt_prompt` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`desc` text DEFAULT NULL,
`model` mediumint(8) unsigned DEFAULT NULL,
`module` varchar(30) DEFAULT NULL,
`source` text DEFAULT NULL,
`targetForm` varchar(30) DEFAULT NULL,
`purpose` text DEFAULT NULL,
`elaboration` text DEFAULT NULL,
`role` text DEFAULT NULL,
`characterization` text DEFAULT NULL,
`status` enum('draft','active','replaced') NOT NULL DEFAULT 'draft',
`parent` mediumint(8) unsigned DEFAULT NULL,
`successor` mediumint(8) unsigned DEFAULT NULL,
`revision` mediumint(8) unsigned DEFAULT NULL,
`createdBy` varchar(30) NOT NULL,
`createdDate` datetime NOT NULL,
`editedBy` varchar(30) DEFAULT NULL,
`editedDate` datetime DEFAULT NULL,
`deleted` enum('0','1') NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+3
View File
@@ -29,3 +29,6 @@ foreach($config->ai->openai->contentTypeMapping as $contentType => $apis)
{
foreach($apis as $api) $config->ai->openai->contentType[$api] = $contentType;
}
$config->ai->createprompt = new stdclass();
$config->ai->createprompt->requiredFields = 'name';
+39 -9
View File
@@ -12,9 +12,9 @@ class ai extends control
{
/**
* List models.
*
*
* TODO: not fully implemented yet, currently shows the only model config.
*
*
* @access public
* @return void
*/
@@ -39,7 +39,7 @@ class ai extends control
/**
* Edit model configuration, store in system.ai settings.
*
*
* @access public
* @return void
*/
@@ -73,7 +73,7 @@ class ai extends control
/**
* Test connection to API endpoint.
*
*
* @access public
* @return void
*/
@@ -81,7 +81,7 @@ class ai extends control
{
$modelConfig = fixer::input('post')->get();
$this->ai->setConfig($modelConfig);
$result = $this->ai->complete('test', 1); // Test completing 'test' with length of 1.
if($result === false) return $this->send(array('result' => 'fail', 'message' => $this->lang->ai->models->testConnectionResult->fail));
@@ -90,19 +90,49 @@ class ai extends control
/**
* List prompts.
*
*
* @param string $module
* @param string $status
* @access public
* @return void
*/
public function prompts($module = '', $status = '')
public function prompts($module = '', $status = '', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1)
{
/* Set pager and order. */
$this->app->loadClass('pager', $static = true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$order = common::appendOrder($orderBy);
$this->view->prompts = $this->ai->getPrompts($module, $status, $order, $pager);
$this->view->module = $module;
$this->view->status = $status;
$this->view->prompts = $this->ai->getPrompts($module, $status);
$this->view->orderBy = $orderBy;
$this->view->pager = $pager;
$this->view->title = $this->lang->ai->prompts->common;
$this->view->position[] = $this->lang->ai->prompts->common;
$this->display();
}
/**
* Create a prompt.
*
* @access public
* @return void
*/
public function createPrompt()
{
if(strtolower($this->server->request_method) == 'post')
{
$prompt = fixer::input('post')->get();
$this->ai->createPrompt($prompt);
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
return print(js::closeModal('parent.parent')); // TODO: jump to step 2 of creation process.
}
$this->view->title = $this->lang->ai->prompts->create;
$this->view->position[] = $this->lang->ai->prompts->common;
$this->display();
}
}
}
+18 -4
View File
@@ -10,14 +10,28 @@
*/
$lang->ai->common = 'AI';
/* Definitions of table columns, used to sprintf error messages to dao::$errors. */
$lang->prompt = new stdclass();
$lang->prompt->name = 'Name';
$lang->prompt->desc = 'Description';
$lang->ai->nextStep = 'Next';
$lang->ai->prompts = new stdclass();
$lang->ai->prompts->common = 'Prompts';
$lang->ai->prompts->emptyList = 'There is no prompts yet.';
$lang->ai->prompts->create = 'Create a prompt';
$lang->ai->prompts->common = 'Prompt';
$lang->ai->prompts->emptyList = 'No prompts yet.';
$lang->ai->prompts->create = 'Create Prompt';
$lang->ai->prompts->id = 'ID';
$lang->ai->prompts->name = 'Name';
$lang->ai->prompts->description = 'Description';
$lang->ai->prompts->createdBy = 'Creator';
$lang->ai->prompts->createdDate = 'Created Date';
$lang->ai->prompts->targetForm = 'Target Form';
$lang->ai->prompts->funcDesc = 'Function Description';
$lang->ai->prompts->statuses = array();
$lang->ai->prompts->statuses[''] = 'All';
// $lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->modules = array();
$lang->ai->prompts->modules[''] = 'All';
+18 -4
View File
@@ -10,14 +10,28 @@
*/
$lang->ai->common = 'AI';
/* Definitions of table columns, used to sprintf error messages to dao::$errors. */
$lang->prompt = new stdclass();
$lang->prompt->name = 'Name';
$lang->prompt->desc = 'Description';
$lang->ai->nextStep = 'Next';
$lang->ai->prompts = new stdclass();
$lang->ai->prompts->common = 'Prompts';
$lang->ai->prompts->emptyList = 'There is no prompts yet.';
$lang->ai->prompts->create = 'Create a prompt';
$lang->ai->prompts->common = 'Prompt';
$lang->ai->prompts->emptyList = 'No prompts yet.';
$lang->ai->prompts->create = 'Create Prompt';
$lang->ai->prompts->id = 'ID';
$lang->ai->prompts->name = 'Name';
$lang->ai->prompts->description = 'Description';
$lang->ai->prompts->createdBy = 'Creator';
$lang->ai->prompts->createdDate = 'Created Date';
$lang->ai->prompts->targetForm = 'Target Form';
$lang->ai->prompts->funcDesc = 'Function Description';
$lang->ai->prompts->statuses = array();
$lang->ai->prompts->statuses[''] = 'All';
// $lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->modules = array();
$lang->ai->prompts->modules[''] = 'All';
+18 -4
View File
@@ -10,14 +10,28 @@
*/
$lang->ai->common = 'AI';
/* Definitions of table columns, used to sprintf error messages to dao::$errors. */
$lang->prompt = new stdclass();
$lang->prompt->name = 'Name';
$lang->prompt->desc = 'Description';
$lang->ai->nextStep = 'Next';
$lang->ai->prompts = new stdclass();
$lang->ai->prompts->common = 'Prompts';
$lang->ai->prompts->emptyList = 'There is no prompts yet.';
$lang->ai->prompts->create = 'Create a prompt';
$lang->ai->prompts->common = 'Prompt';
$lang->ai->prompts->emptyList = 'No prompts yet.';
$lang->ai->prompts->create = 'Create Prompt';
$lang->ai->prompts->id = 'ID';
$lang->ai->prompts->name = 'Name';
$lang->ai->prompts->description = 'Description';
$lang->ai->prompts->createdBy = 'Creator';
$lang->ai->prompts->createdDate = 'Created Date';
$lang->ai->prompts->targetForm = 'Target Form';
$lang->ai->prompts->funcDesc = 'Function Description';
$lang->ai->prompts->statuses = array();
$lang->ai->prompts->statuses[''] = 'All';
// $lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->statuses['draft'] = 'Draft';
$lang->ai->prompts->modules = array();
$lang->ai->prompts->modules[''] = 'All';
+18 -4
View File
@@ -10,14 +10,28 @@
*/
$lang->ai->common = 'AI';
/* Definitions of table columns, used to sprintf error messages to dao::$errors. */
$lang->prompt = new stdclass();
$lang->prompt->name = '名称';
$lang->prompt->desc = '描述';
$lang->ai->nextStep = '下一步';
$lang->ai->prompts = new stdclass();
$lang->ai->prompts->common = '提词';
$lang->ai->prompts->emptyList = '暂时没有提词。';
$lang->ai->prompts->create = '创建提词';
$lang->ai->prompts->common = '提词';
$lang->ai->prompts->emptyList = '暂时没有提词。';
$lang->ai->prompts->create = '创建提词';
$lang->ai->prompts->id = 'ID';
$lang->ai->prompts->name = '名称';
$lang->ai->prompts->description = '描述';
$lang->ai->prompts->createdBy = '创建者';
$lang->ai->prompts->createdDate = '创建时间';
$lang->ai->prompts->targetForm = '表单';
$lang->ai->prompts->funcDesc = '功能描述';
$lang->ai->prompts->statuses = array();
$lang->ai->prompts->statuses[''] = '全部';
// $lang->ai->prompts->statuses['draft'] = '草稿';
$lang->ai->prompts->statuses['draft'] = '草稿';
$lang->ai->prompts->modules = array();
$lang->ai->prompts->modules[''] = '所有分组';
+38 -9
View File
@@ -1,7 +1,7 @@
<?php
/**
* The model file of ai module of ZenTaoPMS.
*
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Wenrui LI <liwenrui@easycorp.ltd>
@@ -12,7 +12,7 @@ class aiModel extends model
{
/**
* Model config.
*
*
* @var object
* @access public
*/
@@ -36,7 +36,7 @@ class aiModel extends model
/**
* Set model config, used for testing.
*
*
* @param object $config
* @access public
* @return void
@@ -94,7 +94,7 @@ class aiModel extends model
/**
* Get proxy type.
*
*
* @param string $proxyType
* @access private
* @return int|false
@@ -301,16 +301,45 @@ class aiModel extends model
/**
* Get list of prompts.
*
* TODO: implement this.
*
*
* TODO: fully implement this.
*
* @param string $module
* @param string $status
* @access public
* @return array
*/
public function getPrompts($module = '', $status = '')
public function getPrompts($module = '', $status = '', $order = 'id_desc', $pager = null)
{
return array();
return $this->dao->select('*')->from(TABLE_PROMPT)
->where('1=1')
->beginIF(!empty($module))->andWhere('module')->eq($module)->fi()
->beginIF(!empty($status))->andWhere('status')->eq($status)->fi()
->orderBy($order)
->page($pager)
->fetchAll();
}
/**
* Create a prompt.
*
* TODO: fully implement this.
*
* @param object $prompt
* @access public
* @return int|false returns prompt id on success, false on fail
*/
public function createPrompt($prompt)
{
$prompt->createdDate = helper::now();
$prompt->createdBy = $this->app->user->account;
$this->dao->insert(TABLE_PROMPT)
->data($prompt)
->autoCheck()
->batchCheck($this->config->ai->createprompt->requiredFields, 'notempty')
->exec();
return dao::isError() ? false : $this->dao->lastInsertID();
}
}
+54
View File
@@ -0,0 +1,54 @@
<?php
/**
* The ai createPrompt view file of ai module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Wenrui LI <liwenrui@easycorp.ltd>
* @package ai
* @link https://www.zentao.net
*/
?>
<?php include '../../common/view/header.lite.html.php';?>
<?php js::set('requiredFields', $config->ai->createprompt->requiredFields);?>
<div id='mainContent' class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2><?php echo $this->lang->ai->prompts->create;?></h2>
</div>
<form method="post" class="main-form form-ajax" target="hiddenwin">
<table class="table table-form">
<tbody>
<tr>
<th class="w-80px"><?php echo $this->lang->ai->prompts->name;?></th>
<td><?php echo html::input('name', '', "class='form-control'");?></td>
</tr>
<tr>
<th class="w-80px"><?php echo $this->lang->ai->prompts->description;?></th>
<td><?php echo html::textarea('desc', '', "rows='6' class='form-control'");?></td>
</tr>
<tr>
<td colspan="2" class="text-center form-actions">
<?php echo html::submitButton($this->lang->ai->nextStep, '', 'btn btn-wide btn-primary disabled');?>
</td>
</tr>
</tbody>
</table>
</form>
</div>
</div>
<script>
$(function() {
$('input[name="name"]').on('input', function() {
if($(this).val().length > 0)
{
$('button[type="submit"]').removeClass('disabled');
}
else
{
$('button[type="submit"]').addClass('disabled');
}
});
});
</script>
<?php include '../../common/view/footer.lite.html.php';?>
+48 -4
View File
@@ -18,7 +18,7 @@
</div>
</div>
<div class="btn-toolbar pull-left">
<?php
<?php
foreach($this->lang->ai->prompts->statuses as $statusKey => $statusName)
{
echo html::a($this->createLink('ai', 'prompts', "module=$module&status=$statusKey"), "<span class='text'>{$this->lang->ai->prompts->statuses[$statusKey]}" . ($status == $statusKey ? '<span class="label label-light label-badge" style="margin-left: 4px;">' . count($prompts) . '</span>' : '') . "</span>", '' ,"id='status-$statusKey' class='btn btn-link" . ($status == $statusKey ? ' btn-active-text' : '') . "'");
@@ -26,7 +26,7 @@
?>
</div>
<div class="btn-toolbar pull-right">
<?php echo html::a($this->createLink('ai', 'createprompt'), "<i class='icon icon-plus'></i> " . $lang->ai->prompts->create, '', "class='btn btn-primary'");?>
<?php echo html::a($this->createLink('ai', 'createprompt'), "<i class='icon icon-plus'></i> " . $lang->ai->prompts->create, '', "class='btn btn-primary iframe'");?>
</div>
</div>
<div id="mainContent" class="main-row fade">
@@ -44,10 +44,54 @@
<div class="table-empty-tip">
<p>
<span class="text-muted"><?php echo $lang->ai->prompts->emptyList;?></span>
<?php echo html::a($this->createLink('ai', 'createprompt'), "<i class='icon icon-plus'></i> " . $lang->ai->prompts->create, '', "class='btn btn-info'");?>
<?php echo html::a($this->createLink('ai', 'createprompt'), "<i class='icon icon-plus'></i> " . $lang->ai->prompts->create, '', "class='btn btn-info iframe'");?>
</p>
</div>
<?php else:?>
<div class='main-table'>
<table class='main-table table has-sort-head table-fixed' id='promptList'>
<thead>
<tr>
<?php $vars = "module=$module&status=$status&orderBy=%s&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}";?>
<th class='c-id text-left w-60px'><?php common::printOrderLink('id', $orderBy, $vars, $lang->ai->prompts->id);?></th>
<th class='c-name'><?php common::printOrderLink('name', $orderBy, $vars, $lang->ai->prompts->name);?></th>
<th class='c-createdby w-120px'><?php common::printOrderLink('createdby', $orderBy, $vars, $lang->ai->prompts->createdBy);?></th>
<th class='c-createddate w-180px'><?php common::printOrderLink('createddate', $orderBy, $vars, $lang->ai->prompts->createdDate);?></th>
<th class='c-targetform'><?php common::printOrderLink('targetform', $orderBy, $vars, $lang->ai->prompts->targetForm);?></th>
<th class='c-desc'><?php echo $lang->ai->prompts->funcDesc;?></th>
<th class='text-center c-actions-5'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
<?php foreach($prompts as $prompt):?>
<tr>
<td class='c-id'><?php echo $prompt->id;?></td>
<td class='c-name'>
<?php echo $prompt->name;?>
<?php if($prompt->status == 'draft') echo "<span class='label label-light label-badge'>{$this->lang->ai->prompts->statuses[$prompt->status]}</span>";?>
</td>
<td class='c-createdby'><?php echo $prompt->createdBy;?></td>
<td class='c-createddate'><?php echo $prompt->createdDate;?></td>
<td class='c-targetform'><?php echo $prompt->targetForm;?></td>
<td class='c-description'><?php echo $prompt->desc;?></td>
<td class='text-center c-actions'>
<?php
echo html::a('#', '<i class="icon-bars text-primary"></i>', '', "class='btn'");
echo html::a('#', '<i class="icon-design text-primary"></i>', '', "class='btn'");
echo html::a('#', '<i class="icon-edit text-primary"></i>', '', "class='btn'");
echo html::a('#', '<i class="icon-lock text-primary"></i>', '', "class='btn'");
echo html::a('#', '<i class="icon-trash text-primary"></i>', '', "class='btn'");
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
<div class='table-footer'>
<?php $pager->show('right', 'pagerjs');?>
</div>
</div>
<?php endif;?>
</div>
</div>
<?php include '../../common/view/footer.html.php';?>
<?php include '../../common/view/footer.html.php';?>