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';
 
   57if (!isModEnabled(
'ai')) {
 
   69$rawData = file_get_contents(
'php://input');
 
   70$jsonData = json_decode($rawData, 
true);
 
   72if (is_null($jsonData)) {
 
   78$function = empty($jsonData[
'function']) ? 
'textgeneration' : $jsonData[
'function'];  
 
   80$format = empty($jsonData[
'format']) ? 
'' : $jsonData[
'format'];
 
   82$generatedContent = $ai->generateContent($instructions, 
'auto', $function, $format);
 
   84if (is_array($generatedContent) && $generatedContent[
'error']) {
 
   86  if (!empty($generatedContent[
'code']) && $generatedContent[
'code'] == 429) {
 
   87    print 
"Quota or allowed period exceeded. Retry Later !";
 
   88  } elseif ($generatedContent[
'code'] >= 400) {
 
   89    print 
"Error : " . $generatedContent[
'message'];
 
   90    print 
'<br><a href="'.DOL_MAIN_URL_ROOT.
'/ai/admin/setup.php">'.$langs->trans(
'ErrorGoToModuleSetup').
'</a>';
 
   92    print 
"Error returned by API call: " . $generatedContent[
'message'];
 
   95  if ($function == 
'textgenerationemail' || $function == 
'textgenerationwebpage') {
 
   97  } elseif ($function == 
'imagegeneration') {
 
   99  } elseif ($function == 
'videogeneration') {
 
  101  } 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.