import { initLogger, wrapTraced } from "braintrust";
const logger = initLogger({ projectName: "My Project" });
// Return span ID from your endpoint
export async function POST(req: Request) {
return logger.traced(async (span) => {
const text = await req.text();
const result = await processRequest(text);
span.log({ input: text, output: result });
return {
result,
requestId: span.id, // Return this to the client
};
});
}
// Log feedback from a separate endpoint
export async function POSTFeedback(req: Request) {
const body = await req.json();
logger.logFeedback({
id: body.requestId, // Span ID from the original request
scores: {
correctness: body.score, // 1 for thumbs up, 0 for thumbs down
},
comment: body.comment,
metadata: {
user_id: body.userId,
},
});
}