Wraps an OpenAI client's completion methods, enabling automatic LangSmith tracing. Method signatures are unchanged, with the exception that you can pass an additional and optional "langsmithExtra" field within the second parameter.
import { OpenAI } from "openai";import { wrapOpenAI } from "langsmith/wrappers/openai";const patchedClient = wrapOpenAI(new OpenAI());const patchedStream = await patchedClient.chat.completions.create( { messages: [{ role: "user", content: `Say 'foo'` }], model: "gpt-3.5-turbo", stream: true, }, { langsmithExtra: { metadata: { additional_data: "bar", }, }, },); Copy
import { OpenAI } from "openai";import { wrapOpenAI } from "langsmith/wrappers/openai";const patchedClient = wrapOpenAI(new OpenAI());const patchedStream = await patchedClient.chat.completions.create( { messages: [{ role: "user", content: `Say 'foo'` }], model: "gpt-3.5-turbo", stream: true, }, { langsmithExtra: { metadata: { additional_data: "bar", }, }, },);
An OpenAI client instance.
Optional
LangSmith options.
Wraps an OpenAI client's completion methods, enabling automatic LangSmith tracing. Method signatures are unchanged, with the exception that you can pass an additional and optional "langsmithExtra" field within the second parameter.
Example