🪢 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): add `from_timestamp` to GET /scores (#1545)
Marc Klingen8799a550b4e4
diff --git a/fern/apis/server/definition/score.yml b/fern/apis/server/definition/score.ymlindex 35c51c42bb..995c7c09c6 100644--- a/fern/apis/server/definition/score.yml+++ b/fern/apis/server/definition/score.yml@@ -23,6 +23,9 @@ service:limit: optional<integer>userId: optional<string>name: optional<string>+ from_timestamp:+ type: optional<datetime>+ docs: Retrieve only scores newer than this timestamp.response: Scoresget-by-id:docs: Get a scorediff --git a/generated/postman/collection.json b/generated/postman/collection.jsonindex 027785c5ef..b613efaedb 100644--- a/generated/postman/collection.json+++ b/generated/postman/collection.json@@ -643,7 +643,7 @@"request": {"description": "Get a list of scores","url": {- "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=",+ "raw": "{{baseUrl}}/api/public/scores?page=&limit=&userId=&name=&from_timestamp=","host": ["{{baseUrl}}"],@@ -672,6 +672,11 @@"key": "name","value": "","description": null+ },+ {+ "key": "from_timestamp",+ "value": "",+ "description": "Retrieve only scores newer than this timestamp."}],"variable": []diff --git a/web/generated/openapi-server/openapi.yml b/web/generated/openapi-server/openapi.ymlindex 07e620a47b..2d4983b324 100644--- a/web/generated/openapi-server/openapi.yml+++ b/web/generated/openapi-server/openapi.yml@@ -804,6 +804,14 @@ paths:schema:type: stringnullable: true+ - name: from_timestamp+ in: query+ description: Retrieve only scores newer than this timestamp.+ required: false+ schema:+ type: string+ format: date-time+ nullable: trueresponses:'200':description: ''diff --git a/web/src/pages/api/public/scores.ts b/web/src/pages/api/public/scores.tsindex 231a2c35fb..3bba3872d7 100644--- a/web/src/pages/api/public/scores.ts+++ b/web/src/pages/api/public/scores.ts@@ -9,6 +9,7 @@ import {ScoreBody,eventTypes,ingestionBatchEvent,+ stringDate,} from "@/src/features/public-api/server/ingestion-api-schema";import { v4 } from "uuid";import {@@ -21,6 +22,7 @@ const ScoresGetSchema = z.object({...paginationZod,userId: z.string().nullish(),name: z.string().nullish(),+ from_timestamp: stringDate,});export default async function handler(@@ -95,8 +97,15 @@ export default async function handler(const obj = ScoresGetSchema.parse(req.query); // uses query and not bodyconst skipValue = (obj.page - 1) * obj.limit;- const userCondition = Prisma.sql`AND t."user_id" = ${obj.userId}`;- const nameCondition = Prisma.sql`AND s."name" = ${obj.name}`;+ const userCondition = obj.userId+ ? Prisma.sql`AND t."user_id" = ${obj.userId}`+ : Prisma.empty;+ const nameCondition = obj.name+ ? Prisma.sql`AND s."name" = ${obj.name}`+ : Prisma.empty;+ const fromTimestampCondition = obj.from_timestamp+ ? Prisma.sql`AND t."timestamp" >= ${obj.from_timestamp}::timestamp with time zone at time zone 'UTC'`+ : Prisma.empty;const scores = await prisma.$queryRaw<Array<Score & { trace: { userId: string } }>@@ -113,17 +122,21 @@ export default async function handler(FROM "scores" AS sJOIN "traces" AS t ON t.id = s.trace_idWHERE t.project_id = ${authCheck.scope.projectId}- ${obj.userId ? userCondition : Prisma.empty}- ${obj.name ? nameCondition : Prisma.empty}+ ${userCondition}+ ${nameCondition}+ ${fromTimestampCondition}ORDER BY t."timestamp" DESCLIMIT ${obj.limit} OFFSET ${skipValue}`);const totalItems = await prisma.score.count({where: {- name: obj.name ?? undefined, // optional filter+ name: obj.name ? obj.name : undefined,+ timestamp: obj.from_timestamp+ ? { gte: new Date(obj.from_timestamp) }+ : undefined,trace: {projectId: authCheck.scope.projectId,- userId: obj.userId ? obj.userId : undefined, // optional filter+ userId: obj.userId ? obj.userId : undefined,},},});