From 8ce483009a1b622e63a5a1f60d0779f906da2afb Mon Sep 17 00:00:00 2001 From: Hystepik Date: Wed, 19 Feb 2025 14:44:54 +0100 Subject: [PATCH] modify code has feedback --- htdocs/ai/admin/custom_prompt.php | 26 ++++++++++++++++--- htdocs/ai/admin/setup.php | 42 +++---------------------------- htdocs/ai/lib/ai.lib.php | 38 +++++++++++++++++++++------- htdocs/langs/en_US/admin.lang | 2 ++ 4 files changed, 57 insertions(+), 51 deletions(-) diff --git a/htdocs/ai/admin/custom_prompt.php b/htdocs/ai/admin/custom_prompt.php index 83753c01a7a..21ab35b9828 100644 --- a/htdocs/ai/admin/custom_prompt.php +++ b/htdocs/ai/admin/custom_prompt.php @@ -39,7 +39,8 @@ require_once DOL_DOCUMENT_ROOT."/ai/lib/ai.lib.php"; $langs->loadLangs(array("admin", "website", "other")); -$arrayofaifeatures = getLitOfAIFeatures(); +$arrayofaifeatures = getListOfAIFeatures(); +$arrayofia = getListOfAIServices(); // Parameters $action = GETPOST('action', 'aZ09'); @@ -74,10 +75,15 @@ if (!class_exists('FormSetup')) { } $formSetup = new FormSetup($db); +$aiservice = getDolGlobalString('AI_API_SERVICE', 'chatgpt'); -// Setup conf AI_PROMPT -$item = $formSetup->newItem('AI_CONFIGURATIONS_PROMPT'); -$item->defaultFieldValue = ''; +// Setup conf for AI model +$formSetup->formHiddenInputs['action'] = "updatefeaturemodel"; +foreach ($arrayofaifeatures as $key => $val) { + $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"]); + $item->cssClass = 'minwidth500 input'; +} $setupnotempty += count($formSetup->items); @@ -93,6 +99,11 @@ $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']); $currentConfigurationsJson = getDolGlobalString('AI_CONFIGURATIONS_PROMPT'); $currentConfigurations = json_decode($currentConfigurationsJson, true); +if ($action == 'updatefeaturemodel' && !empty($formSetup) && is_object($formSetup) && !empty($user->admin)) { + $formSetup->saveConfFromPost(); + $action = 'edit'; +} + if ($action == 'update' && $cancel) { $action = 'edit'; } @@ -397,6 +408,13 @@ if ($action == 'edit' || $action == 'create' || $action == 'deleteproperty') { print '
'; } + +if ($action == 'edit' || $action == 'create' || $action == 'deleteproperty') { + print load_fiche_titre($langs->trans("AIModelForFeature", $arrayofia[$aiservice]), $newbutton, ''); + print $formSetup->generateOutput(true); +} + + if (empty($setupnotempty)) { print '
'.$langs->trans("NothingToSetup"); } diff --git a/htdocs/ai/admin/setup.php b/htdocs/ai/admin/setup.php index 96a18ea1499..80ecd7828ef 100644 --- a/htdocs/ai/admin/setup.php +++ b/htdocs/ai/admin/setup.php @@ -41,7 +41,6 @@ require_once DOL_DOCUMENT_ROOT."/ai/lib/ai.lib.php"; $langs->loadLangs(array("admin", "website", "other")); -$arrayofaifeatures = getLitOfAIFeatures(); // Parameters $action = GETPOST('action', 'aZ09'); @@ -68,13 +67,10 @@ if (!class_exists('FormSetup')) { $formSetup = new FormSetup($db); // List all available IA -$arrayofia = array( - '-1' => $langs->trans('SelectAService'), - 'chatgpt' => 'ChatGPT', - 'groq' => 'Groq', - 'custom' => 'Custom' - //'gemini' => 'Gemini' -); +$arrayofia = getListOfAIServices(); + +// List all available features +$arrayofaifeatures = getListOfAIFeatures(); $item = $formSetup->newItem('AI_API_SERVICE'); // Name of constant must end with _KEY so it is encrypted when saved into database. $item->setAsSelect($arrayofia); @@ -98,36 +94,6 @@ foreach ($arrayofia as $ia => $ialabel) { $item->defaultFieldValue = ''; $item->fieldParams['trClass'] = 'iaservice '.$ia; $item->cssClass = 'minwidth500 input'.$ia; - - $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_MODEL_TEXT'); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_TEXT").' ('.$ialabel.')'; - $item->defaultFieldValue = ''; - $item->fieldParams['trClass'] = 'iaservice '.$ia; - $item->cssClass = 'minwidth500 input'.$ia; - - $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_MODEL_IMAGE'); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_IMAGE").' ('.$ialabel.')'; - $item->defaultFieldValue = ''; - $item->fieldParams['trClass'] = 'iaservice '.$ia; - $item->cssClass = 'minwidth500 input'.$ia; - - $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_MODEL_AUDIO'); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_AUDIO").' ('.$ialabel.')'; - $item->defaultFieldValue = ''; - $item->fieldParams['trClass'] = 'iaservice '.$ia; - $item->cssClass = 'minwidth500 input'.$ia; - - $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_MODEL_TRANSCRIPT'); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_TRANSCRIPT").' ('.$ialabel.')'; - $item->defaultFieldValue = ''; - $item->fieldParams['trClass'] = 'iaservice '.$ia; - $item->cssClass = 'minwidth500 input'.$ia; - - $item = $formSetup->newItem('AI_API_'.strtoupper($ia).'_MODEL_TRANSLATE'); // Name of constant must end with _KEY so it is encrypted when saved into database. - $item->nameText = $langs->trans("AI_API_MODEL_TRANSLATE").' ('.$ialabel.')'; - $item->defaultFieldValue = ''; - $item->fieldParams['trClass'] = 'iaservice '.$ia; - $item->cssClass = 'minwidth500 input'.$ia; } $setupnotempty = + count($formSetup->items); diff --git a/htdocs/ai/lib/ai.lib.php b/htdocs/ai/lib/ai.lib.php index 8705f1e961f..5585549d018 100644 --- a/htdocs/ai/lib/ai.lib.php +++ b/htdocs/ai/lib/ai.lib.php @@ -29,24 +29,44 @@ * * @return array> */ -function getLitOfAIFeatures() +function getListOfAIFeatures() { 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') + 'textgenerationemail' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("EmailContent").')', 'picto'=>'', 'status'=>'dolibarr', 'function' => 'TEXT'), + 'textgenerationwebpage' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("WebsitePage").')', 'picto'=>'', 'status'=>'dolibarr', 'function' => 'TEXT'), + 'textgeneration' => array('label' => $langs->trans('TextGeneration').' ('.$langs->trans("Other").')', 'picto'=>'', 'status'=>'notused', 'function' => 'TEXT'), + 'imagegeneration' => array('label' => 'ImageGeneration', 'picto'=>'', 'status'=>'notused', 'function' => 'IMAGE'), + 'videogeneration' => array('label' => 'VideoGeneration', 'picto'=>'', 'status'=>'notused', 'function' => 'VIDEO'), + 'audiogeneration' => array('label' => 'AudioGeneration', 'picto'=>'', 'status'=>'notused', 'function' => 'AUDIO'), + 'transcription' => array('label' => 'Transcription', 'picto'=>'', 'status'=>'notused', 'function' => 'TRANSCRIPT'), + 'translation' => array('label' => 'Translation', 'picto'=>'', 'status'=>'notused', 'function' => 'TRANSLATE') ); return $arrayofaifeatures; } +/** + * Get list of available ai services + * + * @return array> + */ +function getListOfAIServices() +{ + global $langs; + + $arrayofia = array( + '-1' => $langs->trans('SelectAService'), + 'chatgpt' => 'ChatGPT', + 'groq' => 'Groq', + 'custom' => 'Custom' + //'gemini' => 'Gemini' + ); + + return $arrayofia; +} + /** * Prepare admin pages header * diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index ce99bcd8ed4..a1779281e4c 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2519,6 +2519,7 @@ AI_API_MODEL_IMAGE=AI model for image feature AI_API_MODEL_AUDIO=AI model for audio feature AI_API_MODEL_TRANSCRIPT=AI model for transcription feature AI_API_MODEL_TRANSLATE=AI model for translation feature +AI_API_MODEL_VIDEO=AI model for video feature AiSetup=AI module setup AiCustomPrompt=AI custom prompt AI_CONFIGURATIONS_PROMPT=Custom prompt @@ -2621,3 +2622,4 @@ PDF_XXX_SHOW_PRICE_INCL_TAX=Show column Price including tax AvailableWithSomePDFTemplatesOnly=Feature not supported on old PDF templates SelectAService=Select the kind of service to use SelectFeatureToTest=Select the feature to test +AIModelForFeature=AI model for features (AI service %s)