29if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOREQUIREAJAX')) {
39 define(
'NOREQUIREAJAX',
'1');
41if (!defined(
'NOREQUIRESOC')) {
42 define(
'NOREQUIRESOC',
'1');
45require
'../../main.inc.php';
47require_once DOL_DOCUMENT_ROOT.
'/ai/class/ai.class.php';
49if (!isModEnabled(
'ai')) {
61$rawData = file_get_contents(
'php://input');
62$jsonData = json_decode($rawData,
true);
64if (is_null($jsonData)) {
70$function = empty($jsonData[
'function']) ?
'textgeneration' : $jsonData[
'function'];
72$format = empty($jsonData[
'format']) ?
'' : $jsonData[
'format'];
74$generatedContent = $ai->generateContent($instructions,
'auto', $function, $format);
76if (is_array($generatedContent) && $generatedContent[
'error']) {
78 if (!empty($generatedContent[
'code']) && $generatedContent[
'code'] == 429) {
79 print
"Quota or allowed period exceeded. Retry Later !";
80 } elseif ($generatedContent[
'code'] >= 400) {
81 print
"Error : " . $generatedContent[
'message'];
82 print
'<br><a href="'.DOL_MAIN_URL_ROOT.
'/ai/admin/setup.php">'.$langs->trans(
'ErrorGoToModuleSetup').
'</a>';
84 print
"Error returned by API call: " . $generatedContent[
'message'];
87 if ($function ==
'textgenerationemail' || $function ==
'textgenerationwebpage') {
89 } elseif ($function ==
'imagegeneration') {
91 } elseif ($function ==
'videogeneration') {
93 } elseif ($function ==
'audiogeneration') {
dolPrintHTML($s, $allowiframe=0)
Return a string (that can be on several lines) ready to be output on a HTML page.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolPrintText($s)
Return a string label (possible on several lines and that should not contains any HTML) ready to be o...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.