diff --git a/packages/aila/src/features/rag/rag.fixtures.json b/packages/rag/fixtures.json similarity index 100% rename from packages/aila/src/features/rag/rag.fixtures.json rename to packages/rag/fixtures.json diff --git a/packages/aila/src/features/rag/index.test.ts b/packages/rag/index.test.ts similarity index 98% rename from packages/aila/src/features/rag/index.test.ts rename to packages/rag/index.test.ts index 8e5a6f6e3..a9277882b 100644 --- a/packages/aila/src/features/rag/index.test.ts +++ b/packages/rag/index.test.ts @@ -7,7 +7,7 @@ import { prisma } from "@oakai/db"; // import OpenAI from "openai"; -import ragFixtures from "./rag.fixtures.json"; +import ragFixtures from "./fixtures.json"; // const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }); async function pgVectorSearch({ diff --git a/packages/rag/index.ts b/packages/rag/index.ts new file mode 100644 index 000000000..36c234e33 --- /dev/null +++ b/packages/rag/index.ts @@ -0,0 +1,19 @@ +import { prisma } from "@oakai/db"; +import { aiLogger } from "@oakai/logger"; + +type RagLessonPlan = { + id: string; + oakLessonId: number | null; + oakLessonSlug: string; + ingestLessonId: string | null; + lessonPlan: unknown; + subjectSlug: string; + keyStageSlug: string; + isPublished: boolean; + createdAt: Date; + updatedAt: Date; +}; + +export async function getRagLessonPlans(): Promise { + return await prisma.ragLessonPlan.findMany(); +} diff --git a/packages/rag/jest.config.mjs b/packages/rag/jest.config.mjs new file mode 100644 index 000000000..125c98f56 --- /dev/null +++ b/packages/rag/jest.config.mjs @@ -0,0 +1,40 @@ +import { readFile } from "fs/promises"; +import { pathsToModuleNameMapper } from "ts-jest"; + +const tsconfig = JSON.parse( + await readFile(new URL("./tsconfig.test.json", import.meta.url)), +); + +/** @type {import('ts-jest').JestConfigWithTsJest} */ +const config = { + transform: { + "^.+\\.tsx?$": [ + "ts-jest", + { + tsconfig: "tsconfig.test.json", + useESM: true, + isolatedModules: true, + }, + ], + }, + preset: "ts-jest/presets/default-esm", + moduleNameMapper: { + ...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, { + prefix: "/", + }), + "^(\\.{1,2}/.*)\\.js$": "$1", + }, + extensionsToTreatAsEsm: [".ts"], + testEnvironment: "setup-polly-jest/jest-environment-node", + testMatch: ["**/*.test.ts"], + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + rootDir: ".", + resetMocks: true, + collectCoverage: + process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true", + coverageReporters: ["lcov", "text"], + collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"], + coverageDirectory: "coverage", +}; + +export default config; diff --git a/packages/rag/package.json b/packages/rag/package.json new file mode 100644 index 000000000..ccf733028 --- /dev/null +++ b/packages/rag/package.json @@ -0,0 +1,38 @@ +{ + "name": "@oakai/rag", + "version": "1.0.0", + "description": "", + "keywords": [], + "license": "ISC", + "author": "", + "main": "./index.ts", + "eslintConfig": { + "extends": "@oakai/eslint-config", + "parserOptions": { + "project": "./tsconfig.json" + }, + "rules": {} + }, + "scripts": { + "lint": "eslint .", + "type-check": "tsc --noEmit", + "with-env": "dotenv -e ../../.env --", + "test": "pnpm with-env jest --colors --config jest.config.mjs" + }, + "prettier": "@oakai/prettier-config", + "dependencies": { + "@oakai/aila": "*", + "@oakai/core": "*", + "@oakai/db": "*", + "@oakai/logger": "*", + "zod": "3.23.8" + }, + "devDependencies": { + "@oakai/eslint-config": "*", + "@oakai/prettier-config": "*", + "@types/jest": "^29.5.14", + "jest": "^29.7.0", + "ts-jest": "^29.2.5" + }, + "type": "module" +}