diff --git a/app/api/metrics/score/route.ts b/app/api/metrics/score/route.ts
index b427df0c..b9a5b67a 100644
--- a/app/api/metrics/score/route.ts
+++ b/app/api/metrics/score/route.ts
@@ -108,7 +108,7 @@ export async function POST(req: NextRequest) {
if (scores[1] === 0) {
entry[testId] = 0;
} else {
- entry[testId] = Math.round((scores[0] / scores[1]) * 100);
+ entry[testId] = scores[0] / scores[1];
}
}
);
@@ -124,16 +124,22 @@ export async function POST(req: NextRequest) {
Object.entries(dateScoreMap).map(([date, scoresByTestId]) => {
Object.entries(scoresByTestId as any).forEach(([testId, scores]: any) => {
if (!scoresChartData[testId]) {
- scoresChartData[testId] = 0;
+ scoresChartData[testId] = [0, 0];
}
- if (scores[1] === 0) {
- scoresChartData[testId] = 0;
- }
- scoresChartData[testId] =
- Math.round((scores[0] / scores[1]) * 100) / 100;
+ scoresChartData[testId][0] += scores[0];
+ scoresChartData[testId][1] += scores[1];
});
});
+ const totalScores = Object.entries(scoresChartData).map(
+ ([testId, scores]: any) => {
+ if (scores[1] === 0) {
+ return 0;
+ }
+ return ((scores[0] / scores[1]) * 100).toFixed(2);
+ }
+ );
+
metricsChartData.sort(
(a, b) =>
new Date(a.date as string).getTime() -
@@ -142,7 +148,7 @@ export async function POST(req: NextRequest) {
return NextResponse.json({
metrics: metricsChartData,
- scores: scoresChartData,
+ scores: totalScores,
});
} catch (error) {
return NextResponse.json(
diff --git a/components/annotations/chart-tabs.tsx b/components/annotations/chart-tabs.tsx
index 555c8068..66f28607 100644
--- a/components/annotations/chart-tabs.tsx
+++ b/components/annotations/chart-tabs.tsx
@@ -38,7 +38,7 @@ export function ChartTabs({
{
key: "name",
operation: "EQUALS",
- value: "gen_ai.content.prompt",
+ value: "gen_ai.content.completion",
type: "event",
},
],
@@ -92,7 +92,7 @@ export function ChartTabs({
{Object.keys(chartData?.scores).map(
(testId: string, index: number) => {
- const score = (chartData?.scores[testId] || 0) * 100;
+ const score = chartData?.scores[testId] || 0;
const testName = tests.find((test) =>
testId.includes(test.id)
)?.name;
@@ -114,7 +114,7 @@ export function ChartTabs({
bgColor
)}
>
- {(chartData?.scores[testId] || 0) * 100}%
+ {chartData?.scores[testId] || 0}%
diff --git a/lib/services/trace_service.ts b/lib/services/trace_service.ts
index 1a2664f6..1caf851f 100644
--- a/lib/services/trace_service.ts
+++ b/lib/services/trace_service.ts
@@ -848,6 +848,7 @@ export class TraceService implements ITraceService {
const conditions = [
sql.or(
sql.like("attributes", "%total_tokens%"),
+ sql.like("attributes", "%gen_ai.usage.input_tokens%"),
sql.like("attributes", "%gen_ai.usage.prompt_tokens%")
),
sql.gte("start_time", nHoursAgo),
@@ -1017,6 +1018,8 @@ export class TraceService implements ITraceService {
JSONExtractString(attributes, 'llm.token.counts'), 'input_tokens'
) + COALESCE(
JSONExtractInt(attributes, 'gen_ai.usage.input_tokens'), 0
+ ) + COALESCE(
+ JSONExtractInt(attributes, 'gen_ai.usage.prompt_tokens'), 0
)
) AS input_tokens`,
`SUM(
@@ -1024,6 +1027,8 @@ export class TraceService implements ITraceService {
JSONExtractString(attributes, 'llm.token.counts'), 'output_tokens'
) + COALESCE(
JSONExtractInt(attributes, 'gen_ai.usage.output_tokens'), 0
+ ) + COALESCE(
+ JSONExtractInt(attributes, 'gen_ai.usage.completion_tokens'), 0
)
) AS output_tokens`,
])
diff --git a/package.json b/package.json
index 62e41838..2ea3aac9 100644
--- a/package.json
+++ b/package.json
@@ -27,8 +27,8 @@
"@headlessui/react": "^1.7.18",
"@headlessui/tailwindcss": "^0.2.0",
"@hookform/resolvers": "^3.3.4",
- "@langtrase/trace-attributes": "^6.0.5",
- "@langtrase/typescript-sdk": "^3.3.2",
+ "@langtrase/trace-attributes": "^7.0.1",
+ "@langtrase/typescript-sdk": "^5.0.1",
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@mui/x-tree-view": "^6.17.0",