Skip to content

Commit

Permalink
fix(openai): dont initialize openai if no apikey is configured
Browse files Browse the repository at this point in the history
  • Loading branch information
clabroche committed Feb 5, 2024
1 parent 82bafa8 commit 0746e78
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions modules/openai/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if (!existsSync(confDir)) mkdirSync(confDir)
const openaiConfPath = pathfs.resolve(confDir, 'openaiconf.json')
if(!fse.existsSync(openaiConfPath)) fse.writeJSONSync(openaiConfPath, {})
const openaiconf = fse.readJsonSync(openaiConfPath)
/** @type {OpenAIApi} */
let openai = new OpenAIApi({
/** @type {OpenAIApi | null} */
let openai = openaiconf.apikey ? new OpenAIApi({
apiKey: openaiconf.apikey,
});
}) : null;


module.exports = () => {
Expand Down Expand Up @@ -140,9 +140,9 @@ module.exports = () => {
const {apikey} = req.body
openaiconf.apikey = apikey
save()
openai = new OpenAIApi({
openai = openaiconf.apikey ? new OpenAIApi({
apiKey: openaiconf.apikey,
});
}) : null;

res.json(true)
})
Expand Down

0 comments on commit 0746e78

Please sign in to comment.