Skip to content

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

chore: include usagedetails from postgres in ingestion pipeline (#4034)

Steffen Schmitz64525744de20
diff --git a/worker/src/services/IngestionService/index.ts b/worker/src/services/IngestionService/index.ts
index 195155e849..965c52d9a3 100644
--- a/worker/src/services/IngestionService/index.ts
+++ b/worker/src/services/IngestionService/index.ts
@@ -364,6 +364,14 @@ export class IngestionService {
observationRecord: parsedObservationRecord,
});
+ if (
+ "usage_details" in generationUsage &&
+ Object.keys(generationUsage.usage_details).length === 0
+ ) {
+ generationUsage.usage_details =
+ postgresObservationRecord?.usage_details ?? {};
+ }
+
return {
...parsedObservationRecord,
...generationUsage,
diff --git a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
index 5b07354783..1835d46d2d 100644
--- a/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
+++ b/worker/src/services/IngestionService/tests/IngestionService.integration.test.ts
@@ -1069,6 +1069,7 @@ describe("Ingestion end-to-end tests", () => {
model: "gpt-3.5",
projectId,
startTime: new Date(oldEvent),
+ completionTokens: 5,
// Validates that numbers are parsed correctly. Since there is no usage, no effect on result
calculatedTotalCost: "0.273330000000000000000000000000",
modelParameters: { hello: "world" },
@@ -1106,6 +1107,7 @@ describe("Ingestion end-to-end tests", () => {
expect(observation.input).toBe(JSON.stringify({ key: "value" }));
expect(observation.output).toBe("overwritten");
expect(observation.model_parameters).toBe('{"hello":"world"}');
+ expect(observation.usage_details.output).toBe("5");
expect(observation.project_id).toBe("7a88fb47-b4e2-43b8-a06c-a5ce950dc53a");
});