🪢 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(api): GET /scores support for filtering by sessionId (#9176)
marliessophie63ec00efe925
diff --git a/fern/apis/server/definition/score-v2.yml b/fern/apis/server/definition/score-v2.ymlindex 8863faf6fb..d40e86907e 100644--- a/fern/apis/server/definition/score-v2.yml+++ b/fern/apis/server/definition/score-v2.yml@@ -50,6 +50,9 @@ service:configId:type: optional<string>docs: Retrieve only scores with a specific configId.+ sessionId:+ type: optional<string>+ docs: Retrieve only scores with a specific sessionId.queueId:type: optional<string>docs: Retrieve only scores with a specific annotation queueId.diff --git a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.tsindex 03101b012e..c740cf0e42 100644--- a/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts+++ b/packages/shared/src/features/scores/interfaces/api/v2/endpoints.ts@@ -8,7 +8,9 @@ export const GetScoreQueryV2 = GetScoreQuery;export const GetScoreResponseV2 = APIScoreSchemaV2;// GET /scores v2-export const GetScoresQueryV2 = GetScoresQuery;+export const GetScoresQueryV2 = GetScoresQuery.extend({+ sessionId: z.string().nullish(),+});export const GetScoreResponseDataV2 = z.intersection(APIScoreSchemaV2,z.object({diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.ymlindex 0956fbfab1..7ef7ed4199 100644--- a/web/public/generated/api/openapi.yml+++ b/web/public/generated/api/openapi.yml@@ -4017,6 +4017,13 @@ paths:schema:type: stringnullable: true+ - name: sessionId+ in: query+ description: Retrieve only scores with a specific sessionId.+ required: false+ schema:+ type: string+ nullable: true- name: queueIdin: querydescription: Retrieve only scores with a specific annotation queueId.diff --git a/web/public/generated/postman/collection.json b/web/public/generated/postman/collection.jsonindex d3033559a1..1e769ad109 100644--- a/web/public/generated/postman/collection.json+++ b/web/public/generated/postman/collection.json@@ -2875,7 +2875,7 @@"request": {"description": "Get a list of scores (supports both trace and session scores)","url": {- "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&queueId=&dataType=&traceTags=",+ "raw": "{{baseUrl}}/api/public/v2/scores?page=&limit=&userId=&name=&fromTimestamp=&toTimestamp=&environment=&source=&operator=&value=&scoreIds=&configId=&sessionId=&queueId=&dataType=&traceTags=","host": ["{{baseUrl}}"],@@ -2946,6 +2946,11 @@"value": "","description": "Retrieve only scores with a specific configId."},+ {+ "key": "sessionId",+ "value": "",+ "description": "Retrieve only scores with a specific sessionId."+ },{"key": "queueId","value": "",diff --git a/web/src/__tests__/async/scores-api-v1.servertest.ts b/web/src/__tests__/async/scores-api-v1.servertest.tsindex ac437aba88..5e2f8cd574 100644--- a/web/src/__tests__/async/scores-api-v1.servertest.ts+++ b/web/src/__tests__/async/scores-api-v1.servertest.ts@@ -11,7 +11,10 @@ import {createTracesCh,createOrgProjectAndApiKey,} from "@langfuse/shared/src/server";-import { makeZodVerifiedAPICall } from "@/src/__tests__/test-utils";+import {+ makeAPICall,+ makeZodVerifiedAPICall,+} from "@/src/__tests__/test-utils";import {DeleteScoreResponseV1,GetScoreResponseV1,@@ -1031,6 +1034,21 @@ describe("/api/public/scores API Endpoint", () => {]),);});++ it("should reject session ID filtering", async () => {+ try {+ await makeAPICall(+ "GET",+ `/api/public/scores?sessionId=${sessionId}`,+ undefined,+ authentication,+ );+ } catch (error) {+ expect((error as Error).message).toContain(+ "API call did not return 200, returned status 400",+ );+ }+ });});});});diff --git a/web/src/__tests__/async/scores-api-v2.servertest.ts b/web/src/__tests__/async/scores-api-v2.servertest.tsindex 8ad1bf1f3e..1fddaeb441 100644--- a/web/src/__tests__/async/scores-api-v2.servertest.ts+++ b/web/src/__tests__/async/scores-api-v2.servertest.ts@@ -865,6 +865,39 @@ describe("/api/public/v2/scores API Endpoint", () => {]),);});++ it("should filter scores by session ID", async () => {+ const getScore = await makeZodVerifiedAPICall(+ GetScoresResponseV2,+ "GET",+ `/api/public/v2/scores?sessionId=${sessionId}`,+ undefined,+ authentication,+ );+ expect(getScore.status).toBe(200);+ expect(getScore.body.meta).toMatchObject({+ page: 1,+ limit: 50,+ totalItems: 2,+ totalPages: 1,+ });+ expect(getScore.body.data).toEqual(+ expect.arrayContaining([+ expect.objectContaining({+ id: scoreId_6,+ sessionId: sessionId,+ name: scoreName,+ value: 100.5,+ }),+ expect.objectContaining({+ id: scoreId_7,+ sessionId: sessionId,+ name: "session-score-name",+ value: 100.5,+ }),+ ]),+ );+ });});});});diff --git a/web/src/features/public-api/server/scores.ts b/web/src/features/public-api/server/scores.tsindex f5b46417e5..c45f2beaa6 100644--- a/web/src/features/public-api/server/scores.ts+++ b/web/src/features/public-api/server/scores.ts@@ -20,6 +20,7 @@ export type ScoreQueryType = {value?: number;scoreId?: string;configId?: string;+ sessionId?: string;queueId?: string;traceTags?: string | string[];operator?: string;@@ -323,6 +324,13 @@ const secureScoreFilterOptions = [filterType: "StringFilter",clickhousePrefix: "s",},+ {+ id: "sessionId",+ clickhouseSelect: "session_id",+ clickhouseTable: "scores",+ filterType: "StringFilter",+ clickhousePrefix: "s",+ },{id: "queueId",clickhouseSelect: "queue_id",diff --git a/web/src/pages/api/public/v2/scores/index.ts b/web/src/pages/api/public/v2/scores/index.tsindex e36eca6295..be3a373866 100644--- a/web/src/pages/api/public/v2/scores/index.ts+++ b/web/src/pages/api/public/v2/scores/index.ts@@ -20,6 +20,7 @@ export default withMiddlewares({userId: query.userId ?? undefined,name: query.name ?? undefined,configId: query.configId ?? undefined,+ sessionId: query.sessionId ?? undefined,queueId: query.queueId ?? undefined,traceTags: query.traceTags ?? undefined,dataType: query.dataType ?? undefined,