28require
'../../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
"/core/lib/admin.lib.php";
37require_once DOL_DOCUMENT_ROOT.
"/ai/lib/ai.lib.php";
38require_once DOL_DOCUMENT_ROOT.
"/core/class/html.formai.class.php";
40$langs->loadLangs(array(
"admin",
"website",
"other"));
46$action =
GETPOST(
'action',
'aZ09');
47$backtopage =
GETPOST(
'backtopage',
'alpha');
48$cancel =
GETPOST(
'cancel',
'alpha');
49$modulepart =
GETPOST(
'modulepart',
'aZ09');
51$functioncode =
GETPOST(
'functioncode',
'alpha');
52$pre_prompt =
GETPOST(
'prePrompt');
53$post_prompt =
GETPOST(
'postPrompt');
54$blacklists =
GETPOST(
'blacklists');
76if (!class_exists(
'FormSetup')) {
77 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsetup.class.php';
85$formSetup->formHiddenInputs[
'action'] =
"updatefeaturemodel";
86foreach ($arrayofaifeatures as $featurekey => $feature) {
87 $newfeaturekey = $featurekey;
88 if (preg_match(
'/^text/', $featurekey)) {
89 $newfeaturekey =
'textgeneration';
91 $item = $formSetup->newItem(
'AI_API_'.strtoupper($aiservice).
'_MODEL_'.$feature[
"function"]);
92 if (!empty($arrayofai[$aiservice][$newfeaturekey][
'default']) && $arrayofai[$aiservice][$newfeaturekey][
'default'] !=
'na') {
93 $item->nameText =
'<span class="valignmiddle">'.$langs->trans(
"AI_API_MODEL_".$feature[
"function"]).
' </span><span class="opacitymedium valignmiddle">('.$langs->trans(
"Default").
' = '.$arrayofai[$aiservice][$newfeaturekey][
'default'].
')</span>';
94 if (!empty($arrayofai[$aiservice][$newfeaturekey][
'examples'])) {
95 $htmltooltip = $langs->trans(
"Example").
': '.$arrayofai[$aiservice][$newfeaturekey][
'examples'];
96 $item->nameText .= $form->textwithpicto(
'', $htmltooltip);
99 $item->nameText = $langs->trans(
"AI_API_MODEL_".$feature[
"function"]).
' <span class="opacitymedium">('.$langs->trans(
"None").
')</span>';
101 $item->cssClass =
'minwidth500 input';
104$setupnotempty += count($formSetup->items);
106$dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
116$currentConfigurations = json_decode($currentConfigurationsJson,
true);
118if ($action ==
'updatefeaturemodel' && !empty($user->admin)) {
119 $formSetup->saveConfFromPost();
123if ($action ==
'update' && $cancel) {
127if ($action ==
'update' && !$cancel && !$test) {
129 if (empty($functioncode)) {
133 if (!is_array($currentConfigurations)) {
134 $currentConfigurations = [];
137 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
139 if (empty($functioncode) || (empty($pre_prompt) && empty($post_prompt) && empty($blacklists))) {
140 if (isset($currentConfigurations[$functioncode])) {
141 unset($currentConfigurations[$functioncode]);
144 $currentConfigurations[$functioncode] = [
145 'prePrompt' => $pre_prompt,
146 'postPrompt' => $post_prompt,
147 'blacklists' => $blacklistArray,
151 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
155 header(
"Location: ".$_SERVER[
'PHP_SELF']);
167if ($action ==
'updatePrompts' && !$test) {
168 $blacklistArray = array_filter(array_map(
'trim', explode(
',', $blacklists)));
170 $currentConfigurations[$key] = [
171 'prePrompt' => $pre_prompt,
172 'postPrompt' => $post_prompt,
173 'blacklists' => $blacklistArray,
176 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
189if ($action ==
'updatePrompts' && $test) {
194if ($action ==
'confirm_deleteproperty' &&
GETPOST(
'confirm') ==
'yes') {
195 if (isset($currentConfigurations[$key])) {
196 unset($currentConfigurations[$key]);
198 $newConfigurationsJson = json_encode($currentConfigurations, JSON_UNESCAPED_UNICODE);
201 header(
"Location: ".$_SERVER[
'PHP_SELF']);
220llxHeader(
'', $langs->trans($title), $help_url,
'', 0, 0,
'',
'',
'',
'mod-ai page-admin_custom_prompt');
222$linkback =
'<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1').
'">'.
img_picto($langs->trans(
"BackToModuleList"),
'back',
'class="pictofixedwidth"').
'<span class="hideonsmartphone">'.$langs->trans(
"BackToModuleList").
'</span></a>';
230$newcardbutton = dolGetButtonTitle($langs->trans(
'NewCustomPrompt'),
'',
'fa fa-plus-circle', $_SERVER[
"PHP_SELF"].
'?action=create',
'', 1);
237print
load_fiche_titre($langs->trans(
"AIPromptForFeatures", $arrayofai[$aiservice][
'label']), $newcardbutton,
'');
240if ($action ==
'deleteproperty') {
241 $formconfirm = $form->formconfirm(
242 $_SERVER[
"PHP_SELF"].
'?key='.urlencode(
GETPOST(
'key',
'alpha')),
243 $langs->trans(
'Delete'),
244 $langs->trans(
'ConfirmDeleteSetup',
GETPOST(
'key',
'alpha')),
245 'confirm_deleteproperty',
253if ($action ==
'create') {
254 $out =
'<div class="addcustomprompt">';
256 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
257 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
258 $out .=
'<input type="hidden" name="action" value="update">';
261 $out .=
'<table class="noborder centpercent">';
263 $out .=
'<tr class="liste_titre">';
264 $out .=
'<td>'.$langs->trans(
'NewCustomPrompt').
'</td>';
270 $out .=
'<tr class="oddeven">';
271 $out .=
'<td class="col-setup-title titlefield">';
272 $out .=
'<span id="module" class="spanforparamtooltip">'.$langs->trans(
"Feature").
'</span>';
276 $out .=
'<select name="functioncode" id="functioncode" class="flat minwidth500">';
277 $out .=
'<option> </option>';
278 foreach ($arrayofaifeatures as $featurekey => $feature) {
279 $labelhtml = $langs->trans($arrayofaifeatures[$featurekey][
'label']).($arrayofaifeatures[$featurekey][
'status'] ==
'notused' ?
' <span class="opacitymedium">('.$langs->trans(
"NotYetAvailable").
')</span>' :
"");
280 $labeltext = $langs->trans($arrayofaifeatures[$featurekey][
'label']);
285 $out .=
'<script type="text/javascript">
286 jQuery(document).ready(function() {
287 jQuery("#functioncode").on("change", function() {
288 console.log("We change value of ai function");
289 var changedValue = $(this).val();
290 console.log(changedValue);
291 var arrayplaceholder = {';
292 foreach ($arrayofaifeatures as $featurekey => $feature) {
296 jQuery("#prePromptInput'.dol_escape_js($key).
'").val(arrayplaceholder[changedValue]);
305 $out .=
'<tr class="oddeven">';
306 $out .=
'<td class="col-setup-title">';
307 $out .=
'<span id="prePrompt" class="spanforparamtooltip">';
308 $out .= $form->textwithpicto($langs->trans(
"Pre-Prompt"), $langs->trans(
"Pre-PromptHelp"));
312 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput'.$key.
'" name="prePrompt" rows="2"></textarea>';
315 $out .=
'<tr class="oddeven">';
316 $out .=
'<td class="col-setup-title">';
317 $out .=
'<span id="postPrompt" class="spanforparamtooltip">';
318 $out .= $form->textwithpicto($langs->trans(
"Post-Prompt"), $langs->trans(
"Post-PromptHelp"));
322 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput" name="postPrompt" rows="2"></textarea>';
325 $out .=
'<tr class="oddeven">';
326 $out .=
'<td class="col-setup-title">';
327 $out .=
'<span id="blacklists" class="spanforparamtooltip">';
328 $out .= $form->textwithpicto($langs->trans(
"BlackListWords"), $langs->trans(
"BlackListWordsAIHelp").
'.<br>'.$langs->trans(
"BlackListWordsHelp"));
332 $out .=
'<input type="text" class="flat minwidth500 quatrevingtpercent" id="blacklistsInput" name="blacklists">';
338 $out .= $form->buttonsSaveCancel(
"Add",
"");
349if ($action ==
'edit' || $action ==
'create' || $action ==
'deleteproperty') {
352 if (empty($currentConfigurations)) {
353 if ($action !=
'create') {
354 print
'<!-- no custom prompt-->'.
"\n";
355 print
'<span class="opacitymedium">'.$langs->trans(
"None").
'</span>';
363 foreach ($currentConfigurations as $confkey => $config) {
364 if (!empty($confkey) && !preg_match(
'/^[a-z]+$/i', $confkey)) {
368 $out .=
'<form action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
369 $out .=
'<input type="hidden" name="token" value="'.newToken().
'">';
370 $out .=
'<input type="hidden" name="key" value="'.$confkey.
'" />';
371 $out .=
'<input type="hidden" name="action" value="updatePrompts">';
372 $out .=
'<input type="hidden" name="page_y" value="">';
374 $out .=
'<table class="noborder centpercent">';
376 $out .=
'<tr class="liste_titre">';
377 $out .=
'<td class="titlefield">'.$arrayofaifeatures[$confkey][
'picto'].
' '.$langs->trans($arrayofaifeatures[$confkey][
'label']);
378 $out .=
'<a class="deletefielda reposition marginleftonly right" href="'.$_SERVER[
"PHP_SELF"].
'?action=deleteproperty&token='.newToken().
'&key='.urlencode($confkey).
'">'.
img_delete().
'</a>';
385 $out .=
'<tr class="oddeven">';
386 $out .=
'<td class="col-setup-title">';
387 $out .=
'<span id="prePrompt" class="spanforparamtooltip">'.$langs->trans(
"Pre-Prompt").
'</span>';
390 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="prePromptInput_'.$confkey.
'" name="prePrompt" rows="2">'.$config[
'prePrompt'].
'</textarea>';
394 $out .=
'<tr class="oddeven">';
395 $out .=
'<td class="col-setup-title">';
396 $out .=
'<span id="postPrompt" class="spanforparamtooltip">'.$langs->trans(
"Post-Prompt").
'</span>';
399 $out .=
'<textarea class="flat minwidth500 quatrevingtpercent" id="postPromptInput_'.$confkey.
'" name="postPrompt" rows="2">'.$config[
'postPrompt'].
'</textarea>';
403 $out .=
'<tr id="fichetwothirdright-'.$confkey.
'" class="oddeven">';
404 $out .=
'<td>'.$form->textwithpicto($langs->trans(
"BlackListWords"), $langs->trans(
"BlackListWordsHelp")).
'</td>';
406 $out .=
'<input type="text" class="flat minwidth500 quatrevingtpercent" id="blacklist_'.$confkey.
'" name="blacklists" value="'.(isset($config[
'blacklists']) ? implode(
', ', (array) $config[
'blacklists']) :
'').
'">';
411 $out .=
'<td>'.$langs->trans(
"Test").
'</td>';
414 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
416 $formmail->withaiprompt =
'html';
418 $showlinktoai = $confkey;
419 $showlinktoailabel = $langs->trans(
"ToTest");
420 $htmlname = $confkey;
421 $onlyenhancements = $confkey;
422 $showlinktolayout = 0;
425 include DOL_DOCUMENT_ROOT.
'/core/tpl/formlayoutai.tpl.php';
427 $out .=
'<div id="'.$htmlname.
'"></div>';
435 $out .=
'<center><input type="submit" class="button small submitBtn reposition" name="modify" data-index="'.$confkey.
'" value="'.
dol_escape_htmltag($langs->trans(
"Save")).
'"/></center>';
449if ($action ==
'edit' || $action ==
'create' || $action ==
'deleteproperty') {
450 print
load_fiche_titre($langs->trans(
"AIModelForFeature", $arrayofai[$aiservice][
'label']),
'',
'');
452 print $formSetup->generateOutput(
true);
456if (empty($setupnotempty)) {
457 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).
getListOfAIFeatures()
Prepare admin pages header.
aiAdminPrepareHead()
Prepare admin pages header.
getListOfAIServices()
Get list of available ai services.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.