Skip to content

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

support chat api for LLMs (#15)

Maximilian Deichmann88e5fb034bf3
diff --git a/fern/server/definition/span.yml b/fern/server/definition/span.yml
index 0097ae9db8..627359a054 100644
--- a/fern/server/definition/span.yml
+++ b/fern/server/definition/span.yml
@@ -74,10 +74,15 @@ types:
temperature: optional<double>
maxTokens: optional<integer>
topP: optional<double>
- prompt: optional<string>
+ prompt: optional<list<LLMPrompt>>
completion: optional<string>
tokens: optional<LLMTokens>
+ LLMPrompt:
+ properties:
+ role: string
+ content: string
+
LLMTokens:
properties:
promptAmount: optional<integer>
diff --git a/generated/openapi-server/openapi.yml b/generated/openapi-server/openapi.yml
index 070c9031c9..19f544a9f0 100644
--- a/generated/openapi-server/openapi.yml
+++ b/generated/openapi-server/openapi.yml
@@ -360,11 +360,24 @@ components:
type: number
format: double
prompt:
- type: string
+ type: array
+ items:
+ $ref: '#/components/schemas/LLMPrompt'
completion:
type: string
tokens:
$ref: '#/components/schemas/LLMTokens'
+ LLMPrompt:
+ title: LLMPrompt
+ type: object
+ properties:
+ role:
+ type: string
+ content:
+ type: string
+ required:
+ - role
+ - content
LLMTokens:
title: LLMTokens
type: object
diff --git a/prisma/seed.ts b/prisma/seed.ts
index ab845d27d7..0bfcdb8011 100755
--- a/prisma/seed.ts
+++ b/prisma/seed.ts
@@ -164,7 +164,12 @@ async function main() {
name: `llm-call-${i}-${j}-${k}`,
attributes: {
user: `user-${i}@langfuse.com`,
- prompt: "How can i create a React component?",
+ prompt: [
+ {
+ role: "user",
+ content: "How can i create a React component?",
+ },
+ ],
completion: `Creating a React component can be done in two ways: as a functional component or as a class component. Let's start with a basic example of both.
1. **Functional Component**:
diff --git a/src/components/prompts.tsx b/src/components/prompts.tsx
new file mode 100644
index 0000000000..d6cfaf024d
--- /dev/null
+++ b/src/components/prompts.tsx
@@ -0,0 +1,19 @@
+import { CodeView } from "@/src/components/ui/code";
+import { type LLMMessages } from "@/src/utils/types";
+
+export default function Prompt(props: { messages: LLMMessages[] }) {
+ return (
+ <>
+ {props.messages.map((message, index) => (
+ <div key={index}>
+ <div className="mb-2 mt-5">
+ <h3 className="inline-flex items-baseline rounded-full bg-gray-100 px-2.5 py-0.5 text-sm font-medium leading-6 text-gray-800 md:mt-2 lg:mt-0">
+ {message.role}
+ </h3>
+ </div>
+ <CodeView>{message.content}</CodeView>
+ </div>
+ ))}
+ </>
+ );
+}
diff --git a/src/pages/api/public/llm-span.ts b/src/pages/api/public/llm-span.ts
index 30aca55e2a..bb4444e3e5 100644
--- a/src/pages/api/public/llm-span.ts
+++ b/src/pages/api/public/llm-span.ts
@@ -12,7 +12,9 @@ const LLMSpanCreateSchema = z.object({
name: z.string(),
startTime: z.string().datetime(),
attributes: z.object({
- prompt: z.string().nullish(),
+ prompt: z
+ .array(z.object({ role: z.string(), content: z.string() }))
+ .nullish(),
completion: z.string().nullish(),
tokens: z
.object({
diff --git a/src/pages/project/[projectId]/llm-calls.tsx b/src/pages/project/[projectId]/llm-calls.tsx
index 0fa717888a..42e5aa9a88 100644
--- a/src/pages/project/[projectId]/llm-calls.tsx
+++ b/src/pages/project/[projectId]/llm-calls.tsx
@@ -4,10 +4,15 @@ import { type ColumnDef } from "@tanstack/react-table";
import { DataTable } from "@/src/components/table/data-table";
import TableLink from "@/src/components/table/table-link";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
-import { type RouterOutput, type RouterInput } from "@/src/utils/types";
+import {
+ type RouterOutput,
+ type RouterInput,
+ type LLMMessages,
+} from "@/src/utils/types";
import { useState } from "react";
import { type TableRowOptions } from "@/src/components/table/types";
import { useRouter } from "next/router";
+import Prompt from "@/src/components/prompts";
type LlmCallTableRow = {
id: string;
@@ -15,7 +20,7 @@ type LlmCallTableRow = {
startTime: Date;
endTime?: Date;
name: string;
- prompt?: string;
+ prompt?: LLMMessages[];
completion?: string;
model?: string;
};
@@ -110,6 +115,14 @@ export default function Traces() {
{
accessorKey: "prompt",
header: "Prompt",
+ cell: ({ row }) => {
+ const messages: LLMMessages[] = row.getValue("prompt");
+ if (!messages || messages.length === 0) {
+ return <>No prompt</>;
+ }
+
+ return <Prompt messages={messages} />;
+ },
},
{
accessorKey: "completion",
diff --git a/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx b/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
index d2729001f1..9ba4d49311 100644
--- a/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
+++ b/src/pages/project/[projectId]/llm-calls/[llmCallId].tsx
@@ -1,5 +1,5 @@
import { Button } from "@/src/components/ui/button";
-import { CodeView, JSONview } from "@/src/components/ui/code";
+import { CodeView } from "@/src/components/ui/code";
import DescriptionList from "@/src/components/ui/description-lists";
import { ArrowUpRight } from "lucide-react";
import Link from "next/link";
@@ -8,6 +8,7 @@ import Header from "@/src/components/layouts/header";
import { api } from "@/src/utils/api";
import StatsCards from "@/src/components/stats-cards";
+import Prompt from "@/src/components/prompts";
export default function LlmCallPage() {
const router = useRouter();
@@ -94,16 +95,14 @@ export default function LlmCallPage() {
},
{
label: "Prompt",
- value: <CodeView>{llmCall.data.attributes.prompt}</CodeView>,
+ value: llmCall.data.attributes.prompt ? (
+ <Prompt messages={llmCall.data.attributes.prompt} />
+ ) : undefined,
},
{
label: "Completion",
value: <CodeView>{llmCall.data.attributes.completion}</CodeView>,
},
- {
- label: "Attributes",
- value: <JSONview json={llmCall.data.attributes} />,
- },
{
label: "Metrics (observation)",
value: (
diff --git a/src/utils/types.ts b/src/utils/types.ts
index c7b1e0aaf0..aa0342f937 100644
--- a/src/utils/types.ts
+++ b/src/utils/types.ts
@@ -1,4 +1,4 @@
-import { type Observation, type Prisma } from "@prisma/client";
+import { type Observation } from "@prisma/client";
import { type inferRouterInputs, type inferRouterOutputs } from "@trpc/server";
import { type AppRouter } from "@/src/server/api/root";
@@ -17,10 +17,12 @@ export type Span = Observation & {
endTime: Date; // not null
};
+export type LLMMessages = { role: string; content: string };
+
export type LlmCall = Observation & {
type: "LLMCALL";
attributes: {
- prompt?: string;
+ prompt?: LLMMessages[];
completion?: string;
tokens?: {
promptAmount?: number;