28require
'../../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
30require_once
'../lib/ai.lib.php';
40$langs->loadLangs(array(
"admin",
"website",
"other"));
43$action =
GETPOST(
'action',
'aZ09');
44$backtopage =
GETPOST(
'backtopage',
'alpha');
46$modulepart =
GETPOST(
'modulepart',
'aZ09');
48$functioncode =
GETPOST(
'functioncode',
'alpha');
49$pre_prompt =
GETPOST(
'prePrompt');
50$post_prompt =
GETPOST(
'postPrompt');
51$blacklists =
GETPOST(
'blacklists');
70if (!class_exists(
'FormSetup')) {
71 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
77$item = $formSetup->newItem(
'AI_CONFIGURATIONS_PROMPT');
78$item->defaultFieldValue =
'';
80$setupnotempty += count($formSetup->items);
82$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
85$arrayofaifeatures = array(
86 'textgenerationemail' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"EmailContent").
')',
'picto'=>
'',
'status'=>
'development'),
87 'textgenerationwebpage' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"WebsitePage").
')',
'picto'=>
'',
'status'=>
'development'),
88 'textgeneration' => array(
'label' => $langs->trans(
'TextGeneration').
' ('.$langs->trans(
"Other").
')',
'picto'=>
'',
'status'=>
'notused'),
89 'imagegeneration' => array(
'label' =>
'ImageGeneration',
'picto'=>
'',
'status'=>
'notused'),
90 'videogeneration' => array(
'label' =>
'VideoGeneration',
'picto'=>
'',
'status'=>
'notused'),
91 'audiogeneration' => array(
'label' =>
'AudioGeneration',
'picto'=>
'',
'status'=>
'notused'),
92 'transcription' => array(
'label' =>
'Transcription',
'picto'=>
'',
'status'=>
'notused'),
93 'translation' => array(
'label' =>
'Translation',
'picto'=>
'',
'status'=>
'notused')
104$currentConfigurations = json_decode($currentConfigurationsJson,
true);
106if ($action ==
'update' && $cancel) {
110if ($action ==
'update' && !$cancel && !$test) {
112 if (empty($functioncode)) {
116 if (!is_array($currentConfigurations)) {
117 $currentConfigurations = [];
120 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
122 if (empty($functioncode) || (empty($pre_prompt) && empty($post_prompt) && empty($blacklists))) {
123 if (isset($currentConfigurations[$functioncode])) {
124 unset($currentConfigurations[$functioncode]);
127 $currentConfigurations[$functioncode] = [
128 'prePrompt' => $pre_prompt,
129 'postPrompt' => $post_prompt,
130 'blacklists' => $blacklistArray,
134 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
135 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'',
$conf->entity);
138 header(
"Location: ".$_SERVER[
'PHP_SELF']);
150if ($action ==
'updatePrompts' && !$test) {
151 $key =
GETPOST(
'key',
'alpha');
153 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
155 $currentConfigurations[$key] = [
156 'prePrompt' => $pre_prompt,
157 'postPrompt' => $post_prompt,
158 'blacklists' => $blacklistArray,
161 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
162 $result =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'',
$conf->entity);
174if ($action ==
'updatePrompts' && $test) {
179if ($action ==
'confirm_deleteproperty' &&
GETPOST(
'confirm') ==
'yes') {
180 $key =
GETPOST(
'key',
'alpha');
182 if (isset($currentConfigurations[$key])) {
183 unset($currentConfigurations[$key]);
185 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
186 $res =
dolibarr_set_const($db,
'AI_CONFIGURATIONS_PROMPT', $newConfigurationsJson,
'chaine', 0,
'',
$conf->entity);
188 header(
"Location: ".$_SERVER[
'PHP_SELF']);
202$form =
new Form($db);
207llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-ai page-admin_custom_prompt');
210$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.$langs->trans(
"BackToModuleList").
'</a>';
221print
load_fiche_titre($langs->trans(
"AIPromptForFeatures"), $newbutton,
'');
223if ($action ==
'deleteproperty') {
224 $formconfirm = $form->formconfirm(
225 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
226 $langs->trans(
'Delete'),
227 $langs->trans(
'ConfirmDeleteSetup',
GETPOST(
'key',
'alpha')),
228 'confirm_deleteproperty',
236if ($action ==
'edit' || $action ==
'deleteproperty') {
237 $out =
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
238 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
239 $out .=
'<input type="hidden" name="action" value="update">';
242 $out .=
'<table class="noborder centpercent">';
244 $out .=
'<tr class="liste_titre">';
245 $out .=
'<td>'.$langs->trans(
'Add').
'</td>';
251 $out .=
'<tr class="oddeven">';
252 $out .=
'<td class="col-setup-title titlefield">';
253 $out .=
'<span id="module" class="spanforparamtooltip">'.$langs->trans(
"Feature").
'</span>';
257 $out .=
'<select name="functioncode" id="functioncode" class="flat minwidth500">';
258 $out .=
'<option> </option>';
259 foreach ($arrayofaifeatures as $key => $val) {
260 $labelhtml = $langs->trans($arrayofaifeatures[$key][
'label']).($arrayofaifeatures[$key][
'status'] ==
'notused' ?
' <span class="opacitymedium">('.$langs->trans(
"NotYetAvailable").
')</span>' :
"");
261 $labeltext = $langs->trans($arrayofaifeatures[$key][
'label']);
282 $out .=
'<tr class="oddeven">';
283 $out .=
'<td class="col-setup-title">';
284 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
287 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput" name="prePrompt" rows="3"></textarea>';
290 $out .=
'<tr class="oddeven">';
291 $out .=
'<td class="col-setup-title">';
292 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
295 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput" name="postPrompt" rows="3"></textarea>';
298 $out .=
'<tr class="oddeven">';
299 $out .=
'<td class="col-setup-title">';
300 $out .=
'<span id="blacklists" class="spanforparamtooltip">'.$langs->trans(
"BlackListWords").
' '.
img_help(1,
'Words must be separated by a coma (",")').
'</span>';
303 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="blacklistsInput" name="blacklists" rows="3"></textarea>';
309 $out .= $form->buttonsSaveCancel(
"Add",
"");
311 $out .=
'<br><br><br>';
317if ($action ==
'edit' || $action ==
'create' || $action ==
'deleteproperty') {
320 if (!empty($currentConfigurations)) {
321 foreach ($currentConfigurations as $key => $config) {
322 if (!empty($key) && !preg_match(
'/^[a-z]+$/i', $key)) {
326 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
327 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
328 $out .=
'<input type="hidden" name="key" value="'.$key.
'" />';
329 $out .=
'<input type="hidden" name="action" value="updatePrompts">';
330 $out .=
'<input type="hidden" name="page_y" value="">';
332 $out .=
'<table class="noborder centpercent">';
334 $out .=
'<tr class="liste_titre">';
335 $out .=
'<td class="titlefield">'.$arrayofaifeatures[$key][
'picto'].
' '.$langs->trans($arrayofaifeatures[$key][
'label']);
336 $out .=
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deleteproperty&token='.
newToken().
'&key='.urlencode($key).
'">'.
img_delete().
'</a>';
343 $out .=
'<tr class="oddeven">';
344 $out .=
'<td class="col-setup-title">';
345 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
348 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput_'.$key.
'" name="prePrompt" rows="2">'.$config[
'prePrompt'].
'</textarea>';
352 $out .=
'<tr class="oddeven">';
353 $out .=
'<td class="col-setup-title">';
354 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
357 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput_'.$key.
'" name="postPrompt" rows="2">'.$config[
'postPrompt'].
'</textarea>';
361 $out .=
'<tr id="fichetwothirdright-'.$key.
'" class="oddeven">';
362 $out .=
'<td>'.$langs->trans(
"BlackListWords").
'</td>';
364 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="blacklist_'.$key.
'" name="blacklists" rows="3">'.(isset($config[
'blacklists']) ? implode(
', ', (array) $config[
'blacklists']) :
'').
'</textarea>';
371 $out .=
'<input type="submit" class="button small submitBtn reposition" name="modify" data-index="'.$key.
'" value="'.
dol_escape_htmltag($langs->trans(
"Modify")).
'"/>';
374 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
375 $showlinktoai = $key;
376 $showlinktoailabel = $langs->trans(
"ToTest");
381 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
383 $out .=
'<div id="'.$htmlname.
'"></div>';
400if (empty($setupnotempty)) {
401 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.