Skip to content

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

feat(api): add queueId query param to GET /scores (#3771)

marliessophiec258776a68a9
diff --git a/fern/apis/server/definition/commons.yml b/fern/apis/server/definition/commons.yml
index 366d8712e3..44f0c5d40c 100644
--- a/fern/apis/server/definition/commons.yml
+++ b/fern/apis/server/definition/commons.yml
@@ -240,6 +240,9 @@ types:
configId:
type: optional<string>
docs: Reference a score config on a score. When set, config and score name must be equal and value must comply to optionally defined numerical range
+ queueId:
+ type: optional<string>
+ docs: Reference an annotation queue on a score. Populated if the score was initially created in an annotation queue.
NumericScore:
extends: BaseScore
properties:
diff --git a/fern/apis/server/definition/score.yml b/fern/apis/server/definition/score.yml
index 9d0e7106f2..d2edf7cbdc 100644
--- a/fern/apis/server/definition/score.yml
+++ b/fern/apis/server/definition/score.yml
@@ -52,6 +52,9 @@ service:
configId:
type: optional<string>
docs: Retrieve only scores with a specific configId.
+ queueId:
+ type: optional<string>
+ docs: Retrieve only scores with a specific annotation queueId.
dataType:
type: optional<commons.ScoreDataType>
docs: Retrieve only scores with a specific dataType.
diff --git a/packages/shared/src/features/scores/scoreTypes.ts b/packages/shared/src/features/scores/scoreTypes.ts
index 65cd499660..d1c9946174 100644
--- a/packages/shared/src/features/scores/scoreTypes.ts
+++ b/packages/shared/src/features/scores/scoreTypes.ts
@@ -55,6 +55,7 @@ const ScoreBase = z.object({
configId: z.string().nullish(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
+ queueId: z.string().nullish(),
});
const BaseScoreBody = z.object({
@@ -83,13 +84,13 @@ export const ScoreBodyWithoutConfig = z.discriminatedUnion("dataType", [
z.object({
value: z.number(),
dataType: z.literal("NUMERIC"),
- }),
+ })
),
BaseScoreBody.merge(
z.object({
value: z.string(),
dataType: z.literal("CATEGORICAL"),
- }),
+ })
),
BaseScoreBody.merge(
z.object({
@@ -97,7 +98,7 @@ export const ScoreBodyWithoutConfig = z.discriminatedUnion("dataType", [
message: "Value must be either 0 or 1",
}),
dataType: z.literal("BOOLEAN"),
- }),
+ })
),
]);
@@ -161,7 +162,7 @@ export const ScorePropsAgainstConfig = z.union([
*/
export const filterAndValidateDbScoreList = (
scores: Score[],
- onParseError?: (error: z.ZodError) => void,
+ onParseError?: (error: z.ZodError) => void
): APIScore[] =>
scores.reduce((acc, ts) => {
const result = APIScoreSchema.safeParse(ts);
@@ -198,14 +199,14 @@ export const PostScoresBody = z.discriminatedUnion("dataType", [
value: z.number(),
dataType: z.literal("NUMERIC"),
configId: z.string().nullish(),
- }),
+ })
),
BaseScoreBody.merge(
z.object({
value: z.string(),
dataType: z.literal("CATEGORICAL"),
configId: z.string().nullish(),
- }),
+ })
),
BaseScoreBody.merge(
z.object({
@@ -215,14 +216,14 @@ export const PostScoresBody = z.discriminatedUnion("dataType", [
}),
dataType: z.literal("BOOLEAN"),
configId: z.string().nullish(),
- }),
+ })
),
BaseScoreBody.merge(
z.object({
value: z.union([z.string(), z.number()]),
dataType: z.undefined(),
configId: z.string().nullish(),
- }),
+ })
),
]);
@@ -234,6 +235,7 @@ export const GetScoresQuery = z.object({
userId: z.string().nullish(),
dataType: z.enum(ScoreDataType).nullish(),
configId: z.string().nullish(),
+ queueId: z.string().nullish(),
name: z.string().nullish(),
fromTimestamp: stringDateTime,
toTimestamp: stringDateTime,
@@ -256,7 +258,7 @@ const LegacyGetScoreResponseDataV1 = z.intersection(
trace: z.object({
userId: z.string().nullish(),
}),
- }),
+ })
);
export const GetScoresResponse = z.object({
data: z.array(LegacyGetScoreResponseDataV1),
@@ -265,7 +267,7 @@ export const GetScoresResponse = z.object({
export const legacyFilterAndValidateV1GetScoreList = (
scores: unknown[],
- onParseError?: (error: z.ZodError) => void,
+ onParseError?: (error: z.ZodError) => void
): z.infer<typeof LegacyGetScoreResponseDataV1>[] =>
scores.reduce(
(acc: z.infer<typeof LegacyGetScoreResponseDataV1>[], ts) => {
@@ -278,7 +280,7 @@ export const legacyFilterAndValidateV1GetScoreList = (
}
return acc;
},
- [] as z.infer<typeof LegacyGetScoreResponseDataV1>[],
+ [] as z.infer<typeof LegacyGetScoreResponseDataV1>[]
);
// GET /scores/{scoreId}
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index 37540f64d1..0c1a63cc87 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -1597,6 +1597,13 @@ paths:
schema:
type: string
nullable: true
+ - name: queueId
+ in: query
+ description: Retrieve only scores with a specific annotation queueId.
+ required: false
+ schema:
+ type: string
+ nullable: true
- name: dataType
in: query
description: Retrieve only scores with a specific dataType.
@@ -2453,6 +2460,12 @@ components:
Reference a score config on a score. When set, config and score name
must be equal and value must comply to optionally defined numerical
range
+ queueId:
+ type: string
+ nullable: true
+ description: >-
+ Reference an annotation queue on a score. Populated if the score was
+ initially created in an annotation queue.
required:
- id
- traceId
diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.json
index 7b3c9289ce..349a180713 100644
--- a/web/public/generated/postman/collection.json
+++ b/web/public/generated/postman/collection.json
@@ -1121,7 +1121,7 @@
"request": {
"description": "Get a list of scores",
"url": {
- "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&source=&operator=&value=&scoreIds=&configId=&dataType=",
+ "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&source=&operator=&value=&scoreIds=&configId=&queueId=&dataType=",
"host": [
"{{baseUrl}}"
],
@@ -1186,6 +1186,11 @@
"value": "",
"description": "Retrieve only scores with a specific configId."
},
+ {
+ "key": "queueId",
+ "value": "",
+ "description": "Retrieve only scores with a specific annotation queueId."
+ },
{
"key": "dataType",
"value": "",
diff --git a/web/src/__tests__/scores.servertest.ts b/web/src/__tests__/scores.servertest.ts
index 7a15561b52..6ebdc8c7c2 100644
--- a/web/src/__tests__/scores.servertest.ts
+++ b/web/src/__tests__/scores.servertest.ts
@@ -1022,6 +1022,76 @@ describe("/api/public/scores API Endpoint", () => {
}
});
+ describe("should Filter scores by queueId", () => {
+ describe("queueId filtering", () => {
+ let queueId: string;
+ const projectId = "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a";
+
+ beforeEach(async () => {
+ queueId = uuidv4();
+
+ await Promise.all([
+ prisma.score.create({
+ data: {
+ observationId: generationId,
+ name: "annotation-score-1",
+ value: 100.5,
+ traceId: traceId,
+ comment: "comment 1",
+ queueId,
+ source: "ANNOTATION",
+ project: { connect: { id: projectId } },
+ dataType: "NUMERIC",
+ },
+ }),
+ prisma.score.create({
+ data: {
+ observationId: generationId,
+ name: "annotation-score-2",
+ value: 75.0,
+ traceId: traceId,
+ comment: "comment 2",
+ queueId,
+ source: "ANNOTATION",
+ project: { connect: { id: projectId } },
+ dataType: "NUMERIC",
+ },
+ }),
+ ]);
+ });
+
+ afterEach(async () => {
+ await prisma.score.deleteMany({
+ where: { queueId, projectId },
+ });
+ });
+
+ it("get all scores for queueId", async () => {
+ const getAllScore = await makeZodVerifiedAPICall(
+ GetScoresResponse,
+ "GET",
+ `/api/public/scores?queueId=${queueId}`,
+ );
+
+ expect(getAllScore.status).toBe(200);
+ expect(getAllScore.body.meta).toMatchObject({
+ page: 1,
+ limit: 50,
+ totalItems: 2,
+ totalPages: 1,
+ });
+ for (const val of getAllScore.body.data) {
+ expect(val).toMatchObject({
+ traceId: traceId,
+ observationId: generationId,
+ queueId: queueId,
+ source: "ANNOTATION",
+ });
+ }
+ });
+ });
+ });
+
it("test only operator", async () => {
const getScore = await makeZodVerifiedAPICall(
GetScoresResponse,
diff --git a/web/src/pages/api/public/scores/index.ts b/web/src/pages/api/public/scores/index.ts
index 149b605c07..6c1271fd21 100644
--- a/web/src/pages/api/public/scores/index.ts
+++ b/web/src/pages/api/public/scores/index.ts
@@ -52,6 +52,7 @@ export default withMiddlewares({
page,
limit,
configId,
+ queueId,
userId,
name,
fromTimestamp,
@@ -67,6 +68,9 @@ export default withMiddlewares({
const configCondition = configId
? Prisma.sql`AND s."config_id" = ${configId}`
: Prisma.empty;
+ const queueCondition = queueId
+ ? Prisma.sql`AND s."queue_id" = ${queueId}`
+ : Prisma.empty;
const dataTypeCondition = dataType
? Prisma.sql`AND s."data_type" = ${dataType}::"ScoreDataType"`
: Prisma.empty;
@@ -108,6 +112,7 @@ export default withMiddlewares({
s.comment,
s.data_type as "dataType",
s.config_id as "configId",
+ s.queue_id as "queueId",
s.trace_id as "traceId",
s.observation_id as "observationId",
json_build_object('userId', t.user_id) as "trace"
@@ -115,6 +120,7 @@ export default withMiddlewares({
LEFT JOIN "traces" AS t ON t.id = s.trace_id AND t.project_id = ${auth.scope.projectId}
WHERE s.project_id = ${auth.scope.projectId}
${configCondition}
+ ${queueCondition}
${dataTypeCondition}
${userCondition}
${nameCondition}
@@ -134,6 +140,7 @@ export default withMiddlewares({
LEFT JOIN "traces" AS t ON t.id = s.trace_id AND t.project_id = ${auth.scope.projectId}
WHERE s.project_id = ${auth.scope.projectId}
${configCondition}
+ ${queueCondition}
${dataTypeCondition}
${userCondition}
${nameCondition}