From 3e871cb72423b1be336fe347f2376f58bb47a031 Mon Sep 17 00:00:00 2001 From: Zaki-1052 Date: Fri, 14 Jun 2024 12:08:02 -0700 Subject: [PATCH] key fix --- server.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index d9e2df5..58e9723 100644 --- a/server.js +++ b/server.js @@ -33,11 +33,13 @@ const OpenAI = require('openai').default; // Check if the OPENAI_API_KEY environment variable is set const apiKey = process.env.OPENAI_API_KEY; +let openai; // Declare openai outside the conditional block + if (!apiKey) { console.warn("Warning: The OPENAI_API_KEY environment variable is missing. OpenAI features will be disabled."); } else { // Initialize OpenAI only if the API key is present - const openai = new OpenAI({ + openai = new OpenAI({ apiKey: apiKey }); }