From 58892d8b63b51c07d8dc3be3365f19f35c12993d Mon Sep 17 00:00:00 2001 From: arcticfly <41524992+arcticfly@users.noreply.github.com> Date: Wed, 19 Jul 2023 13:59:11 -0700 Subject: [PATCH] Remove unused fields, refine model translation (#62) * Remove unused ScenarioVariantCell fields * Refine deriveNewConstructFn * Fix prettier --- .../migration.sql | 16 +++++++ prisma/schema.prisma | 5 -- .../migrateScenarioVariantOutputData.ts | 47 ------------------- src/server/utils/deriveNewContructFn.ts | 6 ++- 4 files changed, 21 insertions(+), 53 deletions(-) create mode 100644 prisma/migrations/20230719181731_remove_duplicate_scenario_variant_cell_fields/migration.sql delete mode 100644 src/server/scripts/migrateScenarioVariantOutputData.ts diff --git a/prisma/migrations/20230719181731_remove_duplicate_scenario_variant_cell_fields/migration.sql b/prisma/migrations/20230719181731_remove_duplicate_scenario_variant_cell_fields/migration.sql new file mode 100644 index 0000000..599906a --- /dev/null +++ b/prisma/migrations/20230719181731_remove_duplicate_scenario_variant_cell_fields/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - You are about to drop the column `completionTokens` on the `ScenarioVariantCell` table. All the data in the column will be lost. + - You are about to drop the column `inputHash` on the `ScenarioVariantCell` table. All the data in the column will be lost. + - You are about to drop the column `output` on the `ScenarioVariantCell` table. All the data in the column will be lost. + - You are about to drop the column `promptTokens` on the `ScenarioVariantCell` table. All the data in the column will be lost. + - You are about to drop the column `timeToComplete` on the `ScenarioVariantCell` table. All the data in the column will be lost. + +*/ +-- AlterTable +ALTER TABLE "ScenarioVariantCell" DROP COLUMN "completionTokens", +DROP COLUMN "inputHash", +DROP COLUMN "output", +DROP COLUMN "promptTokens", +DROP COLUMN "timeToComplete"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 1afa8fc..2dfa6f5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -88,17 +88,12 @@ enum CellRetrievalStatus { model ScenarioVariantCell { id String @id @default(uuid()) @db.Uuid - inputHash String? // TODO: Remove once migration is complete - output Json? // TODO: Remove once migration is complete statusCode Int? errorMessage String? - timeToComplete Int? @default(0) // TODO: Remove once migration is complete retryTime DateTime? streamingChannel String? retrievalStatus CellRetrievalStatus @default(COMPLETE) - promptTokens Int? // TODO: Remove once migration is complete - completionTokens Int? // TODO: Remove once migration is complete modelOutput ModelOutput? promptVariantId String @db.Uuid diff --git a/src/server/scripts/migrateScenarioVariantOutputData.ts b/src/server/scripts/migrateScenarioVariantOutputData.ts deleted file mode 100644 index 99984fa..0000000 --- a/src/server/scripts/migrateScenarioVariantOutputData.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { type Prisma } from "@prisma/client"; -import { prisma } from "../db"; - -async function migrateScenarioVariantOutputData() { - // Get all ScenarioVariantCells - const cells = await prisma.scenarioVariantCell.findMany({ include: { modelOutput: true } }); - console.log(`Found ${cells.length} records`); - - let updatedCount = 0; - - // Loop through all scenarioVariants - for (const cell of cells) { - // Create a new ModelOutput for each ScenarioVariant with an existing output - if (cell.output && !cell.modelOutput) { - updatedCount++; - await prisma.modelOutput.create({ - data: { - scenarioVariantCellId: cell.id, - inputHash: cell.inputHash || "", - output: cell.output as Prisma.InputJsonValue, - timeToComplete: cell.timeToComplete ?? undefined, - promptTokens: cell.promptTokens, - completionTokens: cell.completionTokens, - createdAt: cell.createdAt, - updatedAt: cell.updatedAt, - }, - }); - } else if (cell.errorMessage && cell.retrievalStatus === "COMPLETE") { - updatedCount++; - await prisma.scenarioVariantCell.update({ - where: { id: cell.id }, - data: { - retrievalStatus: "ERROR", - }, - }); - } - } - - console.log("Data migration completed"); - console.log(`Updated ${updatedCount} records`); -} - -// Execute the function -migrateScenarioVariantOutputData().catch((error) => { - console.error("An error occurred while migrating data: ", error); - process.exit(1); -}); diff --git a/src/server/utils/deriveNewContructFn.ts b/src/server/utils/deriveNewContructFn.ts index 3fbd0c7..77aef3a 100644 --- a/src/server/utils/deriveNewContructFn.ts +++ b/src/server/utils/deriveNewContructFn.ts @@ -49,12 +49,16 @@ const getPromptFunctionForNewModel = async ( getApiShapeForModel(originalModel), null, 2, - )}\n\nThe prompt variable has already been declared.}`, + )}`, }, { role: "user", content: `Return the prompt constructor function for ${newModel} given the following prompt constructor function for ${originalModel}:\n---\n${originalVariant.constructFn}`, }, + { + role: "user", + content: "The prompt variable has already been declared, so do not declare it again.", + }, ], functions: [ {