Enhance test of AI

This commit is contained in:
ldestailleur 2025-02-16 19:56:03 +01:00
parent 320dbe483e
commit bc1dbae6b0
3 changed files with 95 additions and 24 deletions

View File

@ -28,7 +28,8 @@
// Load Dolibarr environment
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
require_once '../lib/ai.lib.php';
require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php";
require_once DOL_DOCUMENT_ROOT."/ai/lib/ai.lib.php";
/**
* @var Conf $conf
@ -38,7 +39,9 @@ require_once '../lib/ai.lib.php';
* @var User $user
*/
$langs->loadLangs(array("admin"));
$langs->loadLangs(array("admin", "website", "other"));
$arrayofaifeatures = getLitOfAIFeatures();
// Parameters
$action = GETPOST('action', 'aZ09');
@ -49,10 +52,7 @@ if (empty($action)) {
$action = 'edit';
}
$value = GETPOST('value', 'alpha');
$label = GETPOST('label', 'alpha');
$scandir = GETPOST('scan_dir', 'alpha');
$type = 'myobject';
$content = GETPOST('content');
$error = 0;
$setupnotempty = 0;
@ -163,5 +163,55 @@ if (empty($setupnotempty)) {
// Page end
print dol_get_fiche_end();
// Section to test
print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="add">';
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
$functioncode = GETPOST('functioncode');
$out = '';
if ($functioncode) {
$labeloffeature = empty($arrayofaifeatures[GETPOST('functioncode')]['label']) ? 'Undefined' : $arrayofaifeatures[GETPOST('functioncode')]['label'];
$out .= $langs->trans("Test").' '.$labeloffeature.'...<br><br>';
if (GETPOST('functioncode') == 'textgenerationemail') {
$showlinktoai = 1;
$showlinktolayout = 0;
$neweditor = new DolEditor('aicontenttotest', $content);
$out .= $neweditor->Create(1);
$out .= $form->buttonsSaveCancel("Test");
} else {
$out .= $langs->trans("FeatureNotYetAvailable").'<br><br>';
$functioncode = '';
}
}
if (!$functioncode) {
// Combo list of AI features
$out .= '<select name="functioncode" id="functioncode" class="flat minwidth300" placeholder="Test feature">';
$out .= '<option value="-1">'.$langs->trans("SelectFeatureToTest").'</option>';
foreach ($arrayofaifeatures as $key => $val) {
$labelhtml = $langs->trans($arrayofaifeatures[$key]['label']).($arrayofaifeatures[$key]['status'] == 'notused' ? ' <span class="opacitymedium">('.$langs->trans("NotYetAvailable").')</span>' : "");
$labeltext = $langs->trans($arrayofaifeatures[$key]['label']);
$out .= '<option value="'.$key.'" data-html="'.dol_escape_htmltag($labelhtml).'"';
$out .= (GETPOST('functioncode') == $key ? ' selected="selected"' : '');
$out .= '>'.dol_escape_htmltag($labeltext).'</option>';
}
$out .= '</select>';
$out .= ajax_combobox("functioncode");
$out .= '<input class="button small" type="submit" name="testmode" value="'.$langs->trans("Test").'">';
}
print $out;
print '</form>';
llxFooter();
$db->close();

View File

@ -23,6 +23,30 @@
* \brief Library files with common functions for Ai
*/
/**
* Prepare admin pages header
*
* @return array<string,array<string,string>>}>
*/
function getLitOfAIFeatures()
{
global $langs;
$arrayofaifeatures = array(
'textgenerationemail' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("EmailContent").')', 'picto'=>'', 'status'=>'dolibarr'),
'textgenerationwebpage' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("WebsitePage").')', 'picto'=>'', 'status'=>'dolibarr'),
'textgeneration' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("Other").')', 'picto'=>'', 'status'=>'notused'),
'imagegeneration' => array('label' => 'ImageGeneration', 'picto'=>'', 'status'=>'notused'),
'videogeneration' => array('label' => 'VideoGeneration', 'picto'=>'', 'status'=>'notused'),
'audiogeneration' => array('label' => 'AudioGeneration', 'picto'=>'', 'status'=>'notused'),
'transcription' => array('label' => 'Transcription', 'picto'=>'', 'status'=>'notused'),
'translation' => array('label' => 'Translation', 'picto'=>'', 'status'=>'notused')
);
return $arrayofaifeatures;
}
/**
* Prepare admin pages header
*

View File

@ -15,26 +15,22 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Need to have the following variables defined:
* $conf
* $formmail
* $formwebsite (optional)
* $showlinktolayout='emailing', 'email', 'websitepage', ...
* $showlinktolayoutlabel='...'
* $showlinktoai ('' or 'textgeneration', 'textgenerationemail', 'textgenerationwebpage', ...)
* $showlinktoailabel='...'
* $htmlname
*/
/**
/**
* @var Conf $conf
* @var ?FormMail $formmail
* @var ?FormWebsite $formwebsite
* @var string $htmlname
* @var string $showlinktolayout
* @var string $showlinktolayoutlabel
* @var ?FormMail $formmail
* @var ?FormWebsite $formwebsite
* @var string $htmlname
* @var string $showlinktolayout 'emailing', 'email', 'websitepage', ...
* @var string $showlinktolayoutlabel '...'
* @var string $showlinktoai '' or 'textgeneration', 'textgenerationemail', 'textgenerationwebpage', ...
* @var string $showlinktoailabel '...'
* @var string $htmlname
* @var ?string $out
*/
// Protection to avoid direct call of template
//Protection to avoid direct call of template
if (empty($conf) || !is_object($conf)) {
print "Error, template page can't be called as URL";
exit(1);
@ -59,9 +55,10 @@ if (empty($htmlname)) {
@phan-var-force ?string $out
';
if (!isset($out)) {
if (!isset($out)) { // Init to empty string if not defined
$out = '';
}
// Add link to add layout
if ($showlinktolayout) {
$out .= '<a href="#" id="linkforlayouttemplates" class="notasortlink inline-block alink marginrightonly">';