-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aila Categoriser feature with Chat ID and User ID
- Loading branch information
Showing
14 changed files
with
219 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/aila/src/features/categorisation/categorisers/AilaCategorisation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { RAG } from "@oakai/core/src/rag"; | ||
import { | ||
type PrismaClientWithAccelerate, | ||
prisma as globalPrisma, | ||
} from "@oakai/db"; | ||
|
||
import { AilaServices, Message } from "../../../core"; | ||
import { LooseLessonPlan } from "../../../protocol/schema"; | ||
import { AilaCategorisationFeature } from "../../types"; | ||
|
||
export class AilaCategorisation implements AilaCategorisationFeature { | ||
private _aila: AilaServices; | ||
private _prisma: PrismaClientWithAccelerate; | ||
private _chatId: string; | ||
private _userId: string | undefined; | ||
constructor({ | ||
aila, | ||
prisma, | ||
chatId, | ||
userId, | ||
}: { | ||
aila: AilaServices; | ||
prisma?: PrismaClientWithAccelerate; | ||
chatId: string; | ||
userId?: string; | ||
}) { | ||
this._aila = aila; | ||
this._prisma = prisma ?? globalPrisma; | ||
this._chatId = chatId; | ||
this._userId = userId; | ||
} | ||
public async categorise( | ||
messages: Message[], | ||
lessonPlan: LooseLessonPlan, | ||
): Promise<LooseLessonPlan | undefined> { | ||
const { title, subject, keyStage, topic } = lessonPlan; | ||
const input = messages.map((i) => i.content).join("\n\n"); | ||
const categorisationInput = [title, subject, keyStage, topic, input] | ||
.filter((i) => i) | ||
.join(" "); | ||
|
||
const result = await this.fetchCategorisedInput( | ||
categorisationInput, | ||
this._prisma, | ||
); | ||
return result; | ||
} | ||
|
||
private async fetchCategorisedInput( | ||
input: string, | ||
prisma: PrismaClientWithAccelerate, | ||
): Promise<LooseLessonPlan | undefined> { | ||
const rag = new RAG(prisma, { | ||
chatId: this._chatId, | ||
userId: this._userId, | ||
}); | ||
const parsedCategorisation = await rag.categoriseKeyStageAndSubject(input, { | ||
chatId: this._chatId, | ||
userId: this._userId, | ||
}); | ||
const { keyStage, subject, title, topic } = parsedCategorisation; | ||
const plan: LooseLessonPlan = { | ||
keyStage: keyStage ?? undefined, | ||
subject: subject ?? undefined, | ||
title: title ?? undefined, | ||
topic: topic ?? undefined, | ||
}; | ||
return plan; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/aila/src/features/categorisation/categorisers/MockCategoriser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LooseLessonPlan } from "../../../protocol/schema"; | ||
import { AilaCategorisationFeature } from "../../types"; | ||
|
||
export class MockCategoriser implements AilaCategorisationFeature { | ||
private _mockedLessonPlan: LooseLessonPlan | undefined; | ||
constructor({ | ||
mockedLessonPlan, | ||
}: { | ||
mockedLessonPlan: LooseLessonPlan | undefined; | ||
}) { | ||
this._mockedLessonPlan = mockedLessonPlan; | ||
} | ||
public async categorise(): Promise<LooseLessonPlan | undefined> { | ||
return this._mockedLessonPlan; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AilaCategorisation } from "./categorisers/AilaCategorisation"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.