From 1bb7edea8b2a3cea532ea87d500dbc9dd671ff8e Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Tue, 8 Apr 2025 11:42:46 +0200 Subject: [PATCH] Enhance AI features --- htdocs/ai/admin/custom_prompt.php | 34 +++++++++++---- htdocs/ai/class/ai.class.php | 4 ++ htdocs/ai/lib/ai.lib.php | 12 ++++-- htdocs/core/class/html.formai.class.php | 55 ++++++++++++++----------- htdocs/core/tpl/formlayoutai.tpl.php | 8 +++- htdocs/langs/en_US/admin.lang | 5 ++- 6 files changed, 79 insertions(+), 39 deletions(-) diff --git a/htdocs/ai/admin/custom_prompt.php b/htdocs/ai/admin/custom_prompt.php index 092612da89f..8149ec58b09 100644 --- a/htdocs/ai/admin/custom_prompt.php +++ b/htdocs/ai/admin/custom_prompt.php @@ -81,8 +81,16 @@ $aiservice = getDolGlobalString('AI_API_SERVICE', 'chatgpt'); // Setup conf for AI model $formSetup->formHiddenInputs['action'] = "updatefeaturemodel"; foreach ($arrayofaifeatures as $key => $val) { + $newkey = $key; + if (preg_match('/^text/', $key)) { + $newkey = 'textgeneration'; + } $item = $formSetup->newItem('AI_API_'.strtoupper($aiservice).'_MODEL_'.$val["function"]); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_".$val["function"]); + if ($arrayofai[$aiservice][$newkey] != 'na') { + $item->nameText = $langs->trans("AI_API_MODEL_".$val["function"]).' ('.$langs->trans("Default").' = '.$arrayofai[$aiservice][$newkey].')'; + } else { + $item->nameText = $langs->trans("AI_API_MODEL_".$val["function"]).' ('.$langs->trans("None").')'; + } $item->cssClass = 'minwidth500 input'; } @@ -218,10 +226,15 @@ print load_fiche_titre($langs->trans($title), $linkback, 'title_setup'); $head = aiAdminPrepareHead(); print dol_get_fiche_head($head, 'custom', $langs->trans($title), -1, "ai"); -//$newbutton = ''.$langs->trans("New").''; -$newbutton = ''; +$newcardbutton = dolGetButtonTitle($langs->trans('NewCustomPrompt'), '', 'fa fa-plus-circle', $_SERVER["PHP_SELF"].'?action=create', '', 1); +/* +$newbutton = ''; +$newbutton .= img_picto('', 'add'); +$newbutton .= ''; +*/ + +print load_fiche_titre($langs->trans("AIPromptForFeatures", $arrayofai[$aiservice]['label']), $newcardbutton, ''); -print load_fiche_titre($langs->trans("AIPromptForFeatures"), $newbutton, ''); if ($action == 'deleteproperty') { $formconfirm = $form->formconfirm( @@ -236,7 +249,8 @@ if ($action == 'deleteproperty') { print $formconfirm; } -if ($action == 'edit' || $action == 'deleteproperty') { +if ($action == 'create') { + $out .= '