🪢 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
fix: fix order of matched models (#1175)
Max Deichmanndf802184a6da
diff --git a/prisma/migrations/20240215155710_update_observation_view_latency/migration.sql b/prisma/migrations/20240215234937_fix_observations_view/migration.sqlsimilarity index 90%rename from prisma/migrations/20240215155710_update_observation_view_latency/migration.sqlrename to prisma/migrations/20240215234937_fix_observations_view/migration.sqlindex 9389f7b19d..eaba8de862 100644--- a/prisma/migrations/20240215155710_update_observation_view_latency/migration.sql+++ b/prisma/migrations/20240215234937_fix_observations_view/migration.sql@@ -1,4 +1,3 @@--- This is an empty migration.CREATE OR REPLACE VIEW "observations_view" ASSELECTo.*,@@ -45,7 +44,7 @@ LEFT JOIN models m ON m.id = (AND (start_date < o.start_time OR start_date is NULL)AND o.unit::TEXT = unitORDER BY- project_id ASC, -- in postgres, NULLs are sorted first- start_date DESC+ project_id ASC, -- in postgres, NULLs are sorted last when ordering ASC+ start_date DESC NULLS LAST -- now, NULLs are sorted last when ordering DESC as wellLIMIT 1)diff --git a/src/__tests__/cost.servertest.ts b/src/__tests__/cost.servertest.tsindex 78e496c6d9..e9181988b4 100644--- a/src/__tests__/cost.servertest.ts+++ b/src/__tests__/cost.servertest.ts@@ -239,8 +239,23 @@ describe("cost retrieval tests", () => {);});});+it(`should prioritize latest models`, async () => {await pruneDatabase();+ await prisma.model.create({+ data: {+ id: "model-0",+ modelName: "gpt-3.5-turbo",+ inputPrice: "0.0000000",+ outputPrice: "0.0000000",+ totalPrice: "0.1",+ matchPattern: "(.*)(gpt-)(35|3.5)(-turbo)?(.*)",+ projectId: null,+ startDate: null,+ tokenizerConfig: { tokensPerMessage: 3, tokensPerName: 1 },+ unit: ModelUsageUnit.Tokens,+ },+ });await prisma.model.create({data: {@@ -305,6 +320,70 @@ describe("cost retrieval tests", () => {expect(view?.calculatedTotalCost?.toString()).toBe("0.0124");});+ it(`should prioritize own models`, async () => {+ await pruneDatabase();+ await prisma.model.create({+ data: {+ id: "model-0",+ modelName: "gpt-3.5-turbo",+ inputPrice: "0.0000000",+ outputPrice: "0.0000000",+ totalPrice: "0.1",+ matchPattern: "(.*)(gpt-)(35|3.5)(-turbo)?(.*)",+ projectId: null,+ startDate: null,+ tokenizerConfig: { tokensPerMessage: 3, tokensPerName: 1 },+ unit: ModelUsageUnit.Tokens,+ },+ });++ await prisma.model.create({+ data: {+ id: "model-1",+ modelName: "gpt-3.5-turbo",+ inputPrice: "0.0000010",+ outputPrice: "0.0000020",+ totalPrice: "0.1",+ matchPattern: "(.*)(gpt-)(35|3.5)(-turbo)?(.*)",+ startDate: null,+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ tokenizerConfig: { tokensPerMessage: 3, tokensPerName: 1 },+ unit: ModelUsageUnit.Tokens,+ },+ });++ const dbTrace = await prisma.trace.create({+ data: {+ name: "trace-name",+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ },+ });++ await prisma.observation.create({+ data: {+ traceId: dbTrace.id,+ type: "GENERATION",+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ model: "gpt-3.5-turbo",+ internalModel: "gpt-3.5-turbo",+ startTime: new Date("2024-01-01T00:00:00.000Z"),+ unit: ModelUsageUnit.Tokens,+ promptTokens: 200,+ completionTokens: 3000,+ totalTokens: undefined,+ },+ });++ const view = await prisma.observationView.findFirst({+ where: { traceId: dbTrace.id },+ });++ console.log(view);++ // calculated cost fields+ expect(view?.modelId).toBe("model-1");+ });+it(`should prioritize old model if the latest model is not own one`, async () => {await pruneDatabase();@@ -371,6 +450,72 @@ describe("cost retrieval tests", () => {expect(view?.calculatedTotalCost?.toString()).toBe("0.0124");});+ it(`should prioritize new model if the latest model is own one`, async () => {+ await pruneDatabase();++ await prisma.model.create({+ data: {+ id: "model-1",+ modelName: "gpt-3.5-turbo",+ inputPrice: "0.0010",+ outputPrice: "0.0020",+ totalPrice: "0.1",+ matchPattern: "(.*)(gpt-)(35|3.5)(-turbo)?(.*)",+ startDate: null,+ tokenizerConfig: { tokensPerMessage: 3, tokensPerName: 1 },+ unit: ModelUsageUnit.Tokens,+ },+ });+ await prisma.model.create({+ data: {+ id: "model-2",+ modelName: "gpt-3.5-turbo",+ inputPrice: "0.0000020",+ outputPrice: "0.0000040",+ totalPrice: undefined,+ matchPattern: "(.*)(gpt-)(35|3.5)(-turbo)?(.*)",+ startDate: new Date("2023-12-01"),+ tokenizerConfig: { tokensPerMessage: 3, tokensPerName: 1 },+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ unit: ModelUsageUnit.Tokens,+ },+ });++ const dbTrace = await prisma.trace.create({+ data: {+ name: "trace-name",+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ },+ });++ await prisma.observation.create({+ data: {+ traceId: dbTrace.id,+ type: "GENERATION",+ project: { connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" } },+ model: "gpt-3.5-turbo",+ internalModel: "gpt-3.5-turbo",+ startTime: new Date("2024-01-01T00:00:00.000Z"),+ unit: ModelUsageUnit.Tokens,+ promptTokens: 200,+ completionTokens: 3000,+ totalTokens: undefined,+ },+ });++ const view = await prisma.observationView.findFirst({+ where: { traceId: dbTrace.id },+ });++ console.log(view);++ // calculated cost fields+ expect(view?.modelId).toBe("model-2");+ expect(view?.calculatedInputCost?.toString()).toBe("0.0004");+ expect(view?.calculatedOutputCost?.toString()).toBe("0.012");+ expect(view?.calculatedTotalCost?.toString()).toBe("0.0124");+ });+it(`should prioritize user provided cost`, async () => {await pruneDatabase();diff --git a/src/__tests__/features/orderBy/hooks/useOrderByState.clienttest.tsx b/src/features/orderBy/hooks/useOrderByState.clienttest.tsxsimilarity index 100%rename from src/__tests__/features/orderBy/hooks/useOrderByState.clienttest.tsxrename to src/features/orderBy/hooks/useOrderByState.clienttest.tsxdiff --git a/src/__tests__/features/orderBy/server/orderByToPrisma.clienttest.ts b/src/features/orderBy/server/orderByToPrisma.clienttest.tssimilarity index 100%rename from src/__tests__/features/orderBy/server/orderByToPrisma.clienttest.tsrename to src/features/orderBy/server/orderByToPrisma.clienttest.ts