Skip to main content

Module: wrappers/openai

Functions

wrapOpenAI

wrapOpenAI<T>(openai, options?): PatchedOpenAIClient<T>

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.

Type parameters

NameType
Textends OpenAIType

Parameters

NameTypeDescription
openaiTAn OpenAI client instance.
options?Partial<RunTreeConfig>LangSmith options.

Returns

PatchedOpenAIClient<T>

Example

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",
},
},
},
);

Defined in

wrappers/openai.ts:210


wrapSDK

wrapSDK<T>(sdk, options?): T

Wrap an arbitrary SDK, enabling automatic LangSmith tracing. Method signatures are unchanged.

Note that this will wrap and trace ALL SDK methods, not just LLM completion methods. If the passed SDK contains other methods, we recommend using the wrapped instance for LLM calls only.

Type parameters

NameType
Textends object

Parameters

NameTypeDescription
sdkTAn arbitrary SDK instance.
options?ObjectLangSmith options.
options.client?Client-
options.runName?string-

Returns

T

Defined in

wrappers/openai.ts:285


Was this page helpful?