OpenAI integration and Note generation from prompt

This commit is contained in:
Michael Dausmann
2023-04-29 00:00:52 +10:00
parent d00d048b72
commit 3e3c5e57d7
11 changed files with 171 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import prisma_client from '~~/prisma/prisma.client';
import { openai } from './openai.client';
export default class NotesService {
async getAllNotes() {
@@ -33,4 +34,20 @@ export default class NotesService {
async deleteNote(id: number) {
return prisma_client.note.delete({ where: { id } });
}
async generateAINoteFromPrompt(userPrompt: string) {
const prompt = `
Write an interesting short note about ${userPrompt}.
Restrict the note to a single paragraph.
`
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt,
temperature: 0.6,
stop: "\n\n",
max_tokens: 1000,
n: 1,
});
return completion.data.choices[0].text;
}
}

View File

@@ -0,0 +1,9 @@
import { Configuration, OpenAIApi } from "openai";
const config = useRuntimeConfig();
const configuration = new Configuration({
apiKey: config.openAIKey,
});
export const openai = new OpenAIApi(configuration);