From 59e4e5aa55920c0ae88d1fc7896e6f4192331a87 Mon Sep 17 00:00:00 2001 From: Justin Keiser <41843284+keiserjb@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:16:24 -0500 Subject: [PATCH] Update OpenAIDbLog.inc --- modules/openai_dblog/includes/OpenAIDbLog.inc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/openai_dblog/includes/OpenAIDbLog.inc b/modules/openai_dblog/includes/OpenAIDbLog.inc index 28d1cd3..6730f45 100644 --- a/modules/openai_dblog/includes/OpenAIDbLog.inc +++ b/modules/openai_dblog/includes/OpenAIDbLog.inc @@ -6,7 +6,15 @@ class OpenAIDbLog { public function __construct() { $config = config_get('openai.settings'); - $this->api = new OpenAIApi($config['api_key']); + + // Get the key value using the key module. + $api_key = key_get_key_value($config['api_key']); + + if (empty($api_key)) { + throw new Exception(t('The OpenAI API key is not set or is invalid. Please configure it in the OpenAI settings.')); + } + + $this->api = new OpenAIApi($api_key); } public function getOpenAIExplanation($dblog) {