langfuse-js
langfuse-js copied to clipboard
OpenAI response_format in chat completion body breaks observeOpenAI()
Adding response_format
to a child OpenAI observation within a trace will cause the observability to fail. Uncomment the specified line to test.
Example adapted from the Get Started docs page
const langfuse = new Langfuse();
const openai = new OpenAI();
const trace = langfuse.trace({ name: "country-poem-generator" });
const span = trace.span({ name: "poem-span" });
const poem = (
await observeOpenAI(openai, {
parent: span,
generationName: "generate-poem",
}).chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{
role: "system",
content: "You are a poet. Create a haiku about this city.",
},
{ role: "user", content: "France" },
],
// Uncommenting the line below will break the Langfuse observability
// OpenAI API will respond as desired
// response_format: { type: "text" },
})
).choices[0].message.content;
console.log(poem)
span.end();