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
| Name | Type |
|---|---|
T | extends OpenAIType |
Parameters
| Name | Type | Description |
|---|---|---|
openai | T | An 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
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
| Name | Type |
|---|---|
T | extends object |
Parameters
| Name | Type | Description |
|---|---|---|
sdk | T | An arbitrary SDK instance. |
options? | Object | LangSmith options. |
options.client? | Client | - |
options.runName? | string | - |
Returns
T