🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
trace api
Max Deichmann9e37a4c4f712
diff --git a/src/pages/api/traces.ts b/src/pages/api/traces.tsindex 3f5b4bb5aa..c533d74fb6 100644--- a/src/pages/api/traces.ts+++ b/src/pages/api/traces.ts@@ -1,6 +1,45 @@import { type NextApiRequest, type NextApiResponse } from "next";+import { z } from "zod";+import { PrismaClient } from "@prisma/client";+const prisma = new PrismaClient();-export default function handler(req: NextApiRequest, res: NextApiResponse) {- res.status(200).json({ name: 'John Doe' });-}\ No newline at end of file+const TraceSchema = z.object({+ name: z.string(),+ attributes: z.record(z.string(), z.any()),+ status: z.string(),+ statusMessage: z.string().optional(),+});++export default async function handler(+ req: NextApiRequest,+ res: NextApiResponse+) {+ if (req.method !== "POST") {+ return res.status(405).json({ message: "Method not allowed" });+ }++ try {+ const { name, attributes, status, statusMessage } = TraceSchema.parse(+ req.body+ );++ const newTrace = await prisma.trace.create({+ data: {+ timestamp: new Date(),+ name,+ attributes,+ status,+ statusMessage,+ },+ });++ res.status(201).json({ trace: newTrace });+ } catch (error) {+ res.status(400).json({+ success: false,+ message: "Invalid request data",+ error: error.message,+ });+ }+}