28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
30require_once
'../lib/ai.lib.php';
32$langs->loadLangs(array(
"admin",
"website",
"other"));
35$action =
GETPOST(
'action',
'aZ09');
36$backtopage =
GETPOST(
'backtopage',
'alpha');
38$modulepart =
GETPOST(
'modulepart',
'aZ09');
40$functioncode =
GETPOST(
'functioncode',
'alpha');
41$pre_prompt =
GETPOST(
'prePrompt');
42$post_prompt =
GETPOST(
'postPrompt');
43$blacklists =
GETPOST(
'blacklists');
62if (!class_exists(
'FormSetup')) {
63 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
69$item = $formSetup->newItem(
'AI_CONFIGURATIONS_PROMPT');
70$item->defaultFieldValue =
'';
72$setupnotempty += count($formSetup->items);
74$dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
77$arrayofaifeatures = array(
78 'textgenerationemail' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"EmailContent").
')',
'picto'=>
'',
'status'=>
'development'),
79 'textgenerationwebpage' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"WebsitePage").
')',
'picto'=>
'',
'status'=>
'development'),
80 'textgeneration' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"Other").
')',
'picto'=>
'',
'status'=>
'notused'),
81 'imagegeneration' => array(
'label' =>
'ImageGeneration',
'picto'=>
'',
'status'=>
'notused'),
82 'videogeneration' => array(
'label' =>
'VideoGeneration',
'picto'=>
'',
'status'=>
'notused'),
83 'audiogeneration' => array(
'label' =>
'AudioGeneration',
'picto'=>
'',
'status'=>
'notused'),
84 'transcription' => array(
'label' =>
'Transcription',
'picto'=>
'',
'status'=>
'notused'),
85 'translation' => array(
'label' =>
'Translation',
'picto'=>
'',
'status'=>
'notused')
96$currentConfigurations = json_decode($currentConfigurationsJson,
true);
98if ($action ==
'update' && $cancel) {
102if ($action ==
'update' && !$cancel && !$test) {
104 if (empty($functioncode)) {
108 if (!is_array($currentConfigurations)) {
109 $currentConfigurations = [];
112 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
114 if (empty($functioncode) || (empty($pre_prompt) && empty($post_prompt) && empty($blacklists))) {
115 if (isset($currentConfigurations[$functioncode])) {
116 unset($currentConfigurations[$functioncode]);
119 $currentConfigurations[$functioncode] = [
120 'prePrompt' => $pre_prompt,
121 'postPrompt' => $post_prompt,
122 'blacklists' => $blacklistArray,
126 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
127 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
130 header(
"Location: ".$_SERVER[
'PHP_SELF']);
142if ($action ==
'updatePrompts' && !$test) {
143 $key =
GETPOST(
'key',
'alpha');
145 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
147 $currentConfigurations[$key] = [
148 'prePrompt' => $pre_prompt,
149 'postPrompt' => $post_prompt,
150 'blacklists' => $blacklistArray,
153 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
154 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
166if ($action ==
'updatePrompts' && $test) {
171if ($action ==
'confirm_deleteproperty' &&
GETPOST(
'confirm') ==
'yes') {
172 $key =
GETPOST(
'key',
'alpha');
174 if (isset($currentConfigurations[$key])) {
175 unset($currentConfigurations[$key]);
177 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
178 $res =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'', $conf->entity);
180 header(
"Location: ".$_SERVER[
'PHP_SELF']);
194$form =
new Form($db);
199llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-ai page-admin_custom_prompt');
202$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
213print
load_fiche_titre($langs->trans(
"AIPromptForFeatures"), $newbutton,
'');
215if ($action ==
'deleteproperty') {
216 $formconfirm = $form->formconfirm(
217 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
218 $langs->trans(
'Delete'),
219 $langs->trans(
'ConfirmDeleteSetup',
GETPOST(
'key',
'alpha')),
220 'confirm_deleteproperty',
228if ($action ==
'edit' || $action ==
'deleteproperty') {
229 $out =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
230 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
231 $out .=
'<input type="hidden" name="action" value="update">';
234 $out .=
'<table class="noborder centpercent">';
236 $out .=
'<tr class="liste_titre">';
237 $out .=
'<td>'.$langs->trans(
'Add').
'</td>';
243 $out .=
'<tr class="oddeven">';
244 $out .=
'<td class="col-setup-title titlefield">';
245 $out .=
'<span id="module" class="spanforparamtooltip">'.$langs->trans(
"Feature").
'</span>';
249 $out .=
'<select name="functioncode" id="functioncode" class="flat minwidth500">';
250 $out .=
'<option> </option>';
251 foreach ($arrayofaifeatures as $key => $val) {
252 $labelhtml = $langs->trans($arrayofaifeatures[$key][
'label']).($arrayofaifeatures[$key][
'status'] ==
'notused' ?
' <span class="opacitymedium">('.$langs->trans(
"NotYetAvailable").
')</span>' :
"");
253 $labeltext = $langs->trans($arrayofaifeatures[$key][
'label']);
274 $out .=
'<tr class="oddeven">';
275 $out .=
'<td class="col-setup-title">';
276 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
279 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput" name="prePrompt" rows="3"></textarea>';
282 $out .=
'<tr class="oddeven">';
283 $out .=
'<td class="col-setup-title">';
284 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
287 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput" name="postPrompt" rows="3"></textarea>';
290 $out .=
'<tr class="oddeven">';
291 $out .=
'<td class="col-setup-title">';
292 $out .=
'<span id="blacklists" class="spanforparamtooltip">'.$langs->trans(
"BlackListWords").
' '.
img_help(1,
'Words must be separated by a coma (",")').
'</span>';
295 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="blacklistsInput" name="blacklists" rows="3"></textarea>';
301 $out .= $form->buttonsSaveCancel(
"Add",
"");
303 $out .=
'<br><br><br>';
309if ($action ==
'edit' || $action ==
'create' || $action ==
'deleteproperty') {
312 if (!empty($currentConfigurations)) {
313 foreach ($currentConfigurations as $key => $config) {
314 if (!empty($key) && !preg_match(
'/^[a-z]+$/i', $key)) {
318 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
319 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
320 $out .=
'<input type="hidden" name="key" value="'.$key.
'" />';
321 $out .=
'<input type="hidden" name="action" value="updatePrompts">';
322 $out .=
'<input type="hidden" name="page_y" value="">';
324 $out .=
'<table class="noborder centpercent">';
326 $out .=
'<tr class="liste_titre">';
327 $out .=
'<td class="titlefield">'.$arrayofaifeatures[$key][
'picto'].
' '.$langs->trans($arrayofaifeatures[$key][
'label']);
328 $out .=
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deleteproperty&token='.
newToken().
'&key='.urlencode($key).
'">'.
img_delete().
'</a>';
335 $out .=
'<tr class="oddeven">';
336 $out .=
'<td class="col-setup-title">';
337 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
340 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput_'.$key.
'" name="prePrompt" rows="2">'.$config[
'prePrompt'].
'</textarea>';
344 $out .=
'<tr class="oddeven">';
345 $out .=
'<td class="col-setup-title">';
346 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
349 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput_'.$key.
'" name="postPrompt" rows="2">'.$config[
'postPrompt'].
'</textarea>';
353 $out .=
'<tr id="fichetwothirdright-'.$key.
'" class="oddeven">';
354 $out .=
'<td>'.$langs->trans(
"BlackListWords").
'</td>';
356 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="blacklist_'.$key.
'" name="blacklists" rows="3">'.(isset($config[
'blacklists']) ? implode(
', ', (array) $config[
'blacklists']) :
'').
'</textarea>';
363 $out .=
'<input type="submit" class="button small submitBtn reposition" name="modify" data-index="'.$key.
'" value="'.
dol_escape_htmltag($langs->trans(
"Modify")).
'"/>';
366 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
367 $showlinktoai = $key;
368 $showlinktoailabel = $langs->trans(
"ToTest");
373 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
375 $out .=
'<div id="'.$htmlname.
'"></div>';
392if (empty($setupnotempty)) {
393 print
'<br>'.$langs->trans(
"NothingToSetup");
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
aiAdminPrepareHead()
Prepare admin pages header.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_help($usehelpcursor=1, $usealttitle=1)
Show help logo with cursor "?".
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.