Skip to content

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

feat(api): expose promptId via GET /observations (#1619)

Thomas Calvetc7aec93a21b7
diff --git a/web/src/__tests__/observations.servertest.ts b/web/src/__tests__/observations.servertest.ts
index 0205b75104..789d5ce840 100644
--- a/web/src/__tests__/observations.servertest.ts
+++ b/web/src/__tests__/observations.servertest.ts
@@ -41,6 +41,19 @@ describe("/api/public/observations API Endpoint", () => {
},
});
+ const prompt = await prisma.prompt.create({
+ data: {
+ name: "prompt-name",
+ prompt: "prompt-one",
+ isActive: false,
+ version: 1,
+ project: {
+ connect: { id: "7a88fb47-b4e2-43b8-a06c-a5ce950dc53a" },
+ },
+ createdBy: "user-1",
+ },
+ });
+
await prisma.observation.create({
data: {
id: uuidv4(),
@@ -62,6 +75,9 @@ describe("/api/public/observations API Endpoint", () => {
},
internalModel: "gpt-3.5-turbo",
unit: ModelUsageUnit.Tokens,
+ prompt: {
+ connect: { id: prompt.id },
+ },
},
});
@@ -95,6 +111,7 @@ describe("/api/public/observations API Endpoint", () => {
expect(
fetchedObservations.body.data[0]?.calculatedTotalCost,
).toBeGreaterThan(0);
+ expect(fetchedObservations.body.data[0]?.promptId).toBe(prompt.id);
});
it("should fetch all observations, filtered by generations", async () => {
await pruneDatabase();
diff --git a/web/src/pages/api/public/observations/index.ts b/web/src/pages/api/public/observations/index.ts
index c122e7ec92..1fcd7a2831 100644
--- a/web/src/pages/api/public/observations/index.ts
+++ b/web/src/pages/api/public/observations/index.ts
@@ -155,7 +155,8 @@ const getObservation = async (
o."calculated_input_cost" as "calculatedInputCost",
o."calculated_output_cost" as "calculatedOutputCost",
o."calculated_total_cost" as "calculatedTotalCost",
- o."latency"
+ o."latency",
+ o."prompt_id" as "promptId"
FROM observations_view o LEFT JOIN traces ON o."trace_id" = traces."id" AND traces."project_id" = o."project_id"
WHERE o."project_id" = ${authenticatedProjectId}
${nameCondition}