Skip to content

Commit

Permalink
move rag into own package
Browse files Browse the repository at this point in the history
  • Loading branch information
mantagen committed Dec 11, 2024
1 parent f33933b commit f0d8469
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
19 changes: 19 additions & 0 deletions packages/rag/index.ts
Original file line number Diff line number Diff line change
@@ -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<RagLessonPlan[]> {
return await prisma.ragLessonPlan.findMany();
}
40 changes: 40 additions & 0 deletions packages/rag/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -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: "<rootDir>/",
}),
"^(\\.{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;
38 changes: 38 additions & 0 deletions packages/rag/package.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit f0d8469

Please sign in to comment.