Skip to content

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

fix pricing (#113)

Maximilian Deichmannbd9cdb5f0f06
diff --git a/src/features/ingest/lib/usage.ts b/src/features/ingest/lib/usage.ts
index 422443a27d..70bc964af6 100644
--- a/src/features/ingest/lib/usage.ts
+++ b/src/features/ingest/lib/usage.ts
@@ -41,6 +41,7 @@ export function calculateTokenCost(
const pricing = pricingList.filter((p) => p.modelName === input.model);
if (!pricing || pricing.length === 0) {
+ console.log("no pricing found for model", input.model);
return undefined;
} else {
if (pricing.length === 1 && pricing[0]?.tokenType === "TOTAL") {
@@ -67,19 +68,11 @@ export function calculateTokenCost(
);
}
- if (
- promptPrice.equals(new Decimal(0)) ||
- completionPrice.equals(new Decimal(0))
- ) {
- throw new Error(
- `Multiple pricing entries found for model ${input.model}`
- );
- }
-
return promptPrice.plus(completionPrice);
}
+ console.log("unknown model", input.model);
+ return undefined;
}
- throw new Error(`Unexpected pricing configuration for model ${input.model}`);
}
const calculateValue = (price: Decimal, tokens: Decimal) => {
diff --git a/src/pages/project/[projectId]/traces/[traceId].tsx b/src/pages/project/[projectId]/traces/[traceId].tsx
index c3ba5708d9..44e5002038 100644
--- a/src/pages/project/[projectId]/traces/[traceId].tsx
+++ b/src/pages/project/[projectId]/traces/[traceId].tsx
@@ -13,10 +13,13 @@ export default function TracePage() {
const trace = api.traces.byId.useQuery(traceId);
- const totalCost = trace.data?.observations.reduce(
- (acc, o) => acc.plus(o.price ? o.price : new Decimal(0)),
- new Decimal(0)
- );
+ const totalCost = trace.data?.observations.reduce((acc, o) => {
+ if (!o.price) return acc;
+
+ return acc
+ ? acc.plus(o.price ? o.price : new Decimal(0))
+ : new Decimal(0).plus(o.price ? o.price : new Decimal(0));
+ }, undefined as Decimal | undefined);
return (
<div className="flex flex-col overflow-hidden xl:container lg:h-[calc(100vh-100px)] xl:h-[calc(100vh-50px)]">