useage limits on OpenAI requests. closes #12

This commit is contained in:
Michael Dausmann
2023-09-10 22:46:32 +10:00
parent caf65a48c1
commit d65705732e
10 changed files with 95 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import prisma_client from '~~/prisma/prisma.client';
import { openai } from './openai.client';
import { AccountLimitError } from './errors';
import AccountService from './account.service';
export default class NotesService {
async getAllNotes() {
@@ -36,7 +37,10 @@ export default class NotesService {
return prisma_client.note.delete({ where: { id } });
}
async generateAINoteFromPrompt(userPrompt: string) {
async generateAINoteFromPrompt(userPrompt: string, account_id: number) {
const accountService = new AccountService();
const account = await accountService.checkAIGenCount(account_id);
const prompt = `
Write an interesting short note about ${userPrompt}.
Restrict the note to a single paragraph.
@@ -49,6 +53,9 @@ export default class NotesService {
max_tokens: 1000,
n: 1,
});
await accountService.incrementAIGenCount(account);
return completion.data.choices[0].text;
}
}