Skip to content

Commit c0c38a8

Browse files
update openai
1 parent 28539e1 commit c0c38a8

File tree

4 files changed

+259
-83
lines changed

4 files changed

+259
-83
lines changed

lib/services/notes.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export namespace NotesService {
4949
Write an interesting short note about ${userPrompt}.
5050
Restrict the note to a single paragraph.
5151
`;
52-
const completion = await openai.createCompletion({
53-
model: 'text-davinci-003',
54-
prompt,
52+
const completion = await openai.chat.completions.create({
53+
model: 'gpt-3.5-turbo',
54+
messages: [{ role: 'user', content: prompt }],
5555
temperature: 0.6,
5656
stop: '\n\n',
5757
max_tokens: 1000,
@@ -60,6 +60,6 @@ export namespace NotesService {
6060

6161
await AccountService.incrementAIGenCount(account);
6262

63-
return completion.data.choices[0].text;
63+
return completion.choices?.[0]?.message.content?.trim();
6464
}
6565
}

lib/services/openai.client.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import { Configuration, OpenAIApi } from 'openai';
1+
import OpenAI from 'openai';
22

3-
const config = useRuntimeConfig();
4-
5-
const configuration = new Configuration({
6-
apiKey: config.openAIKey
3+
export const openai = new OpenAI({
4+
apiKey: process.env.OPENAI_API_KEY
75
});
8-
9-
export const openai = new OpenAIApi(configuration);

0 commit comments

Comments
 (0)