From 56a4dd46db7d489759af538cd1b301fd51bdc747 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Mar 2024 20:41:56 +0100 Subject: [PATCH] Add a log --- htdocs/ai/ajax/generate_content.php | 2 +- htdocs/ai/class/ai.class.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/ai/ajax/generate_content.php b/htdocs/ai/ajax/generate_content.php index 9b1adf13b84e0..f60cef9ee09f3 100644 --- a/htdocs/ai/ajax/generate_content.php +++ b/htdocs/ai/ajax/generate_content.php @@ -67,7 +67,7 @@ $generatedContent = $ai->generateContent($instructions, 'auto', $function); if (is_array($generatedContent) && $generatedContent['error']) { - print "Error : " . $generatedContent['message']; + print "Error returned by API call: " . $generatedContent['message']; } else { print $generatedContent; } diff --git a/htdocs/ai/class/ai.class.php b/htdocs/ai/class/ai.class.php index 399b3adb1ee4b..fd1c7ca17c5a7 100644 --- a/htdocs/ai/class/ai.class.php +++ b/htdocs/ai/class/ai.class.php @@ -64,6 +64,10 @@ public function __construct($db) */ public function generateContent($instructions, $model = 'auto', $function = 'textgeneration') { + if (empty($this->apiKey)) { + return array('error' => true, 'message' => 'API key is no defined'); + } + if (empty($this->apiEndpoint)) { if ($function == 'textgeneration') { $this->apiEndpoint = 'https://api.openai.com/v1/chat/completions'; @@ -97,6 +101,8 @@ public function generateContent($instructions, $model = 'auto', $function = 'tex } } + dol_syslog("Call API for apiEndpoint=".$this->apiEndpoint." apiKey=".substr($this->apiKey, 0, 3).'***********, model='.$model); + try { $configurationsJson = getDolGlobalString('AI_CONFIGURATIONS_PROMPT'); $configurations = json_decode($configurationsJson, true);