Skip to content

Commit

Permalink
chore: upgrade gpt model to gpt-4o-mini
Browse files Browse the repository at this point in the history
  • Loading branch information
dyaskur committed Oct 28, 2024
1 parent dc434f7 commit 804f606
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 479 deletions.
16 changes: 7 additions & 9 deletions helpers/gpt.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {Configuration, OpenAIApi} from 'openai';
import OpenAI from 'openai';

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

const openai = new OpenAIApi(configuration);

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

// eslint-disable-next-line require-jsdoc
export async function getRandomFromGpt(something) {
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt: generatePrompt(something),
const completion = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{role: 'user', content: generatePrompt(something)}],
temperature: 0.6,
max_tokens: 65,
});
let answer = 'Sorry I don\'t know what you mean';
if (completion.data?.choices.length > 0) {
answer = completion.data?.choices.map((a) => a.text.replace(/(\r\n|\n|\r)/gm, '')).join('\n');
if (completion?.choices.length > 0) {
answer = completion.choices.map((a) => a.message.content.replace(/(\r\n|\n|\r)/gm, '')).join('\n');
}
return answer;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@google-cloud/tasks": "^3.1.2",
"googleapis": "^118.0.0",
"openai": "^3.2.1"
"openai": "^4.68.4"
},
"devDependencies": {
"eslint": ">=5.16.0",
Expand Down
Loading

0 comments on commit 804f606

Please sign in to comment.