Langtrace integrates directly with the Vercel AI Sdk, offering detailed, real-time insights into performance metrics such as accuracy, evaluations, and latency.
import * as Langtrace from '@langtrase/typescript-sdk';
import * as ai from 'ai'
import { openai } from '@ai-sdk/openai';
import { NextResponse, NextRequest } from 'next/server';
Langtrace.init({instrumentations: {ai: ai}, write_spans_to_console: false, disable_latest_version_check: true})
export async function GET(req: NextRequest) {
try {
const {text} = await ai.generateText({
model: openai('gpt-4-turbo', { user: 'TestUserId' }),
system: 'You are a friendly assistant!',
temperature: 0,
topP: 1,
maxRetries: 3,
maxTokens: 1024,
messages: [{ role: 'system', content: 'You are a friendly assistant' }, { role: 'user', content: 'How are you' }]
})
return NextResponse.json({response: text })
} catch (err) {
console.log(err)
return NextResponse.json({
error: err,
});
}
}