Skip to content

Commit

Permalink
Create the prompt variant if none exists
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl committed Aug 28, 2024
1 parent c7302d8 commit 6c1185b
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/aila/src/features/generation/AilaGeneration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { prisma } from "@oakai/db";
import { PromptVariants } from "@oakai/core/src/models/promptVariants";
import { ailaGenerate } from "@oakai/core/src/prompts/lesson-assistant/variants";
import { prisma, Prompt } from "@oakai/db";
import { getEncoding } from "js-tiktoken";

import { AilaServices } from "../../core";
Expand Down Expand Up @@ -151,15 +153,30 @@ export class AilaGeneration {
// This key is defined in the setupPrompts script in core
const variantSlug = `${responseMode}-${basedOn ? "basedOn" : "notBasedOn"}-${useRag ? "rag" : "noRag"}`;

const prompt = await prisma.prompt.findFirst({
let prompt: Prompt | null = null;
prompt = await prisma.prompt.findFirst({
where: {
variant: variantSlug,
appId: appSlug,
slug: promptSlug,
},
});
if (!prompt) {
throw new Error(`Prompt not found - have you run pnpm prompts:dev?`);
// If the prompt does not exist for this variant, we need to generate it
const prompts = new PromptVariants(prisma, ailaGenerate, promptSlug);
prompts.setCurrent(variantSlug, true);
prompt = await prisma.prompt.findFirst({
where: {
variant: variantSlug,
appId: appSlug,
slug: promptSlug,
},
});
}
if (!prompt) {
throw new Error(
"Prompt not found - please run pnpm prompts or pnpm prompts:dev in development",
);
}
return prompt?.id;
}
Expand Down

0 comments on commit 6c1185b

Please sign in to comment.