update openai

This commit is contained in:
Michael Dausmann
2024-02-17 13:38:18 +11:00
parent 28539e16c3
commit c0c38a8474
4 changed files with 257 additions and 81 deletions

View File

@@ -49,9 +49,9 @@ export namespace NotesService {
Write an interesting short note about ${userPrompt}.
Restrict the note to a single paragraph.
`;
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt,
const completion = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: prompt }],
temperature: 0.6,
stop: '\n\n',
max_tokens: 1000,
@@ -60,6 +60,6 @@ export namespace NotesService {
await AccountService.incrementAIGenCount(account);
return completion.data.choices[0].text;
return completion.choices?.[0]?.message.content?.trim();
}
}

View File

@@ -1,9 +1,5 @@
import { Configuration, OpenAIApi } from 'openai';
import OpenAI from 'openai';
const config = useRuntimeConfig();
const configuration = new Configuration({
apiKey: config.openAIKey
export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
export const openai = new OpenAIApi(configuration);