* Copyright (C) 2005-2016 Regis Houssin * Copyright (C) 2012 J. Fernando Lagrange * Copyright (C) 2015 Raphaƫl Doursenaud * Copyright (C) 2023 Eric Seigne * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * or see https://www.gnu.org/ */ /** * \file htdocs/ai/lib/generate_content.lib.php * \brief Library of ai script */ if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); // Disables token renewal } if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); } if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); } if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } if (!defined('NOREQUIRESOC')) { define('NOREQUIRESOC', '1'); } require_once '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/ai/class/ai.class.php'; //get data from AJAX $rawData = file_get_contents('php://input'); $jsonData = json_decode($rawData, true); if (is_null($jsonData)) { dol_print_error('data with format JSON valide.'); } $token = GETPOST('token'); if ($token !== currentToken()) { // Remplacez 'newToken' par le nom de votre variable de session contenant le token dol_print_error('CSRF token validation failed.'); exit; } $chatGPT = new Ai('API_ENDPOINT', 'API_KEY'); $instructions = dol_string_nohtmltag($jsonData['instructions'], 1, 'UTF-8'); $generatedContent = $chatGPT->generateContent($instructions); if ($generatedContent) { print $generatedContent; } else { dol_print_error('error!!'); }