+ prompt role assigning, task #95114.
This commit is contained in:
+32
-10
@@ -139,12 +139,30 @@ class ai extends control
|
||||
/**
|
||||
* Edit role of prompt, prompt editing step 2.
|
||||
*
|
||||
* @param int $prompt
|
||||
* @param int $promptID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function promptAssignRole($prompt)
|
||||
public function promptAssignRole($promptID)
|
||||
{
|
||||
$prompt = $this->ai->getPromptByID($promptID);
|
||||
|
||||
if($_POST)
|
||||
{
|
||||
$role = fixer::input('post')->get();
|
||||
|
||||
$prompt->model = $role->model;
|
||||
$prompt->role = $role->role;
|
||||
$prompt->characterization = $role->characterization;
|
||||
|
||||
$this->ai->updatePrompt($prompt);
|
||||
|
||||
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('promptSelectDataSource', "promptID=$promptID") . '#app=admin'));
|
||||
}
|
||||
|
||||
$this->view->prompt = $prompt;
|
||||
$this->view->promptID = $promptID;
|
||||
$this->view->title = $this->lang->ai->prompts->assignRole . " {$this->lang->colon} " . $this->lang->ai->prompts->common;
|
||||
$this->view->position[] = $this->lang->ai->prompts->common;
|
||||
$this->display();
|
||||
@@ -153,12 +171,13 @@ class ai extends control
|
||||
/**
|
||||
* Set data source of prompt, prompt editing step 3.
|
||||
*
|
||||
* @param int $prompt
|
||||
* @param int $promptID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function promptSelectDataSource($prompt)
|
||||
public function promptSelectDataSource($promptID)
|
||||
{
|
||||
$this->view->promptID = $promptID;
|
||||
$this->view->title = $this->lang->ai->prompts->selectDataSource . " {$this->lang->colon} " . $this->lang->ai->prompts->common;
|
||||
$this->view->position[] = $this->lang->ai->prompts->common;
|
||||
$this->display();
|
||||
@@ -167,12 +186,13 @@ class ai extends control
|
||||
/**
|
||||
* Edit purpose and purpose elaboration of prompt, prompt editing step 4.
|
||||
*
|
||||
* @param int $prompt
|
||||
* @param int $promptID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function promptSetPurpose($prompt)
|
||||
public function promptSetPurpose($promptID)
|
||||
{
|
||||
$this->view->promptID = $promptID;
|
||||
$this->view->title = $this->lang->ai->prompts->setPurpose . " {$this->lang->colon} " . $this->lang->ai->prompts->common;
|
||||
$this->view->position[] = $this->lang->ai->prompts->common;
|
||||
$this->display();
|
||||
@@ -181,12 +201,13 @@ class ai extends control
|
||||
/**
|
||||
* Set target form of prompt, prompt editing step 5.
|
||||
*
|
||||
* @param int $prompt
|
||||
* @param int $promptID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function promptSetTargetForm($prompt)
|
||||
public function promptSetTargetForm($promptID)
|
||||
{
|
||||
$this->view->promptID = $promptID;
|
||||
$this->view->title = $this->lang->ai->prompts->setTargetForm . " {$this->lang->colon} " . $this->lang->ai->prompts->common;
|
||||
$this->view->position[] = $this->lang->ai->prompts->common;
|
||||
$this->display();
|
||||
@@ -195,12 +216,13 @@ class ai extends control
|
||||
/**
|
||||
* Edit additional information of prompt, final prompt editing step.
|
||||
*
|
||||
* @param int $prompt
|
||||
* @param int $promptID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function promptFinalize($prompt)
|
||||
public function promptFinalize($promptID)
|
||||
{
|
||||
$this->view->promptID = $promptID;
|
||||
$this->view->title = $this->lang->ai->prompts->finalize . " {$this->lang->colon} " . $this->lang->ai->prompts->common;
|
||||
$this->view->position[] = $this->lang->ai->prompts->common;
|
||||
$this->display();
|
||||
|
||||
@@ -12,8 +12,9 @@ $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->prompt->name = 'Name';
|
||||
$lang->prompt->desc = 'Description';
|
||||
$lang->prompt->model = 'Model';
|
||||
|
||||
$lang->ai->nextStep = 'Next';
|
||||
|
||||
@@ -35,6 +36,11 @@ $lang->ai->prompts->setPurpose = 'Set Purpose';
|
||||
$lang->ai->prompts->setTargetForm = 'Set Target Form';
|
||||
$lang->ai->prompts->finalize = 'Finalize';
|
||||
|
||||
$lang->ai->prompts->assignModel = 'Select Model';
|
||||
$lang->ai->prompts->model = 'Model';
|
||||
$lang->ai->prompts->role = 'Role';
|
||||
$lang->ai->prompts->characterization = 'Characterization';
|
||||
|
||||
$lang->ai->prompts->statuses = array();
|
||||
$lang->ai->prompts->statuses[''] = 'All';
|
||||
$lang->ai->prompts->statuses['draft'] = 'Draft';
|
||||
|
||||
@@ -12,8 +12,9 @@ $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->prompt->name = '名称';
|
||||
$lang->prompt->desc = '描述';
|
||||
$lang->prompt->model = '语言模型';
|
||||
|
||||
$lang->ai->nextStep = '下一步';
|
||||
|
||||
@@ -35,6 +36,11 @@ $lang->ai->prompts->setPurpose = '确认操作';
|
||||
$lang->ai->prompts->setTargetForm = '结果处理';
|
||||
$lang->ai->prompts->finalize = '准备发布';
|
||||
|
||||
$lang->ai->prompts->assignModel = '指定语言模型';
|
||||
$lang->ai->prompts->model = '语言模型';
|
||||
$lang->ai->prompts->role = '角色';
|
||||
$lang->ai->prompts->characterization = '角色描述';
|
||||
|
||||
$lang->ai->prompts->statuses = array();
|
||||
$lang->ai->prompts->statuses[''] = '全部';
|
||||
$lang->ai->prompts->statuses['draft'] = '草稿';
|
||||
|
||||
@@ -320,6 +320,22 @@ class aiModel extends model
|
||||
->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get prompt by id.
|
||||
*
|
||||
* TODO: fully implement this.
|
||||
*
|
||||
* @param int $id
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getPromptById($id)
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_PROMPT)
|
||||
->where('id')->eq($id)
|
||||
->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a prompt.
|
||||
*
|
||||
@@ -342,4 +358,28 @@ class aiModel extends model
|
||||
|
||||
return dao::isError() ? false : $this->dao->lastInsertID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a prompt.
|
||||
*
|
||||
* TODO: fully implement this.
|
||||
*
|
||||
* @param object $prompt
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function updatePrompt($prompt)
|
||||
{
|
||||
$prompt->editedDate = helper::now();
|
||||
$prompt->editedBy = $this->app->user->account;
|
||||
|
||||
$this->dao->update(TABLE_PROMPT)
|
||||
->data($prompt)
|
||||
->autoCheck()
|
||||
->batchCheck($this->config->ai->createprompt->requiredFields, 'notempty')
|
||||
->where('id')->eq($prompt->id)
|
||||
->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,60 @@
|
||||
*/
|
||||
?>
|
||||
<?php include '../../common/view/header.html.php';?>
|
||||
<style>
|
||||
.center-wrapper {display: flex; justify-content: center; height: 100%;}
|
||||
.center-content {min-width: 800px; height: 100%; display: flex; flex-direction: column;}
|
||||
.content-row {display: flex; flex-direction: row; padding: 8px 0px;}
|
||||
.input-label {width: 120px; padding: 6px 12px; text-align: right;}
|
||||
.input {flex-grow: 1;}
|
||||
</style>
|
||||
<div id='mainMenu' class='clearfix' style='display: flex; flex-direction: row;'>
|
||||
<?php echo html::backButton("<i class='icon icon-back icon-sm'></i> $lang->goback", '', 'btn btn-info');?>
|
||||
<?php include 'promptdesignprogressbar.html.php';?>
|
||||
<?php echo html::submitButton("<i class='icon icon-save icon-sm'></i> $lang->save", '', 'btn btn-primary');?>
|
||||
</div>
|
||||
<div id='mainContent' class='main-content' style='height: calc(100vh - 120px);'>
|
||||
<form class='load-indicator main-form form-ajax' method='post' style='height: 100%;'>
|
||||
<div class='center-wrapper'>
|
||||
<div class='center-content'>
|
||||
<div>
|
||||
<h4><?php echo $lang->ai->prompts->assignModel;?></h4>
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->model;?></span></div>
|
||||
<div class='input mw-400px'>
|
||||
<?php echo html::select('model', $lang->ai->models->typeList, current(array_keys($lang->ai->models->typeList)), "class='form-control chosen' required disabled");?>
|
||||
<?php echo html::hidden('model', current(array_keys($lang->ai->models->typeList))); // TODO: use actual model list and value. ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h4><?php echo $lang->ai->prompts->assignRole;?></h4>
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->role;?></span></div>
|
||||
<div class='input mw-400px'><?php echo html::input('role', $prompt->role, "class='form-control'");?></div>
|
||||
</div>
|
||||
<div class='content-row'>
|
||||
<div class='input-label'><span><?php echo $lang->ai->prompts->characterization;?></span></div>
|
||||
<div class='input'><?php echo html::textarea('characterization', $prompt->characterization, "class='form-control'");?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div style='display: flex; flex-grow: 1; flex-direction: column-reverse;'>
|
||||
<div style='display: flex; justify-content: center;'><?php echo html::submitButton($lang->ai->nextStep, 'disabled');?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$(function()
|
||||
{
|
||||
$('select[name="model"]').change(function()
|
||||
{
|
||||
var model = $(this).val();
|
||||
if(model) $('button[type="submit"]').removeAttr('disabled');
|
||||
if(!model) $('button[type="submit"]').attr('disabled', 'disabled');
|
||||
});
|
||||
$('select[name="model"]').trigger('change');
|
||||
});
|
||||
</script>
|
||||
<?php include '../../common/view/footer.html.php';?>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* The ai prompt design progress bar 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
|
||||
*/
|
||||
?>
|
||||
<style>
|
||||
#prompt-design-progress {flex-grow: 1;}
|
||||
</style>
|
||||
<div id='prompt-design-progress'>
|
||||
</div>
|
||||
Reference in New Issue
Block a user