Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

chore: remove database pruning from worker tests (#12196)

Max Deichmann7af02d8274ac
diff --git a/worker/src/__tests__/evalService.filtering.test.ts b/worker/src/__tests__/evalService.filtering.test.ts
index 58015dd2f9..5fd4bc1cff 100644
--- a/worker/src/__tests__/evalService.filtering.test.ts
+++ b/worker/src/__tests__/evalService.filtering.test.ts
@@ -21,7 +21,6 @@ import { afterAll, test as baseTest, beforeAll, describe } from "vitest";
import { z } from "zod/v4";
import { createEvalJobs } from "../features/evaluation/evalService";
import { OpenAIServer } from "./network";
-import { pruneDatabase } from "./utils";
let OPENAI_API_KEY = process.env.OPENAI_API_KEY;
// Check for both OPENAI_API_KEY and LANGFUSE_LLM_CONNECTION_OPENAI_KEY
@@ -39,7 +38,6 @@ const openAIServer = new OpenAIServer({
beforeAll(openAIServer.setup);
beforeAll(async () => {
- await pruneDatabase();
openAIServer.respondWithDefault();
});
afterAll(openAIServer.teardown);
diff --git a/worker/src/__tests__/experimentsService.test.ts b/worker/src/__tests__/experimentsService.test.ts
index f555d94cf0..b3a7ef64a5 100644
--- a/worker/src/__tests__/experimentsService.test.ts
+++ b/worker/src/__tests__/experimentsService.test.ts
@@ -1,11 +1,14 @@
import { expect, test, describe, beforeEach, vi, afterEach } from "vitest";
import { prisma } from "@langfuse/shared/src/db";
import { randomUUID } from "crypto";
-import { pruneDatabase } from "./utils";
import { LLMAdapter } from "@langfuse/shared";
import { encrypt } from "@langfuse/shared/encryption";
import { createExperimentJobClickhouse } from "../features/experiments/experimentServiceClickhouse";
-import { createDatasetItem, logger } from "@langfuse/shared/src/server";
+import {
+ createDatasetItem,
+ createOrgProjectAndApiKey,
+ logger,
+} from "@langfuse/shared/src/server";
// Mock the logger to capture log calls
vi.mock("@langfuse/shared/src/server", async () => {
@@ -26,7 +29,6 @@ describe("create experiment jobs", () => {
const mockLogger = vi.mocked(logger);
beforeEach(async () => {
- await pruneDatabase();
vi.clearAllMocks();
});
@@ -34,10 +36,10 @@ describe("create experiment jobs", () => {
vi.restoreAllMocks();
});
test("processes valid experiment without throwing", async () => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
- const promptId = "03f834cc-c089-4bcb-9add-b14cadcdf47c";
+ const promptId = randomUUID();
// Create required prompt
await prisma.prompt.create({
@@ -116,7 +118,7 @@ describe("create experiment jobs", () => {
});
test("handles experiment validation failure (missing prompt_id) without throwing", async () => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
@@ -170,10 +172,10 @@ describe("create experiment jobs", () => {
});
test("handles prompt with variables without throwing", async () => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
- const promptId = "03f834cc-c089-4bcb-9add-b14cadcdf47c";
+ const promptId = randomUUID();
// Create dataset
await prisma.dataset.create({
@@ -245,10 +247,10 @@ describe("create experiment jobs", () => {
});
test("handles mismatched dataset variables without throwing", async () => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
- const promptId = "03f834cc-c089-4bcb-9add-b14cadcdf47c";
+ const promptId = randomUUID();
// Create prompt with variable that won't match dataset item
await prisma.prompt.create({
data: {
@@ -321,7 +323,6 @@ describe("create experiment jobs with placeholders", () => {
const mockLogger = vi.mocked(logger);
beforeEach(async () => {
- await pruneDatabase();
vi.clearAllMocks();
});
@@ -329,10 +330,10 @@ describe("create experiment jobs with placeholders", () => {
promptConfig: any,
datasetItemInput: any,
) => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
- const promptId = "03f834cc-c089-4bcb-9add-b14cadcdf47c";
+ const promptId = randomUUID();
// Create prompt
await prisma.prompt.create({
data: {
@@ -474,15 +475,14 @@ describe("create experiment jobs with placeholders", () => {
describe("experiment processing integration", () => {
beforeEach(async () => {
- await pruneDatabase();
vi.clearAllMocks();
});
test("processes experiment end-to-end without throwing", async () => {
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+ const { projectId } = await createOrgProjectAndApiKey();
const datasetId = randomUUID();
const runId = randomUUID();
- const promptId = "03f834cc-c089-4bcb-9add-b14cadcdf47c";
+ const promptId = randomUUID();
// Create required prompt
await prisma.prompt.create({
diff --git a/worker/src/__tests__/utils.ts b/worker/src/__tests__/utils.ts
deleted file mode 100644
index d9ab4c9789..0000000000
--- a/worker/src/__tests__/utils.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { prisma } from "@langfuse/shared/src/db";
-
-import { env } from "../env";
-import { logger } from "@langfuse/shared/src/server";
-export const pruneDatabase = async () => {
- if (!env.DATABASE_URL.includes("localhost:5432")) {
- throw new Error("You cannot prune database unless running on localhost.");
- }
-
- logger.info("Pruning database");
- await prisma.datasetItem.deleteMany();
- await prisma.dataset.deleteMany();
- await prisma.datasetRuns.deleteMany();
- await prisma.prompt.deleteMany();
- await prisma.model.deleteMany();
- await prisma.jobExecution.deleteMany();
- await prisma.jobConfiguration.deleteMany();
- await prisma.evalTemplate.deleteMany();
- await prisma.llmApiKeys.deleteMany();
- await prisma.price.deleteMany();
-};
diff --git a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
index 5b477fb2c5..9142f94239 100644
--- a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
+++ b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
@@ -14,9 +14,9 @@ import {
TraceEventType,
traceRecordReadSchema,
TraceRecordReadType,
+ createOrgProjectAndApiKey,
createIngestionEventSchema,
} from "@langfuse/shared/src/server";
-import { pruneDatabase } from "../../../__tests__/utils";
import waitForExpect from "wait-for-expect";
import { ClickhouseWriter, TableName } from "../../ClickhouseWriter";
import { IngestionService } from "../../IngestionService";
@@ -24,7 +24,7 @@ import { ModelUsageUnit, ScoreSourceEnum } from "@langfuse/shared";
import { Cluster } from "ioredis";
import { env } from "../../../env";
-const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+let projectId = "";
const environment = "default";
describe("Ingestion end-to-end tests", () => {
@@ -34,7 +34,7 @@ describe("Ingestion end-to-end tests", () => {
beforeEach(async () => {
if (!redis) throw new Error("Redis not initialized");
- await pruneDatabase();
+ ({ projectId } = await createOrgProjectAndApiKey());
if (redis instanceof Cluster) {
await Promise.all(redis.nodes("master").map((node) => node.flushall()));
@@ -570,7 +570,7 @@ describe("Ingestion end-to-end tests", () => {
expect(trace.name).toBe("trace-name");
expect(trace.release).toBe("1.0.0");
expect(trace.version).toBe("2.0.0");
- expect(trace.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(trace.project_id).toBe(projectId);
expect(trace.tags).toEqual(["tag-1", "tag-2"]);
const generation = await getClickhouseRecord(
@@ -620,7 +620,7 @@ describe("Ingestion end-to-end tests", () => {
expect(score.value).toBe(100.5);
expect(score.observation_id).toBeNull();
expect(score.source).toBe(ScoreSourceEnum.EVAL);
- expect(score.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(score.project_id).toBe(projectId);
}, 10_000);
});
@@ -778,7 +778,7 @@ describe("Ingestion end-to-end tests", () => {
],
},
{
- observationExternalModel: "GPT-4",
+ observationExternalModel: "lf-unmatched-model-for-token-test",
observationStartTime: new Date("2021-01-01T00:00:00.000Z"),
modelUnit: ModelUsageUnit.Tokens,
expectedInternalModelId: null,
@@ -819,12 +819,22 @@ describe("Ingestion end-to-end tests", () => {
)}`, async () => {
const traceId = randomUUID();
const generationId = randomUUID();
+ const modelIdMap = new Map<string, string>();
+
+ const getModelId = (id: string) => {
+ const existing = modelIdMap.get(id);
+ if (existing) return existing;
+ const generatedId = randomUUID();
+ modelIdMap.set(id, generatedId);
+ return generatedId;
+ };
await Promise.all(
testConfig.models.map(async (model) =>
prisma.model.create({
data: {
- id: model.id,
+ id: getModelId(model.id),
+ projectId,
modelName: model.modelName,
matchPattern: model.matchPattern,
startDate: model.startDate,
@@ -914,9 +924,11 @@ describe("Ingestion end-to-end tests", () => {
expect(generation.usage_details.output).toBe(
testConfig.expectedUsageDetails.output,
);
- expect(generation.internal_model_id).toBe(
- testConfig.expectedInternalModelId,
- );
+ const expectedModelId =
+ testConfig.expectedInternalModelId === null
+ ? null
+ : getModelId(testConfig.expectedInternalModelId);
+ expect(generation.internal_model_id).toBe(expectedModelId);
});
});
@@ -1077,7 +1089,7 @@ describe("Ingestion end-to-end tests", () => {
const trace = await getClickhouseRecord(TableName.Traces, traceId);
- expect(trace.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(trace.project_id).toBe(projectId);
const span = await getClickhouseRecord(TableName.Observations, spanId);
@@ -1344,7 +1356,7 @@ describe("Ingestion end-to-end tests", () => {
expect(trace.user_id).toBe("user-2");
expect(trace.release).toBe("1.0.0");
expect(trace.version).toBe("2.0.0");
- expect(trace.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(trace.project_id).toBe(projectId);
expect(trace.tags.sort()).toEqual(
["tag-1", "tag-2", "tag-3", "tag-4"].sort(),
);
@@ -1400,16 +1412,21 @@ describe("Ingestion end-to-end tests", () => {
expect(trace.name).toBe("trace-name");
expect(trace.user_id).toBe("user-1");
- expect(trace.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(trace.project_id).toBe(projectId);
}, 10_000);
it("should merge observations and set negative tokens and cost to null", async () => {
- const modelId = "clyrjpbe20000t0mzcbwc42rg";
- const pricingTierId = "f94390ea-8d08-4bbb-b106-519f3eaf81bb";
+ const modelId = randomUUID();
+ const pricingTierId = randomUUID();
+ const inputPriceId = randomUUID();
+ const outputPriceId = randomUUID();
+ const observationId = randomUUID();
+ const traceId = randomUUID();
await prisma.model.create({
data: {
id: modelId,
+ projectId,
modelName: "gpt-4o-mini-2024-07-18",
matchPattern: "(?i)^(gpt-4o-mini-2024-07-18)$",
startDate: new Date("2021-01-01T00:00:00.000Z"),
@@ -1438,9 +1455,9 @@ describe("Ingestion end-to-end tests", () => {
await prisma.price.create({
data: {
- id: "cm2uio8ef006mh6qlzc2mqa0e",
+ id: inputPriceId,
pricingTierId,
- modelId: "clyrjpbe20000t0mzcbwc42rg",
+ modelId,
projectId: null,
price: 0.00000015,
usageType: "input",
@@ -1449,23 +1466,22 @@ describe("Ingestion end-to-end tests", () => {
await prisma.price.create({
data: {
- id: "cm2uio8ef006oh6qlldn36376",
+ id: outputPriceId,
pricingTierId,
- modelId: "clyrjpbe20000t0mzcbwc42rg",
+ modelId,
projectId: null,
price: 0.0000006,
usageType: "output",
},
});
- const observationId = "c8d30f61-4097-407f-a337-5fb1e0c100f2";
const observationEventList: ObservationEvent[] = [
{
- id: "084274e5-f15e-4f66-8419-a171808d8180",
+ id: randomUUID(),
timestamp: "2024-11-04T16:13:51.496457Z",
type: "generation-create",
body: {
- traceId: "82c480bc-1c4e-4ba8-a153-0bd9f9e1a28e",
+ traceId,
name: "extract_location",
startTime: "2024-11-04T16:13:51.495868Z",
metadata: {
@@ -1476,7 +1492,7 @@ describe("Ingestion end-to-end tests", () => {
ls_max_tokens: 1000,
},
input: "Sample input",
- id: "c8d30f61-4097-407f-a337-5fb1e0c100f2",
+ id: observationId,
model: "gpt-4o-mini-2024-07-18",
modelParameters: {
temperature: "0.4",
@@ -1487,13 +1503,13 @@ describe("Ingestion end-to-end tests", () => {
},
},
{
- id: "ef654262-b1d0-4b0b-9e4a-2a410e0577a6",
+ id: randomUUID(),
timestamp: "2024-11-04T16:13:52.156691Z",
type: "generation-update",
body: {
- traceId: "82c480bc-1c4e-4ba8-a153-0bd9f9e1a28e",
+ traceId,
output: "Sample output",
- id: "c8d30f61-4097-407f-a337-5fb1e0c100f2",
+ id: observationId,
endTime: "2024-11-04T16:13:52.156248Z",
model: "gpt-4o-mini-2024-07-18",
usage: {
@@ -1538,12 +1554,17 @@ describe("Ingestion end-to-end tests", () => {
});
it("should merge observations and calculate cost", async () => {
- const modelId = "clyrjpbe20000t0mzcbwc42rg";
- const pricingTierId = "f94390ea-8d08-4bbb-b106-519f3eaf81bb";
+ const modelId = randomUUID();
+ const pricingTierId = randomUUID();
+ const inputPriceId = randomUUID();
+ const outputPriceId = randomUUID();
+ const observationId = randomUUID();
+ const traceId = randomUUID();
await prisma.model.create({
data: {
- id: "clyrjpbe20000t0mzcbwc42rg",
+ id: modelId,
+ projectId,
modelName: "gpt-4o-mini-2024-07-18",
matchPattern: "(?i)^(gpt-4o-mini-2024-07-18)$",
startDate: new Date("2021-01-01T00:00:00.000Z"),
@@ -1572,9 +1593,9 @@ describe("Ingestion end-to-end tests", () => {
await prisma.price.create({
data: {
- id: "cm2uio8ef006mh6qlzc2mqa0e",
+ id: inputPriceId,
pricingTierId,
- modelId: "clyrjpbe20000t0mzcbwc42rg",
+ modelId,
projectId: null,
price: 0.00000015,
usageType: "input",
@@ -1583,23 +1604,22 @@ describe("Ingestion end-to-end tests", () => {
await prisma.price.create({
data: {
- id: "cm2uio8ef006oh6qlldn36376",
+ id: outputPriceId,
pricingTierId,
- modelId: "clyrjpbe20000t0mzcbwc42rg",
+ modelId,
projectId: null,
price: 0.0000006,
usageType: "output",
},
});
- const observationId = "c8d30f61-4097-407f-a337-5fb1e0c100f2";
const observationEventList: ObservationEvent[] = [
{
- id: "084274e5-f15e-4f66-8419-a171808d8180",
+ id: randomUUID(),
timestamp: "2024-11-04T16:13:51.496457Z",
type: "generation-create",
body: {
- traceId: "82c480bc-1c4e-4ba8-a153-0bd9f9e1a28e",
+ traceId,
name: "extract_location",
startTime: "2024-11-04T16:13:51.495868Z",
metadata: {
@@ -1610,7 +1630,7 @@ describe("Ingestion end-to-end tests", () => {
ls_max_tokens: 1000,
},
input: "Sample input",
- id: "c8d30f61-4097-407f-a337-5fb1e0c100f2",
+ id: observationId,
model: "gpt-4o-mini-2024-07-18",
modelParameters: {
temperature: "0.4",
@@ -1621,13 +1641,13 @@ describe("Ingestion end-to-end tests", () => {
},
},
{
- id: "ef654262-b1d0-4b0b-9e4a-2a410e0577a6",
+ id: randomUUID(),
timestamp: "2024-11-04T16:13:52.156691Z",
type: "generation-update",
body: {
- traceId: "82c480bc-1c4e-4ba8-a153-0bd9f9e1a28e",
+ traceId,
output: "Sample output",
- id: "c8d30f61-4097-407f-a337-5fb1e0c100f2",
+ id: observationId,
endTime: "2024-11-04T16:13:52.156248Z",
model: "gpt-4o-mini-2024-07-18",
usage: {
@@ -1920,6 +1940,7 @@ describe("Ingestion end-to-end tests", () => {
await prisma.model.create({
data: {
+ projectId,
modelName: "gpt-3.5",
matchPattern: "(?i)^(gpt-)(35|3.5)(-turbo)?$",
startDate: new Date("2021-01-01T00:00:00.000Z"),
@@ -1997,7 +2018,7 @@ describe("Ingestion end-to-end tests", () => {
const trace = await getClickhouseRecord(TableName.Traces, traceId);
expect(trace.name).toBe("trace-name");
- expect(trace.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
+ expect(trace.project_id).toBe(projectId);
expect(trace.user_id).toBe("user-1");
const generation = await getClickhouseRecord(
@@ -2025,6 +2046,7 @@ describe("Ingestion end-to-end tests", () => {
await prisma.model.create({
data: {
+ projectId,
modelName: "gpt-3.5",
matchPattern: "(?i)^(gpt-)(35|3.5)(-turbo)?$",
startDate: new Date("2021-01-01T00:00:00.000Z"),
@@ -2307,14 +2329,16 @@ describe("Ingestion end-to-end tests", () => {
it("should apply default tier for usage below threshold (Anthropic Claude example)", async () => {
const traceId = randomUUID();
const generationId = randomUUID();
- const modelId = "claude-sonnet-test";
+ const modelId = randomUUID();
+ const modelName = `claude-sonnet-4.5-${randomUUID()}`;
// Create model with tiered pricing (Anthropic Claude pattern: $3/M tokens default, $6/M tokens >200K)
await prisma.model.create({
data: {
id: modelId,
- modelName: "claude-sonnet-4.5",
- matchPattern: "(?i)^(claude-sonnet-4.5)$",
+ projectId,
+ modelName,
+ matchPattern: `(?i)^(${modelName})$`,
startDate: new Date("2021-01-01T00:00:00.000Z"),
unit: ModelUsageUnit.Tokens,
pricingTiers: {
@@ -2382,7 +2406,7 @@ describe("Ingestion end-to-end tests", () => {
type: "GENERATION",
name: "generation-name",
startTime: new Date().toISOString(),
- model: "claude-sonnet-4.5",
+ model: modelName,
usage: {
input: 100000, // Below 200K threshold
output: 2000,
@@ -2445,14 +2469,16 @@ describe("Ingestion end-to-end tests", () => {
it("should apply large context tier for usage above threshold (Anthropic Claude example)", async () => {
const traceId = randomUUID();
const generationId = randomUUID();
- const modelId = "claude-sonnet-test-2";
+ const modelId = randomUUID();
+ const modelName = `claude-sonnet-4.5-test-${randomUUID()}`;
// Create model with tiered pricing
await prisma.model.create({
data: {
id: modelId,
- modelName: "claude-sonnet-4.5-test",
- matchPattern: "(?i)^(claude-sonnet-4.5-test)$",
+ projectId,
+ modelName,
+ matchPattern: `(?i)^(${modelName})$`,
startDate: new Date("2021-01-01T00:00:00.000Z"),
unit: ModelUsageUnit.Tokens,
pricingTiers: {
@@ -2520,7 +2546,7 @@ describe("Ingestion end-to-end tests", () => {
type: "GENERATION",
name: "generation-name",
startTime: new Date().toISOString(),
- model: "claude-sonnet-4.5-test",
+ model: modelName,
usage: {
input: 250000, // Above 200K threshold
output: 2000,
@@ -2583,14 +2609,16 @@ describe("Ingestion end-to-end tests", () => {
it("should match pattern with granular usage details (input_cached + input_regular)", async () => {
const traceId = randomUUID();
const generationId = randomUUID();
- const modelId = "claude-test-granular";
+ const modelId = randomUUID();
+ const modelName = `claude-test-granular-${randomUUID()}`;
// Create model with tiered pricing that sums all input* fields
await prisma.model.create({
data: {
id: modelId,
- modelName: "claude-test-granular",
- matchPattern: "(?i)^(claude-test-granular)$",
+ projectId,
+ modelName,
+ matchPattern: `(?i)^(${modelName})$`,
startDate: new Date("2021-01-01T00:00:00.000Z"),
unit: ModelUsageUnit.Tokens,
pricingTiers: {
@@ -2648,7 +2676,7 @@ describe("Ingestion end-to-end tests", () => {
type: "GENERATION",
name: "generation-name",
startTime: new Date().toISOString(),
- model: "claude-test-granular",
+ model: modelName,
usageDetails: {
input_cached: 150000,
input_regular: 60000, // Total: 210K > 200K
@@ -2702,13 +2730,15 @@ describe("Ingestion end-to-end tests", () => {
it("should handle exactly at threshold boundary (200K tokens)", async () => {
const traceId = randomUUID();
const generationId = randomUUID();
- const modelId = "claude-boundary-test";
+ const modelId = randomUUID();
+ const modelName = `claude-boundary-${randomUUID()}`;
await prisma.model.create({
data: {
id: modelId,
- modelName: "claude-boundary",
- matchPattern: "(?i)^(claude-boundary)$",
+ projectId,
+ modelName,
+ matchPattern: `(?i)^(${modelName})$`,
startDate: new Date("2021-01-01T00:00:00.000Z"),
unit: ModelUsageUnit.Tokens,
pricingTiers: {
@@ -2766,7 +2796,7 @@ describe("Ingestion end-to-end tests", () => {
type: "GENERATION",
name: "generation-name",
startTime: new Date().toISOString(),
- model: "claude-boundary",
+ model: modelName,
usage: {
input: 200000, // Exactly at threshold
output: 100,
diff --git a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts
index ececb64b4d..86550780d7 100644
--- a/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts
+++ b/worker/src/services/IngestionService/tests/calculateTokenCost.unit.test.ts
@@ -4,8 +4,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { Price } from "@langfuse/shared";
import { prisma } from "@langfuse/shared/src/db";
+import { createOrgProjectAndApiKey } from "@langfuse/shared/src/server";
-import { pruneDatabase } from "../../../__tests__/utils";
import { IngestionService } from "../../IngestionService";
import * as clickhouseWriteExports from "../../ClickhouseWriter";
@@ -38,23 +38,20 @@ const mockIngestionService = new IngestionService(
);
describe("Token Cost Calculation", () => {
- const modelName = "gpt-test-" + uuidv4();
- const matchPattern = `(?i)^(${modelName})$`;
- const traceId = uuidv4();
- const generationId = uuidv4();
- const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
-
- const modelId = uuidv4();
- const tokenModelData = {
- id: modelId,
- modelName,
- matchPattern,
- tokenizerId: "openai",
+ let modelName: string;
+ let modelId: string;
+ let generationId: string;
+ let projectId: string;
+ let tokenModelData: {
+ id: string;
+ modelName: string;
+ matchPattern: string;
+ tokenizerId: string;
tokenizerConfig: {
- tokensPerName: 1,
- tokenizerModel: "gpt-4o",
- tokensPerMessage: 3,
- },
+ tokensPerName: number;
+ tokenizerModel: string;
+ tokensPerMessage: number;
+ };
};
const modelPrices: Pick<Price, "price" | "usageType">[] = [
@@ -73,7 +70,23 @@ describe("Token Cost Calculation", () => {
];
beforeEach(async () => {
- await pruneDatabase();
+ modelName = `gpt-test-${uuidv4()}`;
+ modelId = uuidv4();
+ generationId = uuidv4();
+ ({ projectId } = await createOrgProjectAndApiKey());
+ const matchPattern = `(?i)^(${modelName})$`;
+ tokenModelData = {
+ id: modelId,
+ modelName,
+ matchPattern,
+ tokenizerId: "openai",
+ tokenizerConfig: {
+ tokensPerName: 1,
+ tokenizerModel: "gpt-4o",
+ tokensPerMessage: 3,
+ },
+ };
+
const model = await prisma.model.create({
data: tokenModelData,
});