Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): pass other traceable options in wrapSDK #878

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions js/src/wrappers/openai.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAI } from "openai";
import type { APIPromise } from "openai/core";
import type { Client, RunTreeConfig } from "../index.js";
import type { RunTreeConfig } from "../index.js";
import { isTraceableFunction, traceable } from "../traceable.js";

// Extra leniency around types in case multiple OpenAI SDK versions get installed
Expand Down Expand Up @@ -280,7 +280,7 @@ export const wrapOpenAI = <T extends OpenAIType>(
const _wrapClient = <T extends object>(
sdk: T,
runName: string,
options?: { client?: Client }
options?: Omit<RunTreeConfig, "name">
): T => {
return new Proxy(sdk, {
get(target, propKey, receiver) {
Expand Down Expand Up @@ -312,6 +312,10 @@ const _wrapClient = <T extends object>(
});
};

type WrapSDKOptions = Partial<
Omit<RunTreeConfig, "name"> & { runName: string }
dqbd marked this conversation as resolved.
Show resolved Hide resolved
>;

/**
* Wrap an arbitrary SDK, enabling automatic LangSmith tracing.
* Method signatures are unchanged.
Expand All @@ -325,9 +329,14 @@ const _wrapClient = <T extends object>(
*/
export const wrapSDK = <T extends object>(
sdk: T,
options?: { client?: Client; runName?: string }
options?: WrapSDKOptions
): T => {
return _wrapClient(sdk, options?.runName ?? sdk.constructor?.name, {
client: options?.client,
});
const traceableOptions = options ? { ...options } : undefined;
if (traceableOptions != null) delete traceableOptions.runName;
dqbd marked this conversation as resolved.
Show resolved Hide resolved

return _wrapClient(
sdk,
options?.runName ?? sdk.constructor?.name,
traceableOptions
);
};
Loading