Skip to content

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

rename

Max Deichmann63e3a698c5a4
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index 22d322c45b..dd3d6915fd 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -2,6 +2,10 @@
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
+ "astro-build.astro-vscode",
+ "bradlc.vscode-tailwindcss",
+ "unifiedjs.vscode-mdx",
+ "yoavbls.pretty-ts-errors",
"Prisma.prisma"
]
-}
\ No newline at end of file
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000..a957609b10
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,27 @@
+{
+ "editor.codeActionsOnSave": {
+ "source.fixAll.eslint": true
+ },
+ "editor.defaultFormatter": "esbenp.prettier-vscode",
+ "editor.formatOnSave": true,
+ "editor.rulers": [100],
+ "editor.tabSize": 2,
+
+ "eslint.validate": [
+ "javascript",
+ "javascriptreact",
+ "astro",
+ "typescript",
+ "typescriptreact"
+ ],
+
+ "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
+ "typescript.tsdk": "node_modules/typescript/lib",
+ "prettier.documentSelectors": [
+ "**/*.{cjs,mjs,ts,tsx,astro,md,mdx,json,yaml,yml}"
+ ],
+ "mdx.experimentalLanguageServer": true,
+ "[astro]": {
+ "editor.defaultFormatter": "astro-build.astro-vscode"
+ }
+ }
\ No newline at end of file
diff --git a/README.md b/README.md
index 8ed32b6bc0..93125df658 100644
--- a/README.md
+++ b/README.md
@@ -4,36 +4,37 @@ Langfuse is an observability platform for LLM native applications.
## Development
-To get it running, follow the steps below
+Follow the steps below to setup the development environment.
### Setup env variables
Copy the `.env.example` file to `.env` and fill in the values.
-### Install dependencies
+### Set up the application locally
-```bash
-npm install
-```
-
-### Migration
+Follow the steps below to set up a dev environment. You will have a postgres database running in a docker container. The server will be started using NPM.
```bash
+# Install dependencies
+npm install
+# Run the db
+docker-compose up
+# Migration
npx prisma migrate dev
-```
-
-### Seed the database
-
-```bash
+# Seed the database
npx prisma db seed
+# Start the server
+npm run dev
```
-### Start the server
+Follow the steps below to set up the environment via docker-compose. Both the server and the database will be running in docker containers.
```bash
-npm run dev
+docker-compose -f docker-compose.local.yml up
```
+## Production Deployment
+
### Generate SDKs
```bash
@@ -47,8 +48,6 @@ npm install --save @finto-fern/api-client
# update the client in the client repo
# install ncu via: https://www.npmjs.com/package/npm-check-updates
ncu -u && npm update --save
-
-
```
### UI Libraries
diff --git a/docker-compose.local.yml b/docker-compose.local.yml
new file mode 100644
index 0000000000..426ac63333
--- /dev/null
+++ b/docker-compose.local.yml
@@ -0,0 +1,30 @@
+version: "3.5"
+
+services:
+ server:
+ build:
+ dockerfile: Dockerfile
+ command: ["sh", "-c", "npx prisma migrate deploy && node server.js"]
+ depends_on:
+ - db
+ ports:
+ - "3000:3000"
+ environment:
+ - NODE_ENV=development
+ - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
+ - DIRECT_URL=postgresql://postgres:postgres@db:5432/postgres
+ db:
+ image: postgres
+ restart: always
+ environment:
+ - POSTGRES_USER=postgres
+ - POSTGRES_PASSWORD=postgres
+ - POSTGRES_DB=postgres
+ ports:
+ - 5432:5432
+ volumes:
+ - database_data:/var/lib/postgresql/data
+
+volumes:
+ database_data:
+ driver: local
diff --git a/docker-compose.yml b/docker-compose.yml
index 3b9a8eb547..016fc1d228 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,19 +1,6 @@
version: '3.5'
services:
-
- server:
- build:
- dockerfile: Dockerfile
- command: ["sh", "-c", "npx prisma migrate deploy && node server.js"]
- depends_on:
- - db
- ports:
- - "3000:3000"
- environment:
- - NODE_ENV=development
- - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- - DIRECT_URL=postgresql://postgres:postgres@db:5432/postgres
db:
image: postgres
restart: always
diff --git a/fern/api/definition/metric.yml b/fern/api/definition/score.yml
similarity index 74%
rename from fern/api/definition/metric.yml
rename to fern/api/definition/score.yml
index fc290eef9c..5d2b55d8fa 100644
--- a/fern/api/definition/metric.yml
+++ b/fern/api/definition/score.yml
@@ -5,20 +5,20 @@ service:
base-path: /api
endpoints:
create:
- docs: Add a metric to the database
+ docs: Add a score to the database
method: POST
- path: /metrics
- request: CreateMetricRequest
- response: Metric
+ path: /scores
+ request: CreateScoreRequest
+ response: Score
types:
- CreateMetricRequest:
+ CreateScoreRequest:
properties:
traceId: string
name: string
value: integer
observationId: optional<string>
- Metric:
+ Score:
properties:
id: string
name: string
diff --git a/generated/openapi/openapi.yml b/generated/openapi/openapi.yml
index bca36c982f..9f3563ece7 100644
--- a/generated/openapi/openapi.yml
+++ b/generated/openapi/openapi.yml
@@ -1,7 +1,7 @@
openapi: 3.0.1
info:
title: langfuse
- version: ''
+ version: ""
paths:
/api/events:
post:
@@ -11,38 +11,38 @@ paths:
- Event
parameters: []
responses:
- '200':
- description: ''
+ "200":
+ description: ""
content:
application/json:
schema:
- $ref: '#/components/schemas/Event'
+ $ref: "#/components/schemas/Event"
requestBody:
required: true
content:
application/json:
schema:
- $ref: '#/components/schemas/CreateEventRequest'
- /api/metrics:
+ $ref: "#/components/schemas/CreateEventRequest"
+ /api/scores:
post:
- description: Add a metric to the database
- operationId: metric_create
+ description: Add a score to the database
+ operationId: score_create
tags:
- - Metric
+ - Score
parameters: []
responses:
- '200':
- description: ''
+ "200":
+ description: ""
content:
application/json:
schema:
- $ref: '#/components/schemas/Metric'
+ $ref: "#/components/schemas/Score"
requestBody:
required: true
content:
application/json:
schema:
- $ref: '#/components/schemas/CreateMetricRequest'
+ $ref: "#/components/schemas/CreateScoreRequest"
/api/spans:
post:
description: Add a span to the database
@@ -51,18 +51,18 @@ paths:
- Span
parameters: []
responses:
- '200':
- description: ''
+ "200":
+ description: ""
content:
application/json:
schema:
- $ref: '#/components/schemas/Span'
+ $ref: "#/components/schemas/Span"
requestBody:
required: true
content:
application/json:
schema:
- $ref: '#/components/schemas/CreateSpanRequest'
+ $ref: "#/components/schemas/CreateSpanRequest"
patch:
description: Update a span to the database
operationId: span_update
@@ -70,18 +70,18 @@ paths:
- Span
parameters: []
responses:
- '200':
- description: ''
+ "200":
+ description: ""
content:
application/json:
schema:
- $ref: '#/components/schemas/Span'
+ $ref: "#/components/schemas/Span"
requestBody:
required: true
content:
application/json:
schema:
- $ref: '#/components/schemas/UpdateSpanRequest'
+ $ref: "#/components/schemas/UpdateSpanRequest"
/api/traces:
post:
description: Add a trace to the database
@@ -90,18 +90,18 @@ paths:
- Trace
parameters: []
responses:
- '200':
- description: ''
+ "200":
+ description: ""
content:
application/json:
schema:
- $ref: '#/components/schemas/Trace'
+ $ref: "#/components/schemas/Trace"
requestBody:
required: true
content:
application/json:
schema:
- $ref: '#/components/schemas/CreateTraceRequest'
+ $ref: "#/components/schemas/CreateTraceRequest"
components:
schemas:
CreateEventRequest:
@@ -148,8 +148,8 @@ components:
- name
- startTime
- attributes
- CreateMetricRequest:
- title: CreateMetricRequest
+ CreateScoreRequest:
+ title: CreateScoreRequest
type: object
properties:
traceId:
@@ -164,8 +164,8 @@ components:
- traceId
- name
- value
- Metric:
- title: Metric
+ Score:
+ title: Score
type: object
properties:
id:
diff --git a/generated/python/__init__.py b/generated/python/__init__.py
index 136a71cf3f..d6386838bf 100644
--- a/generated/python/__init__.py
+++ b/generated/python/__init__.py
@@ -2,32 +2,32 @@
from .resources import (
CreateEventRequest,
- CreateMetricRequest,
+ CreateScoreRequest,
CreateSpanRequest,
CreateTraceRequest,
Event,
- Metric,
+ Score,
Span,
Trace,
UpdateSpanRequest,
event,
- metric,
+ score,
span,
trace,
)
__all__ = [
"CreateEventRequest",
- "CreateMetricRequest",
+ "CreateScoreRequest",
"CreateSpanRequest",
"CreateTraceRequest",
"Event",
- "Metric",
+ "Score",
"Span",
"Trace",
"UpdateSpanRequest",
"event",
- "metric",
+ "score",
"span",
"trace",
]
diff --git a/generated/python/client.py b/generated/python/client.py
index 55da3c37a6..44b05d7453 100644
--- a/generated/python/client.py
+++ b/generated/python/client.py
@@ -4,7 +4,7 @@ from backports.cached_property import cached_property
from .environment import FintoLangfuseEnvironment
from .resources.event.client import EventClient
-from .resources.metric.client import MetricClient
+from .resources.score.client import ScoreClient
from .resources.span.client import SpanClient
from .resources.trace.client import TraceClient
@@ -18,8 +18,8 @@ class FintoLangfuse:
return EventClient(environment=self._environment)
@cached_property
- def metric(self) -> MetricClient:
- return MetricClient(environment=self._environment)
+ def score(self) -> ScoreClient:
+ return ScoreClient(environment=self._environment)
@cached_property
def span(self) -> SpanClient:
diff --git a/generated/python/resources/__init__.py b/generated/python/resources/__init__.py
index 0e0ff1f4db..c4a636e5d2 100644
--- a/generated/python/resources/__init__.py
+++ b/generated/python/resources/__init__.py
@@ -1,23 +1,23 @@
# This file was auto-generated by Fern from our API Definition.
-from . import event, metric, span, trace
+from . import event, score, span, trace
from .event import CreateEventRequest, Event
-from .metric import CreateMetricRequest, Metric
+from .score import CreateScoreRequest, Score
from .span import CreateSpanRequest, Span, UpdateSpanRequest
from .trace import CreateTraceRequest, Trace
__all__ = [
"CreateEventRequest",
- "CreateMetricRequest",
+ "CreateScoreRequest",
"CreateSpanRequest",
"CreateTraceRequest",
"Event",
- "Metric",
+ "Score",
"Span",
"Trace",
"UpdateSpanRequest",
"event",
- "metric",
+ "score",
"span",
"trace",
]
diff --git a/generated/python/resources/metric/__init__.py b/generated/python/resources/metric/__init__.py
deleted file mode 100644
index fcafdfa26b..0000000000
--- a/generated/python/resources/metric/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-# This file was auto-generated by Fern from our API Definition.
-
-from .types import CreateMetricRequest, Metric
-
-__all__ = ["CreateMetricRequest", "Metric"]
diff --git a/generated/python/resources/metric/types/__init__.py b/generated/python/resources/metric/types/__init__.py
deleted file mode 100644
index 9284ee5412..0000000000
--- a/generated/python/resources/metric/types/__init__.py
+++ /dev/null
@@ -1,6 +0,0 @@
-# This file was auto-generated by Fern from our API Definition.
-
-from .create_metric_request import CreateMetricRequest
-from .metric import Metric
-
-__all__ = ["CreateMetricRequest", "Metric"]
diff --git a/generated/python/resources/score/__init__.py b/generated/python/resources/score/__init__.py
new file mode 100644
index 0000000000..85b283fc81
--- /dev/null
+++ b/generated/python/resources/score/__init__.py
@@ -0,0 +1,5 @@
+# This file was auto-generated by Fern from our API Definition.
+
+from .types import CreateScoreRequest, Score
+
+__all__ = ["CreateScoreRequest", "Score"]
diff --git a/generated/python/resources/metric/client.py b/generated/python/resources/score/client.py
similarity index 72%
rename from generated/python/resources/metric/client.py
rename to generated/python/resources/score/client.py
index 03d64e1858..ca41e6eb08 100644
--- a/generated/python/resources/metric/client.py
+++ b/generated/python/resources/score/client.py
@@ -9,20 +9,20 @@ import pydantic
from ...core.api_error import ApiError
from ...core.jsonable_encoder import jsonable_encoder
from ...environment import FintoLangfuseEnvironment
-from .types.create_metric_request import CreateMetricRequest
-from .types.metric import Metric
+from .types.create_score_request import CreateScoreRequest
+from .types.score import Score
-class MetricClient:
+class ScoreClient:
def __init__(self, *, environment: FintoLangfuseEnvironment):
self._environment = environment
- def create(self, *, request: CreateMetricRequest) -> Metric:
+ def create(self, *, request: CreateScoreRequest) -> Score:
_response = httpx.request(
- "POST", urllib.parse.urljoin(f"{self._environment}/", "api/metrics"), json=jsonable_encoder(request)
+ "POST", urllib.parse.urljoin(f"{self._environment}/", "api/scores"), json=jsonable_encoder(request)
)
if 200 <= _response.status_code < 300:
- return pydantic.parse_obj_as(Metric, _response.json()) # type: ignore
+ return pydantic.parse_obj_as(Score, _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
diff --git a/generated/python/resources/score/types/__init__.py b/generated/python/resources/score/types/__init__.py
new file mode 100644
index 0000000000..6b56e13740
--- /dev/null
+++ b/generated/python/resources/score/types/__init__.py
@@ -0,0 +1,6 @@
+# This file was auto-generated by Fern from our API Definition.
+
+from .create_score_request import CreateScoreRequest
+from .score import Score
+
+__all__ = ["CreateScoreRequest", "Score"]
diff --git a/generated/python/resources/metric/types/create_metric_request.py b/generated/python/resources/score/types/create_score_request.py
similarity index 95%
rename from generated/python/resources/metric/types/create_metric_request.py
rename to generated/python/resources/score/types/create_score_request.py
index e193dfd957..76d849e86d 100644
--- a/generated/python/resources/metric/types/create_metric_request.py
+++ b/generated/python/resources/score/types/create_score_request.py
@@ -8,7 +8,7 @@ import pydantic
from ....core.datetime_utils import serialize_datetime
-class CreateMetricRequest(pydantic.BaseModel):
+class CreateScoreRequest(pydantic.BaseModel):
trace_id: str = pydantic.Field(alias="traceId")
name: str
value: int
diff --git a/generated/python/resources/metric/types/metric.py b/generated/python/resources/score/types/score.py
similarity index 96%
rename from generated/python/resources/metric/types/metric.py
rename to generated/python/resources/score/types/score.py
index 153d556180..be025e7e9f 100644
--- a/generated/python/resources/metric/types/metric.py
+++ b/generated/python/resources/score/types/score.py
@@ -8,7 +8,7 @@ import pydantic
from ....core.datetime_utils import serialize_datetime
-class Metric(pydantic.BaseModel):
+class Score(pydantic.BaseModel):
id: str
name: str
value: int
diff --git a/package.json b/package.json
index 82552bcb63..a5b9318e4d 100644
--- a/package.json
+++ b/package.json
@@ -7,6 +7,7 @@
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint",
+ "clean": "rm -rf node_modules",
"start": "next start"
},
"prisma": {
diff --git a/src/components/layouts/layout.tsx b/src/components/layouts/layout.tsx
index ad070dfd6e..92d3f3f9fa 100644
--- a/src/components/layouts/layout.tsx
+++ b/src/components/layouts/layout.tsx
@@ -18,7 +18,7 @@ const navigationPaths = [
{ name: "Dashboard", href: "/", icon: HomeIcon },
{ name: "Traces", href: "/traces", icon: UsersIcon },
{ name: "LLM Calls", href: "/llm-calls", icon: DocumentDuplicateIcon },
- { name: "Metrics", href: "/metrics", icon: LineChart },
+ { name: "Scores", href: "/scores", icon: LineChart },
{ name: "Playground (soon)", href: "#", icon: Joystick },
];
diff --git a/src/pages/api/metrics.ts b/src/pages/api/scores.ts
similarity index 86%
rename from src/pages/api/metrics.ts
rename to src/pages/api/scores.ts
index df7ae1763b..2e587b5d3b 100644
--- a/src/pages/api/metrics.ts
+++ b/src/pages/api/scores.ts
@@ -4,7 +4,7 @@ import { type NextApiRequest, type NextApiResponse } from "next";
import { z } from "zod";
import { cors, runMiddleware } from "./cors";
-const MetricSchema = z.object({
+const ScoreSchema = z.object({
name: z.string(),
value: z.number().int(),
traceId: z.string(),
@@ -22,7 +22,7 @@ export default async function handler(
}
try {
- const obj = MetricSchema.parse(req.body);
+ const obj = ScoreSchema.parse(req.body);
const data: Prisma.ScoreCreateInput = {
timestamp: new Date(),
@@ -35,9 +35,9 @@ export default async function handler(
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
- const newObservation = await prisma.score.create({ data });
+ const newScore = await prisma.score.create({ data });
- res.status(201).json(newObservation);
+ res.status(201).json(newScore);
} catch (error: unknown) {
const errorMessage =
error instanceof Error ? error.message : "An unknown error occurred";
diff --git a/src/pages/llm-calls/[llmCallId].tsx b/src/pages/llm-calls/[llmCallId].tsx
index 2404a67a60..e173a94ac4 100644
--- a/src/pages/llm-calls/[llmCallId].tsx
+++ b/src/pages/llm-calls/[llmCallId].tsx
@@ -20,7 +20,8 @@ export default function LlmCallPage() {
llmCall.data?.scores.filter(
(score) => score.observationId === llmCall.data.id
) ?? [];
- const traceScores = llmCall.data?.scores.filter((score) => !obsMetrics?.includes(score)) ??[];
+ const traceScores =
+ llmCall.data?.scores.filter((score) => !obsMetrics?.includes(score)) ?? [];
return (
<>
diff --git a/src/pages/metrics.tsx b/src/pages/scores.tsx
similarity index 80%
rename from src/pages/metrics.tsx
rename to src/pages/scores.tsx
index 7634e2bfb6..2928697a7d 100644
--- a/src/pages/metrics.tsx
+++ b/src/pages/scores.tsx
@@ -19,8 +19,8 @@ interface RowData {
observationId?: string;
}
-export default function MetricsPage() {
- const metrics = api.scores.all.useQuery(undefined, {
+export default function ScoresPage() {
+ const scores = api.scores.all.useQuery(undefined, {
refetchInterval: 1000,
});
const router = useRouter();
@@ -60,14 +60,14 @@ export default function MetricsPage() {
{ field: "value", headerName: "Value", minWidth: 200 },
];
- const rows: GridRowsProp = metrics.isSuccess
- ? metrics.data.map((metric) => ({
- id: metric.id,
- timestamp: metric.timestamp,
- name: metric.name,
- value: metric.value,
- observationId: metric.observationId,
- traceId: metric.traceId,
+ const rows: GridRowsProp = scores.isSuccess
+ ? scores.data.map((scores) => ({
+ id: scores.id,
+ timestamp: scores.timestamp,
+ name: scores.name,
+ value: scores.value,
+ observationId: scores.observationId,
+ traceId: scores.traceId,
}))
: [];
@@ -78,7 +78,7 @@ export default function MetricsPage() {
rows={rows}
columns={columns}
slots={{ toolbar: GridToolbar }}
- loading={metrics.isLoading}
+ loading={scores.isLoading}
/>
</>
);
diff --git a/src/pages/traces.tsx b/src/pages/traces.tsx
index 42b9b1b169..7222f77b04 100644
--- a/src/pages/traces.tsx
+++ b/src/pages/traces.tsx
@@ -54,8 +54,8 @@ export default function Traces() {
flex: 1,
},
{
- field: "metrics",
- headerName: "Metrics",
+ field: "scores",
+ headerName: "Scores",
flex: 1,
},
];
@@ -68,8 +68,8 @@ export default function Traces() {
status: trace.status,
statusMessage: trace.statusMessage,
attributes: JSON.stringify(trace.attributes),
- metrics: trace.metrics
- .map((metric) => `${metric.name}: ${metric.value}`)
+ scores: trace.scores
+ .map((score) => `${score.name}: ${score.value}`)
.join("; "),
}))
: [];
diff --git a/src/server/api/routers/traces.ts b/src/server/api/routers/traces.ts
index 0c0edaef82..bdfd3a7adb 100644
--- a/src/server/api/routers/traces.ts
+++ b/src/server/api/routers/traces.ts
@@ -12,7 +12,7 @@ export const traceRouter = createTRPCRouter({
timestamp: "desc",
},
include: {
- metrics: true,
+ scores: true,
},
});
@@ -26,7 +26,7 @@ export const traceRouter = createTRPCRouter({
id: input,
},
include: {
- metrics: true,
+
},
}),
prisma.observation.findMany({