🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(score_config): add table via migration (#2126)
marliessophiea6d8ce8c96ed
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.tsindex a684dc9a91..9946e3e9d4 100644--- a/packages/shared/prisma/generated/types.ts+++ b/packages/shared/prisma/generated/types.ts@@ -30,6 +30,11 @@ export const ScoreSource = {EVAL: "EVAL"} as const;export type ScoreSource = (typeof ScoreSource)[keyof typeof ScoreSource];+export const ScoreDataType = {+ CATEGORICAL: "CATEGORICAL",+ NUMERIC: "NUMERIC"+} as const;+export type ScoreDataType = (typeof ScoreDataType)[keyof typeof ScoreDataType];export const PricingUnit = {PER_1000_TOKENS: "PER_1000_TOKENS",PER_1000_CHARS: "PER_1000_CHARS"@@ -351,6 +356,22 @@ export type Score = {comment: string | null;trace_id: string;observation_id: string | null;+ config_id: string | null;+ string_value: string | null;+ data_type: Generated<ScoreDataType>;+};+export type ScoreConfig = {+ id: string;+ created_at: Generated<Timestamp>;+ updated_at: Generated<Timestamp>;+ project_id: string;+ name: string;+ data_type: ScoreDataType;+ is_archived: Generated<boolean>;+ min_value: number | null;+ max_value: number | null;+ categories: unknown | null;+ description: string | null;};export type Session = {id: string;@@ -450,6 +471,7 @@ export type DB = {project_memberships: ProjectMembership;projects: Project;prompts: Prompt;+ score_configs: ScoreConfig;scores: Score;Session: Session;sso_configs: SsoConfig;diff --git a/packages/shared/prisma/migrations/20240523142425_score_config_add_table/migration.sql b/packages/shared/prisma/migrations/20240523142425_score_config_add_table/migration.sqlnew file mode 100644index 0000000000..873f6a387e--- /dev/null+++ b/packages/shared/prisma/migrations/20240523142425_score_config_add_table/migration.sql@@ -0,0 +1,42 @@+-- CreateEnum+CREATE TYPE "ScoreDataType" AS ENUM ('CATEGORICAL', 'NUMERIC');++-- AlterTable+ALTER TABLE "scores" ADD COLUMN "config_id" TEXT,+ADD COLUMN "data_type" "ScoreDataType" NOT NULL DEFAULT 'NUMERIC',+ADD COLUMN "string_value" TEXT;++-- CreateTable+CREATE TABLE "score_configs" (+ "id" TEXT NOT NULL,+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,+ "project_id" TEXT NOT NULL,+ "name" TEXT NOT NULL,+ "data_type" "ScoreDataType" NOT NULL,+ "is_archived" BOOLEAN NOT NULL DEFAULT false,+ "min_value" DOUBLE PRECISION,+ "max_value" DOUBLE PRECISION,+ "categories" JSONB,+ "description" TEXT,++ CONSTRAINT "score_configs_pkey" PRIMARY KEY ("id")+);++-- CreateIndex+CREATE INDEX "score_configs_data_type_idx" ON "score_configs"("data_type");++-- CreateIndex+CREATE INDEX "score_configs_is_archived_idx" ON "score_configs"("is_archived");++-- CreateIndex+CREATE INDEX "score_configs_project_id_idx" ON "score_configs"("project_id");++-- CreateIndex+CREATE INDEX "score_configs_categories_idx" ON "score_configs"("categories");++-- CreateIndex+CREATE UNIQUE INDEX "score_configs_id_project_id_key" ON "score_configs"("id", "project_id");++-- AddForeignKey+ALTER TABLE "score_configs" ADD CONSTRAINT "score_configs_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE CASCADE ON UPDATE CASCADE;diff --git a/packages/shared/prisma/migrations/20240523142524_scores_add_config_id_idx/migration.sql b/packages/shared/prisma/migrations/20240523142524_scores_add_config_id_idx/migration.sqlnew file mode 100644index 0000000000..db29bd29e1--- /dev/null+++ b/packages/shared/prisma/migrations/20240523142524_scores_add_config_id_idx/migration.sql@@ -0,0 +1,2 @@+-- CreateIndex+CREATE INDEX CONCURRENTLY "scores_config_id_idx" ON "scores"("config_id");diff --git a/packages/shared/prisma/migrations/20240523142610_scores_add_fk_scores_config_id/migration.sql b/packages/shared/prisma/migrations/20240523142610_scores_add_fk_scores_config_id/migration.sqlnew file mode 100644index 0000000000..481533bc1f--- /dev/null+++ b/packages/shared/prisma/migrations/20240523142610_scores_add_fk_scores_config_id/migration.sql@@ -0,0 +1,2 @@+-- AddForeignKey+ALTER TABLE "scores" ADD CONSTRAINT "scores_config_id_fkey" FOREIGN KEY ("config_id") REFERENCES "score_configs"("id") ON DELETE SET NULL ON UPDATE CASCADE;diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prismaindex 96d8feba98..bff1c6c8c4 100644--- a/packages/shared/prisma/schema.prisma+++ b/packages/shared/prisma/schema.prisma@@ -114,6 +114,7 @@ model Project {LlmApiKeys LlmApiKeys[]PosthogIntegration PosthogIntegration[]Score Score[]+ scoreConfig ScoreConfig[]@@map("projects")}@@ -403,13 +404,18 @@ model Score {comment String?traceId String @map("trace_id")observationId String? @map("observation_id")+ configId String? @map("config_id")+ stringValue String? @map("string_value")+ dataType ScoreDataType @default(NUMERIC) @map("data_type")JobExecution JobExecution[]+ scoreConfig ScoreConfig? @relation(fields: [configId], references: [id], onDelete: SetNull)@@unique([id, projectId]) // used for upserts via prisma@@index(timestamp)@@index([value])@@index([projectId])@@index([authorUserId])+ @@index([configId])@@index([traceId], type: Hash)@@index([observationId], type: Hash)@@index([source])@@ -422,6 +428,34 @@ enum ScoreSource {EVAL}+model ScoreConfig {+ id String @id @default(cuid())+ createdAt DateTime @default(now()) @map("created_at")+ updatedAt DateTime @default(now()) @updatedAt @map("updated_at")+ projectId String @map("project_id")+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)+ name String+ dataType ScoreDataType @map("data_type")+ isArchived Boolean @default(false) @map("is_archived")+ minValue Float? @map("min_value")+ maxValue Float? @map("max_value")+ categories Json? @map("categories")+ description String?+ score Score[]++ @@unique([id, projectId]) // used for upserts via prisma+ @@index([dataType])+ @@index([isArchived])+ @@index([projectId])+ @@index([categories])+ @@map("score_configs")+}++enum ScoreDataType {+ CATEGORICAL+ NUMERIC+}+enum PricingUnit {PER_1000_TOKENSPER_1000_CHARSdiff --git a/web/src/__tests__/scores.servertest.ts b/web/src/__tests__/scores.servertest.tsindex 6fe5cfc0c0..9042030c20 100644--- a/web/src/__tests__/scores.servertest.ts+++ b/web/src/__tests__/scores.servertest.ts@@ -490,14 +490,14 @@ describe("/api/public/scores API Endpoint", () => {});expect(getScore.body.data).toMatchObject([{- id: scoreId_1,+ id: scoreId_2,name: scoreName,- value: 10.5,+ value: 50.5,},{- id: scoreId_2,+ id: scoreId_1,name: scoreName,- value: 50.5,+ value: 10.5,},]);});@@ -515,14 +515,14 @@ describe("/api/public/scores API Endpoint", () => {});expect(getScore.body.data).toMatchObject([{- id: scoreId_2,+ id: scoreId_3,name: scoreName,- value: 50.5,+ value: 100.8,},{- id: scoreId_3,+ id: scoreId_2,name: scoreName,- value: 100.8,+ value: 50.5,},]);});@@ -540,14 +540,14 @@ describe("/api/public/scores API Endpoint", () => {});expect(getScore.body.data).toMatchObject([{- id: scoreId_1,+ id: scoreId_3,name: scoreName,- value: 10.5,+ value: 100.8,},{- id: scoreId_3,+ id: scoreId_1,name: scoreName,- value: 100.8,+ value: 10.5,},]);});diff --git a/worker/generated/types.ts b/worker/generated/types.tsindex c38b007b96..e0e48013bc 100644--- a/worker/generated/types.ts+++ b/worker/generated/types.ts@@ -33,6 +33,11 @@ export const ScoreSource = {EVAL: "EVAL",} as const;export type ScoreSource = (typeof ScoreSource)[keyof typeof ScoreSource];+export const ScoreDataType = {+ CATEGORICAL: "CATEGORICAL",+ NUMERIC: "NUMERIC",+} as const;+export type ScoreDataType = (typeof ScoreDataType)[keyof typeof ScoreDataType];export const PricingUnit = {PER_1000_TOKENS: "PER_1000_TOKENS",PER_1000_CHARS: "PER_1000_CHARS",@@ -356,6 +361,22 @@ export type Score = {comment: string | null;trace_id: string;observation_id: string | null;+ config_id: string | null;+ string_value: string | null;+ data_type: Generated<ScoreDataType>;+};+export type ScoreConfig = {+ id: string;+ created_at: Generated<Timestamp>;+ updated_at: Generated<Timestamp>;+ project_id: string;+ name: string;+ data_type: ScoreDataType;+ is_archived: Generated<boolean>;+ min_value: number | null;+ max_value: number | null;+ categories: unknown | null;+ description: string | null;};export type Session = {id: string;@@ -455,6 +476,7 @@ export type DB = {project_memberships: ProjectMembership;projects: Project;prompts: Prompt;+ score_configs: ScoreConfig;scores: Score;Session: Session;sso_configs: SsoConfig;