mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
modify code has feedback
This commit is contained in:
parent
7eb0b2b885
commit
8ce483009a
|
|
@ -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 '<br>';
|
||||
}
|
||||
|
||||
|
||||
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 '<br>'.$langs->trans("NothingToSetup");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -29,24 +29,44 @@
|
|||
*
|
||||
* @return array<string,array<string,string>>
|
||||
*/
|
||||
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<string,array<string,string>>
|
||||
*/
|
||||
function getListOfAIServices()
|
||||
{
|
||||
global $langs;
|
||||
|
||||
$arrayofia = array(
|
||||
'-1' => $langs->trans('SelectAService'),
|
||||
'chatgpt' => 'ChatGPT',
|
||||
'groq' => 'Groq',
|
||||
'custom' => 'Custom'
|
||||
//'gemini' => 'Gemini'
|
||||
);
|
||||
|
||||
return $arrayofia;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare admin pages header
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user