Skip to content

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

Feature/lf 27 fix display token usage on llm call (#14)

Maximilian Deichmannd709957e7f51
diff --git a/fern/fern.config.json b/fern/fern.config.json
index 3401f89f62..c69fda7f19 100644
--- a/fern/fern.config.json
+++ b/fern/fern.config.json
@@ -1,4 +1,4 @@
{
"organization": "finto",
- "version": "0.9.9"
+ "version": "0.10.24"
}
\ No newline at end of file
diff --git a/fern/server/definition/span.yml b/fern/server/definition/span.yml
index 780a2d11ae..0097ae9db8 100644
--- a/fern/server/definition/span.yml
+++ b/fern/server/definition/span.yml
@@ -70,12 +70,15 @@ types:
LLMAttributes:
properties:
- model: unknown
+ model: optional<string>
+ temperature: optional<double>
+ maxTokens: optional<integer>
+ topP: optional<double>
prompt: optional<string>
completion: optional<string>
tokens: optional<LLMTokens>
LLMTokens:
properties:
- prompt_amount: optional<integer>
- completion_amount: optional<integer>
+ promptAmount: optional<integer>
+ completionAmount: optional<integer>
diff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.yml
index 5e8837e0ac..070c9031c9 100644
--- a/generated/openapi-server/openapi.yml
+++ b/generated/openapi-server/openapi.yml
@@ -349,22 +349,29 @@ components:
title: LLMAttributes
type: object
properties:
- model: {}
+ model:
+ type: string
+ temperature:
+ type: number
+ format: double
+ maxTokens:
+ type: integer
+ topP:
+ type: number
+ format: double
prompt:
type: string
completion:
type: string
tokens:
$ref: '#/components/schemas/LLMTokens'
- required:
- - model
LLMTokens:
title: LLMTokens
type: object
properties:
- prompt_amount:
+ promptAmount:
type: integer
- completion_amount:
+ completionAmount:
type: integer
CreateTraceRequest:
title: CreateTraceRequest
diff --git a/src/components/observationDisplay.tsx b/src/components/observation-display.tsx
similarity index 100%
rename from src/components/observationDisplay.tsx
rename to src/components/observation-display.tsx
diff --git a/src/components/stats-cards.tsx b/src/components/stats-cards.tsx
new file mode 100644
index 0000000000..dc6ee17ec5
--- /dev/null
+++ b/src/components/stats-cards.tsx
@@ -0,0 +1,29 @@
+interface Statistic {
+ name: string;
+ stat: string;
+}
+
+export default function StatsCards({ stats }: { stats: Statistic[] }) {
+ return (
+ <div>
+ <h3 className="text-base font-semibold leading-6 text-gray-900">
+ Model configuration
+ </h3>
+ <dl className="mt-5 grid grid-cols-1 gap-5 sm:grid-cols-4">
+ {stats.map((item) => (
+ <div
+ key={item.name}
+ className="overflow-hidden rounded-lg bg-white px-4 py-5 shadow sm:p-6"
+ >
+ <dt className="truncate text-sm font-medium text-gray-500">
+ {item.name}
+ </dt>
+ <dd className="mt-1 text-3xl font-semibold tracking-tight text-gray-900">
+ {item.stat}
+ </dd>
+ </div>
+ ))}
+ </dl>
+ </div>
+ );
+}
diff --git a/src/components/ui/descriptionLists.tsx b/src/components/ui/description-lists.tsx
similarity index 100%
rename from src/components/ui/descriptionLists.tsx
rename to src/components/ui/description-lists.tsx
diff --git a/src/pages/api/public/llm-span.ts b/src/pages/api/public/llm-span.ts
index accdcf77c1..30aca55e2a 100644
--- a/src/pages/api/public/llm-span.ts
+++ b/src/pages/api/public/llm-span.ts
@@ -12,30 +12,34 @@ const LLMSpanCreateSchema = z.object({
name: z.string(),
startTime: z.string().datetime(),
attributes: z.object({
- prompt: z.string().optional(),
- completion: z.string().optional(),
+ prompt: z.string().nullish(),
+ completion: z.string().nullish(),
tokens: z
.object({
- prompt: z.number().optional(),
- completion: z.number().optional(),
+ prompt: z.number().nullish(),
+ completion: z.number().nullish(),
})
- .optional(),
+ .nullish(),
+ model: z.string().nullish(),
+ temperature: z.number().nullish(),
+ topP: z.number().nullish(),
+ maxTokens: z.number().nullish(),
}),
- parentObservationId: z.string().optional(),
+ parentObservationId: z.string().nullish(),
});
const LLMSpanUpdateSchema = z.object({
spanId: z.string(),
endTime: z.string().datetime(),
attributes: z.object({
- prompt: z.string().optional(),
- completion: z.string().optional(),
+ prompt: z.string().nullish(),
+ completion: z.string().nullish(),
tokens: z
.object({
- prompt: z.number().optional(),
- completion: z.number().optional(),
+ promptAmount: z.number().nullish(),
+ completionAmount: z.number().nullish(),
})
- .optional(),
+ .nullish(),
}),
});
diff --git a/src/pages/api/public/traces.ts b/src/pages/api/public/traces.ts
index 9fc623423d..45c894d070 100644
--- a/src/pages/api/public/traces.ts
+++ b/src/pages/api/public/traces.ts
@@ -25,7 +25,7 @@ export default async function handler(
await runMiddleware(req, res, cors);
if (req.method !== "POST" && req.method !== "PATCH") {
- console.log(req.method, req.body);
+ console.error(req.method, req.body);
return res.status(405).json({ message: "Method not allowed" });
}
diff --git a/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx b/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
index 292cdcbae2..d2729001f1 100644
--- a/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
+++ b/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
@@ -1,12 +1,13 @@
import { Button } from "@/src/components/ui/button";
import { CodeView, JSONview } from "@/src/components/ui/code";
-import DescriptionList from "@/src/components/ui/descriptionLists";
+import DescriptionList from "@/src/components/ui/description-lists";
import { ArrowUpRight } from "lucide-react";
import Link from "next/link";
import { useRouter } from "next/router";
import Header from "@/src/components/layouts/header";
import { api } from "@/src/utils/api";
+import StatsCards from "@/src/components/stats-cards";
export default function LlmCallPage() {
const router = useRouter();
@@ -24,6 +25,19 @@ export default function LlmCallPage() {
const traceScores =
llmCall.data?.scores.filter((score) => !obsMetrics?.includes(score)) ?? [];
+ const statProps = [
+ { name: "Model", stat: llmCall.data?.attributes.model ?? "-" },
+ {
+ name: "Temperature",
+ stat: llmCall.data?.attributes.temperature?.toString() ?? "-",
+ },
+ {
+ name: "Max Tokens",
+ stat: llmCall.data?.attributes.maxTokens?.toString() ?? "-",
+ },
+ { name: "Top P", stat: llmCall.data?.attributes.topP?.toString() ?? "-" },
+ ];
+
return (
<div className="container">
<Header
@@ -33,6 +47,9 @@ export default function LlmCallPage() {
{ name: llmCallId },
]}
/>
+ <div className="my-10">
+ <StatsCards stats={statProps} />
+ </div>
{llmCall.data ? (
<DescriptionList
items={[
@@ -67,10 +84,10 @@ export default function LlmCallPage() {
{
label: "Tokens",
value: [
- llmCall.data.attributes.tokens?.prompt &&
- `${llmCall.data.attributes.tokens.prompt} prompt tokens`,
- llmCall.data.attributes.tokens?.completion &&
- `${llmCall.data.attributes.tokens.completion} completion tokens`,
+ llmCall.data.attributes.tokens?.promptAmount &&
+ `${llmCall.data.attributes.tokens.promptAmount} prompt tokens`,
+ llmCall.data.attributes.tokens?.completionAmount &&
+ `${llmCall.data.attributes.tokens.completionAmount} completion tokens`,
]
.filter(Boolean)
.join(", "),
@@ -83,10 +100,6 @@ export default function LlmCallPage() {
label: "Completion",
value: <CodeView>{llmCall.data.attributes.completion}</CodeView>,
},
- {
- label: "Model",
- value: <JSONview json={llmCall.data.attributes.model} />,
- },
{
label: "Attributes",
value: <JSONview json={llmCall.data.attributes} />,
diff --git a/src/pages/project/[projectId]/traces.tsx b/src/pages/project/[projectId]/traces.tsx
index e57aeb8565..6a87cad238 100644
--- a/src/pages/project/[projectId]/traces.tsx
+++ b/src/pages/project/[projectId]/traces.tsx
@@ -15,7 +15,7 @@ import { Button } from "@/src/components/ui/button";
import Link from "next/link";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
import TableLink from "@/src/components/table/table-link";
-import ObservationDisplay from "@/src/components/observationDisplay";
+import ObservationDisplay from "@/src/components/observation-display";
import { useRouter } from "next/router";
import { type TableRowOptions } from "@/src/components/table/types";
import {
diff --git a/src/pages/project/[projectId]/traces/[traceId].tsx b/src/pages/project/[projectId]/traces/[traceId].tsx
index a827413041..c89eb4dddb 100644
--- a/src/pages/project/[projectId]/traces/[traceId].tsx
+++ b/src/pages/project/[projectId]/traces/[traceId].tsx
@@ -1,9 +1,9 @@
import { useRouter } from "next/router";
import Header from "@/src/components/layouts/header";
import { api } from "@/src/utils/api";
-import DescriptionList from "@/src/components/ui/descriptionLists";
+import DescriptionList from "@/src/components/ui/description-lists";
import { JSONview } from "@/src/components/ui/code";
-import ObservationDisplay from "@/src/components/observationDisplay";
+import ObservationDisplay from "@/src/components/observation-display";
export default function TracePage() {
const router = useRouter();
diff --git a/src/utils/types.ts b/src/utils/types.ts
index 80730ee970..c7b1e0aaf0 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -23,10 +23,13 @@ export type LlmCall = Observation & {
prompt?: string;
completion?: string;
tokens?: {
- prompt?: number;
- completion?: number;
+ promptAmount?: number;
+ completionAmount?: number;
};
- model: Prisma.JsonValue;
+ model?: string;
+ temperature?: number;
+ topP?: number;
+ maxTokens?: number;
};
};