langsmith 0.1.14 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/wrappers/openai.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/wrappers/openai.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/wrappers/openai.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/wrappers/openai.js'
package/wrappers.cjs CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist/wrappers.cjs');
1
+ module.exports = require('./dist/wrappers/index.cjs');
package/wrappers.d.cts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/wrappers/index.js'
package/wrappers.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/wrappers.js'
1
+ export * from './dist/wrappers/index.js'
package/wrappers.js CHANGED
@@ -1 +1 @@
1
- export * from './dist/wrappers.js'
1
+ export * from './dist/wrappers/index.js'
package/dist/wrappers.cjs DELETED
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapSDK = exports.wrapOpenAI = void 0;
4
- const traceable_js_1 = require("./traceable.cjs");
5
- /**
6
- * Wraps an OpenAI client's completion methods, enabling automatic LangSmith
7
- * tracing. Method signatures are unchanged.
8
- * @param openai An OpenAI client instance.
9
- * @param options LangSmith options.
10
- * @returns
11
- */
12
- const wrapOpenAI = (openai, options) => {
13
- openai.chat.completions.create = (0, traceable_js_1.traceable)(openai.chat.completions.create.bind(openai.chat.completions), Object.assign({ name: "ChatOpenAI", run_type: "llm" }, options?.client));
14
- openai.completions.create = (0, traceable_js_1.traceable)(openai.completions.create.bind(openai.completions), Object.assign({ name: "OpenAI", run_type: "llm" }, options?.client));
15
- return openai;
16
- };
17
- exports.wrapOpenAI = wrapOpenAI;
18
- const _wrapClient = (sdk, runName, options) => {
19
- return new Proxy(sdk, {
20
- get(target, propKey, receiver) {
21
- const originalValue = target[propKey];
22
- if (typeof originalValue === "function") {
23
- return (0, traceable_js_1.traceable)(originalValue.bind(target), Object.assign({ name: [runName, propKey.toString()].join("."), run_type: "llm" }, options?.client));
24
- }
25
- else if (originalValue != null &&
26
- !Array.isArray(originalValue) &&
27
- // eslint-disable-next-line no-instanceof/no-instanceof
28
- !(originalValue instanceof Date) &&
29
- typeof originalValue === "object") {
30
- return _wrapClient(originalValue, [runName, propKey.toString()].join("."), options);
31
- }
32
- else {
33
- return Reflect.get(target, propKey, receiver);
34
- }
35
- },
36
- });
37
- };
38
- /**
39
- * Wrap an arbitrary SDK, enabling automatic LangSmith tracing.
40
- * Method signatures are unchanged.
41
- *
42
- * Note that this will wrap and trace ALL SDK methods, not just
43
- * LLM completion methods. If the passed SDK contains other methods,
44
- * we recommend using the wrapped instance for LLM calls only.
45
- * @param sdk An arbitrary SDK instance.
46
- * @param options LangSmith options.
47
- * @returns
48
- */
49
- const wrapSDK = (sdk, options) => {
50
- return _wrapClient(sdk, options?.runName ?? sdk.constructor?.name, {
51
- client: options?.client,
52
- });
53
- };
54
- exports.wrapSDK = wrapSDK;
@@ -1,37 +0,0 @@
1
- import type { Client } from "./index.js";
2
- type OpenAIType = {
3
- chat: {
4
- completions: {
5
- create: (...args: any[]) => any;
6
- };
7
- };
8
- completions: {
9
- create: (...args: any[]) => any;
10
- };
11
- };
12
- /**
13
- * Wraps an OpenAI client's completion methods, enabling automatic LangSmith
14
- * tracing. Method signatures are unchanged.
15
- * @param openai An OpenAI client instance.
16
- * @param options LangSmith options.
17
- * @returns
18
- */
19
- export declare const wrapOpenAI: <T extends OpenAIType>(openai: T, options?: {
20
- client?: Client;
21
- }) => T;
22
- /**
23
- * Wrap an arbitrary SDK, enabling automatic LangSmith tracing.
24
- * Method signatures are unchanged.
25
- *
26
- * Note that this will wrap and trace ALL SDK methods, not just
27
- * LLM completion methods. If the passed SDK contains other methods,
28
- * we recommend using the wrapped instance for LLM calls only.
29
- * @param sdk An arbitrary SDK instance.
30
- * @param options LangSmith options.
31
- * @returns
32
- */
33
- export declare const wrapSDK: <T extends object>(sdk: T, options?: {
34
- client?: Client;
35
- runName?: string;
36
- }) => T;
37
- export {};
package/dist/wrappers.js DELETED
@@ -1,49 +0,0 @@
1
- import { traceable } from "./traceable.js";
2
- /**
3
- * Wraps an OpenAI client's completion methods, enabling automatic LangSmith
4
- * tracing. Method signatures are unchanged.
5
- * @param openai An OpenAI client instance.
6
- * @param options LangSmith options.
7
- * @returns
8
- */
9
- export const wrapOpenAI = (openai, options) => {
10
- openai.chat.completions.create = traceable(openai.chat.completions.create.bind(openai.chat.completions), Object.assign({ name: "ChatOpenAI", run_type: "llm" }, options?.client));
11
- openai.completions.create = traceable(openai.completions.create.bind(openai.completions), Object.assign({ name: "OpenAI", run_type: "llm" }, options?.client));
12
- return openai;
13
- };
14
- const _wrapClient = (sdk, runName, options) => {
15
- return new Proxy(sdk, {
16
- get(target, propKey, receiver) {
17
- const originalValue = target[propKey];
18
- if (typeof originalValue === "function") {
19
- return traceable(originalValue.bind(target), Object.assign({ name: [runName, propKey.toString()].join("."), run_type: "llm" }, options?.client));
20
- }
21
- else if (originalValue != null &&
22
- !Array.isArray(originalValue) &&
23
- // eslint-disable-next-line no-instanceof/no-instanceof
24
- !(originalValue instanceof Date) &&
25
- typeof originalValue === "object") {
26
- return _wrapClient(originalValue, [runName, propKey.toString()].join("."), options);
27
- }
28
- else {
29
- return Reflect.get(target, propKey, receiver);
30
- }
31
- },
32
- });
33
- };
34
- /**
35
- * Wrap an arbitrary SDK, enabling automatic LangSmith tracing.
36
- * Method signatures are unchanged.
37
- *
38
- * Note that this will wrap and trace ALL SDK methods, not just
39
- * LLM completion methods. If the passed SDK contains other methods,
40
- * we recommend using the wrapped instance for LLM calls only.
41
- * @param sdk An arbitrary SDK instance.
42
- * @param options LangSmith options.
43
- * @returns
44
- */
45
- export const wrapSDK = (sdk, options) => {
46
- return _wrapClient(sdk, options?.runName ?? sdk.constructor?.name, {
47
- client: options?.client,
48
- });
49
- };