🪢 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: adds filter by score IDs to list scores endpoint
Hassieb Pakzad0d1f94862532
diff --git a/fern/apis/server/definition/score.yml b/fern/apis/server/definition/score.ymlindex af21bca4f1..a1d06fb4c8 100644--- a/fern/apis/server/definition/score.yml+++ b/fern/apis/server/definition/score.yml@@ -39,6 +39,9 @@ service:value:type: optional<double>docs: Retrieve only scores with <operator> value.+ scoreIds:+ type: optional<list<string>>+ docs: Comma-separated list of score IDs to limit the results to.response: Scoresget-by-id:docs: Get a scorediff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex 3bb4af2ba7..5461d9d4d2 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -1015,6 +1015,13 @@ paths:type: numberformat: doublenullable: true+ - name: scoreIds+ in: query+ description: Comma-separated list of score IDs to limit the results to.+ required: false+ schema:+ type: string+ nullable: trueresponses:'200':description: ''diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.jsonindex 6eab49abd6..1458598fec 100644--- a/web/public/generated/postman/collection.json+++ b/web/public/generated/postman/collection.json@@ -755,7 +755,7 @@"request": {"description": "Get a list of scores","url": {- "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=&fromTimestamp=&source=&operator=&value=",+ "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=&fromTimestamp=&source=&operator=&value=&scoreIds=","host": ["{{baseUrl}}"],@@ -804,6 +804,11 @@"key": "value","value": "","description": "Retrieve only scores with <operator> value."+ },+ {+ "key": "scoreIds",+ "value": "",+ "description": "Retrieve only scores with the given ids."}],"variable": []diff --git a/web/src/__tests__/scores.servertest.ts b/web/src/__tests__/scores.servertest.tsindex 9042030c20..d07d398fef 100644--- a/web/src/__tests__/scores.servertest.ts+++ b/web/src/__tests__/scores.servertest.ts@@ -591,5 +591,37 @@ describe("/api/public/scores API Endpoint", () => {message: "Invalid request data",});});++ it("should filter scores by score IDs", async () => {+ const getScore = await makeAPICall<{+ data: [+ {+ id: string;+ name: string;+ value: number;+ },+ ];+ meta: object;+ }>("GET", `/api/public/scores?scoreIds=${scoreId_1},${scoreId_2}`);+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 2,+ totalPages: 1,+ });+ expect(getScore.body.data).toMatchObject([+ {+ id: scoreId_2,+ name: scoreName,+ value: 50.5,+ },+ {+ id: scoreId_1,+ name: scoreName,+ value: 10.5,+ },+ ]);+ });});});diff --git a/web/src/pages/api/public/scores.ts b/web/src/pages/api/public/scores.tsindex f475c049c3..903cea921d 100644--- a/web/src/pages/api/public/scores.ts+++ b/web/src/pages/api/public/scores.ts@@ -20,15 +20,24 @@ import { isPrismaException } from "@/src/utils/exceptions";const operators = ["<", ">", "<=", ">=", "!=", "="] as const;-const ScoresGetSchema = z.object({- ...paginationZod,- userId: z.string().nullish(),- name: z.string().nullish(),- fromTimestamp: stringDate,- source: z.nativeEnum(ScoreSource).nullish(),- value: z.coerce.number().nullish(),- operator: z.enum(operators).nullish(),-});+const ScoresGetSchema = z+ .object({+ ...paginationZod,+ userId: z.string().nullish(),+ name: z.string().nullish(),+ fromTimestamp: stringDate,+ source: z.nativeEnum(ScoreSource).nullish(),+ value: z.coerce.number().nullish(),+ operator: z.enum(operators).nullish(),+ scoreIds: z+ .string()+ .transform((str) => str.split(",").map((id) => id.trim())) // Split the comma-separated string+ .refine((arr) => arr.every((id) => typeof id === "string"), {+ message: "Each score ID must be a string",+ })+ .nullish(),+ })+ .strict(); // Use strict to give 400s on typo'd query paramsexport default async function handler(req: NextApiRequest,@@ -117,6 +126,9 @@ export default async function handler(obj.operator && obj.value !== null && obj.value !== undefined? Prisma.sql`AND s."value" ${Prisma.raw(`${obj.operator}`)} ${obj.value}`: Prisma.empty;+ const scoreIdCondition = obj.scoreIds+ ? Prisma.sql`AND s."id" = ANY(${obj.scoreIds})`+ : Prisma.empty;const scores = await prisma.$queryRaw<Array<Score & { trace: { userId: string } }>@@ -139,7 +151,8 @@ export default async function handler(${sourceCondition}${fromTimestampCondition}${valueCondition}- ORDER BY t."timestamp" DESC+ ${scoreIdCondition}+ ORDER BY s."timestamp" DESCLIMIT ${obj.limit} OFFSET ${skipValue}`);@@ -154,6 +167,7 @@ export default async function handler(${sourceCondition}${fromTimestampCondition}${valueCondition}+ ${scoreIdCondition}`,);