Skip to content

Commit

Permalink
refactor: initiate openAI inside a function
Browse files Browse the repository at this point in the history
  • Loading branch information
dyaskur committed Oct 28, 2024
1 parent ab6f6b6 commit a534c5a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions helpers/gpt.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});

/**
* @param {string} something - thing that will get a random of it
* @returns {string} the prompt for gpt
Expand All @@ -14,6 +10,10 @@ function generatePrompt(something) {

// eslint-disable-next-line require-jsdoc
export async function getRandomFromGpt(something) {
const openai = new OpenAI({
apiKey: process.env?.OPENAI_API_KEY,
});

const completion = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{role: 'user', content: generatePrompt(something)}],
Expand Down

0 comments on commit a534c5a

Please sign in to comment.