From 45c17e9fffb7ea0a0fef653a2e8efb956f294dfe Mon Sep 17 00:00:00 2001 From: Gareth Lomax <6199423+gclomax@users.noreply.github.com> Date: Thu, 12 Dec 2024 15:03:18 +0000 Subject: [PATCH] fixed integration bugs due to prisma mismatch. Now finds lesson slug via id - lessonPlan - lesson - slug --- packages/aila/src/core/chat/AilaChat.ts | 3 ++- .../core/quiz/generators/BaseQuizGenerator.ts | 6 ++--- .../quiz/generators/BaseQuizGeneratorTests.ts | 23 +++++++++++++++++++ .../core/quiz/generators/MLQuizGenerator.ts | 6 ++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/aila/src/core/chat/AilaChat.ts b/packages/aila/src/core/chat/AilaChat.ts index 680b75409..48f106d01 100644 --- a/packages/aila/src/core/chat/AilaChat.ts +++ b/packages/aila/src/core/chat/AilaChat.ts @@ -101,7 +101,8 @@ export class AilaChat implements AilaChatService { quizRatingSchema: testRatingSchema, quizSelector: "simple", quizReranker: "return-first", - quizGenerators: ["ml", "rag", "basedOnRag"], + // quizGenerators: ["ml", "rag", "basedOnRag"], + quizGenerators: ["basedOnRag"], }); } // TODO: GCLOMAX This should be put in a new class called AilaQuizService, in the ailaservices class. diff --git a/packages/aila/src/core/quiz/generators/BaseQuizGenerator.ts b/packages/aila/src/core/quiz/generators/BaseQuizGenerator.ts index 3e2690bf9..9d748aa98 100644 --- a/packages/aila/src/core/quiz/generators/BaseQuizGenerator.ts +++ b/packages/aila/src/core/quiz/generators/BaseQuizGenerator.ts @@ -86,14 +86,14 @@ export abstract class BaseQuizGenerator implements AilaQuizGeneratorService { public async getLessonSlugFromPlanId(planId: string): Promise { try { - const result = await prisma.lesson.findUnique({ + const result = await prisma.lessonPlan.findUnique({ where: { id: planId }, select: { - slug: true, + lesson: true, }, }); - return result?.slug || null; + return result?.lesson.slug || null; } catch (error) { console.error("Error fetching lesson slug:", error); return null; diff --git a/packages/aila/src/core/quiz/generators/BaseQuizGeneratorTests.ts b/packages/aila/src/core/quiz/generators/BaseQuizGeneratorTests.ts index 13b0f102a..774f5140c 100644 --- a/packages/aila/src/core/quiz/generators/BaseQuizGeneratorTests.ts +++ b/packages/aila/src/core/quiz/generators/BaseQuizGeneratorTests.ts @@ -88,5 +88,28 @@ export const runCommonQuizGeneratorTests = ( ).rejects.toBeDefined(); }); }); + + // [ + // 'DSemIaiDytA0PtrHTo9Zq', + // '0ChBXkONXh8IOVS00iTlm', + // 'LnViNV0cVTEaiunKzumPs', + // 'R3IrL-ct9sSAhpsz7lgrE', + // 'AGtKSucW7OTUKiswiHfJ9' + // ] + describe("Question Array From Plan Id", () => { + it("should handle invalid lesson plans gracefully", async () => { + await expect( + generator.questionArrayFromPlanId("invalid-plan-id"), + ).rejects.toBeDefined(); + }); + it("should handle valid lesson plans gracefully", async () => { + const result = await generator.questionArrayFromPlanId( + "clna7lofy0og0p4qxju5j6z56", + ); + expect(result).toBeDefined(); + expect(Array.isArray(result)).toBe(true); + expect(result.length).toBeGreaterThan(0); + }); + }); }); }; diff --git a/packages/aila/src/core/quiz/generators/MLQuizGenerator.ts b/packages/aila/src/core/quiz/generators/MLQuizGenerator.ts index 037e8baea..c3d568048 100644 --- a/packages/aila/src/core/quiz/generators/MLQuizGenerator.ts +++ b/packages/aila/src/core/quiz/generators/MLQuizGenerator.ts @@ -25,10 +25,8 @@ export class MLQuizGenerator extends BaseQuizGenerator { // Check for minimum required properties if ( !( - typeof lessonPlan === "object" && - "title" in lessonPlan && - "keyStage" in lessonPlan && - "topic" in lessonPlan + ("title" in lessonPlan && "keyStage" in lessonPlan) + // "topic" in lessonPlan ) ) { throw new Error("Invalid lesson plan: missing required properties");