langsmith 0.1.27 → 0.1.28

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.
@@ -226,6 +226,7 @@ class _ExperimentManager {
226
226
  metadata: projectMetadata,
227
227
  description: this._description,
228
228
  });
229
+ this._experiment = project;
229
230
  }
230
231
  catch (e) {
231
232
  if (String(e).includes("already exists")) {
@@ -222,6 +222,7 @@ class _ExperimentManager {
222
222
  metadata: projectMetadata,
223
223
  description: this._description,
224
224
  });
225
+ this._experiment = project;
225
226
  }
226
227
  catch (e) {
227
228
  if (String(e).includes("already exists")) {
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLangchainStringEvaluator = void 0;
4
+ const evaluation_1 = require("langchain/evaluation");
5
+ const langchain_js_1 = require("../langchain.cjs");
6
+ function isStringifiable(value) {
7
+ return (typeof value === "string" ||
8
+ typeof value === "number" ||
9
+ typeof value === "boolean" ||
10
+ typeof value === "bigint");
11
+ }
12
+ // utility methods for extracting stringified values
13
+ // from unknown inputs and records
14
+ function getPrimitiveValue(value) {
15
+ if (isStringifiable(value))
16
+ return String(value);
17
+ if (!Array.isArray(value) && typeof value === "object" && value != null) {
18
+ const values = Object.values(value);
19
+ if (values.length === 1 && isStringifiable(values[0])) {
20
+ return String(values[0]);
21
+ }
22
+ }
23
+ return undefined;
24
+ }
25
+ /**
26
+ * This utility function loads a LangChain string evaluator and returns a function
27
+ * which can be used by newer `evaluate` function.
28
+ *
29
+ * @param type Type of string evaluator, one of "criteria" or "labeled_criteria
30
+ * @param options Options for loading the evaluator
31
+ * @returns Evaluator consumable by `evaluate`
32
+ */
33
+ async function getLangchainStringEvaluator(type, options) {
34
+ const evaluator = await (0, evaluation_1.loadEvaluator)(type, options);
35
+ const feedbackKey = getPrimitiveValue(options.criteria) ?? type;
36
+ const formatEvaluatorInputs = options.formatEvaluatorInputs ??
37
+ ((run, example) => {
38
+ const prediction = getPrimitiveValue(run.outputs);
39
+ const reference = getPrimitiveValue(example.outputs);
40
+ const input = getPrimitiveValue(example.inputs);
41
+ if (prediction == null)
42
+ throw new Error("Missing prediction");
43
+ if (type === "criteria")
44
+ return { prediction, input };
45
+ return { prediction, reference, input };
46
+ });
47
+ return async (run, example) => {
48
+ const score = await evaluator.evaluateStrings(formatEvaluatorInputs(run, example), { callbacks: await (0, langchain_js_1.getLangchainCallbacks)() });
49
+ return { key: feedbackKey, ...score };
50
+ };
51
+ }
52
+ exports.getLangchainStringEvaluator = getLangchainStringEvaluator;
@@ -0,0 +1,19 @@
1
+ import type { Run, Example } from "../schemas.js";
2
+ import { type LoadEvaluatorOptions } from "langchain/evaluation";
3
+ /**
4
+ * This utility function loads a LangChain string evaluator and returns a function
5
+ * which can be used by newer `evaluate` function.
6
+ *
7
+ * @param type Type of string evaluator, one of "criteria" or "labeled_criteria
8
+ * @param options Options for loading the evaluator
9
+ * @returns Evaluator consumable by `evaluate`
10
+ */
11
+ export declare function getLangchainStringEvaluator(type: "criteria" | "labeled_criteria", options: LoadEvaluatorOptions & {
12
+ formatEvaluatorInputs?: (run: Run, example: Example) => {
13
+ prediction: string;
14
+ reference?: string;
15
+ input?: string;
16
+ };
17
+ }): Promise<(run: Run, example: Example) => Promise<{
18
+ key: string;
19
+ }>>;
@@ -0,0 +1,48 @@
1
+ import { loadEvaluator } from "langchain/evaluation";
2
+ import { getLangchainCallbacks } from "../langchain.js";
3
+ function isStringifiable(value) {
4
+ return (typeof value === "string" ||
5
+ typeof value === "number" ||
6
+ typeof value === "boolean" ||
7
+ typeof value === "bigint");
8
+ }
9
+ // utility methods for extracting stringified values
10
+ // from unknown inputs and records
11
+ function getPrimitiveValue(value) {
12
+ if (isStringifiable(value))
13
+ return String(value);
14
+ if (!Array.isArray(value) && typeof value === "object" && value != null) {
15
+ const values = Object.values(value);
16
+ if (values.length === 1 && isStringifiable(values[0])) {
17
+ return String(values[0]);
18
+ }
19
+ }
20
+ return undefined;
21
+ }
22
+ /**
23
+ * This utility function loads a LangChain string evaluator and returns a function
24
+ * which can be used by newer `evaluate` function.
25
+ *
26
+ * @param type Type of string evaluator, one of "criteria" or "labeled_criteria
27
+ * @param options Options for loading the evaluator
28
+ * @returns Evaluator consumable by `evaluate`
29
+ */
30
+ export async function getLangchainStringEvaluator(type, options) {
31
+ const evaluator = await loadEvaluator(type, options);
32
+ const feedbackKey = getPrimitiveValue(options.criteria) ?? type;
33
+ const formatEvaluatorInputs = options.formatEvaluatorInputs ??
34
+ ((run, example) => {
35
+ const prediction = getPrimitiveValue(run.outputs);
36
+ const reference = getPrimitiveValue(example.outputs);
37
+ const input = getPrimitiveValue(example.inputs);
38
+ if (prediction == null)
39
+ throw new Error("Missing prediction");
40
+ if (type === "criteria")
41
+ return { prediction, input };
42
+ return { prediction, reference, input };
43
+ });
44
+ return async (run, example) => {
45
+ const score = await evaluator.evaluateStrings(formatEvaluatorInputs(run, example), { callbacks: await getLangchainCallbacks() });
46
+ return { key: feedbackKey, ...score };
47
+ };
48
+ }
package/dist/index.cjs CHANGED
@@ -6,4 +6,4 @@ Object.defineProperty(exports, "Client", { enumerable: true, get: function () {
6
6
  var run_trees_js_1 = require("./run_trees.cjs");
7
7
  Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () { return run_trees_js_1.RunTree; } });
8
8
  // Update using yarn bump-version
9
- exports.__version__ = "0.1.27";
9
+ exports.__version__ = "0.1.28";
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Client } from "./client.js";
2
2
  export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
- export declare const __version__ = "0.1.27";
4
+ export declare const __version__ = "0.1.28";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Client } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  // Update using yarn bump-version
4
- export const __version__ = "0.1.27";
4
+ export const __version__ = "0.1.28";
@@ -5,6 +5,7 @@ const manager_1 = require("@langchain/core/callbacks/manager");
5
5
  const tracer_langchain_1 = require("@langchain/core/tracers/tracer_langchain");
6
6
  const runnables_1 = require("@langchain/core/runnables");
7
7
  const traceable_js_1 = require("./traceable.cjs");
8
+ const asserts_js_1 = require("./utils/asserts.cjs");
8
9
  /**
9
10
  * Converts the current run tree active within a traceable-wrapped function
10
11
  * into a LangChain compatible callback manager. This is useful to handoff tracing
@@ -96,7 +97,27 @@ class RunnableTraceable extends runnables_1.Runnable {
96
97
  }
97
98
  async invoke(input, options) {
98
99
  const [config] = this._getOptionsList(options ?? {}, 1);
99
- return (await this.func(config, input));
100
+ const callbacks = await (0, runnables_1.getCallbackManagerForConfig)(config);
101
+ return (await this.func((0, runnables_1.patchConfig)(config, { callbacks }), input));
102
+ }
103
+ async *_streamIterator(input, options) {
104
+ const result = await this.invoke(input, options);
105
+ if ((0, asserts_js_1.isAsyncIterable)(result)) {
106
+ for await (const item of result) {
107
+ yield item;
108
+ }
109
+ return;
110
+ }
111
+ if ((0, asserts_js_1.isIteratorLike)(result)) {
112
+ while (true) {
113
+ const state = result.next();
114
+ if (state.done)
115
+ break;
116
+ yield state.value;
117
+ }
118
+ return;
119
+ }
120
+ yield result;
100
121
  }
101
122
  static from(func) {
102
123
  return new RunnableTraceable({ func });
@@ -24,6 +24,7 @@ export declare class RunnableTraceable<RunInput, RunOutput> extends Runnable<Run
24
24
  func: AnyTraceableFunction;
25
25
  });
26
26
  invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
27
+ _streamIterator(input: RunInput, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
27
28
  static from(func: AnyTraceableFunction): RunnableTraceable<unknown, unknown>;
28
29
  }
29
30
  export {};
package/dist/langchain.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import { CallbackManager } from "@langchain/core/callbacks/manager";
2
2
  import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
3
- import { Runnable } from "@langchain/core/runnables";
3
+ import { Runnable, patchConfig, getCallbackManagerForConfig, } from "@langchain/core/runnables";
4
4
  import { getCurrentRunTree, isTraceableFunction, } from "./traceable.js";
5
+ import { isAsyncIterable, isIteratorLike } from "./utils/asserts.js";
5
6
  /**
6
7
  * Converts the current run tree active within a traceable-wrapped function
7
8
  * into a LangChain compatible callback manager. This is useful to handoff tracing
@@ -92,7 +93,27 @@ export class RunnableTraceable extends Runnable {
92
93
  }
93
94
  async invoke(input, options) {
94
95
  const [config] = this._getOptionsList(options ?? {}, 1);
95
- return (await this.func(config, input));
96
+ const callbacks = await getCallbackManagerForConfig(config);
97
+ return (await this.func(patchConfig(config, { callbacks }), input));
98
+ }
99
+ async *_streamIterator(input, options) {
100
+ const result = await this.invoke(input, options);
101
+ if (isAsyncIterable(result)) {
102
+ for await (const item of result) {
103
+ yield item;
104
+ }
105
+ return;
106
+ }
107
+ if (isIteratorLike(result)) {
108
+ while (true) {
109
+ const state = result.next();
110
+ if (state.done)
111
+ break;
112
+ yield state.value;
113
+ }
114
+ return;
115
+ }
116
+ yield result;
96
117
  }
97
118
  static from(func) {
98
119
  return new RunnableTraceable({ func });
@@ -28,13 +28,7 @@ const uuid = __importStar(require("uuid"));
28
28
  const env_js_1 = require("./utils/env.cjs");
29
29
  const client_js_1 = require("./client.cjs");
30
30
  const env_js_2 = require("./env.cjs");
31
- const warnedMessages = {};
32
- function warnOnce(message) {
33
- if (!warnedMessages[message]) {
34
- console.warn(message);
35
- warnedMessages[message] = true;
36
- }
37
- }
31
+ const warn_js_1 = require("./utils/warn.cjs");
38
32
  function stripNonAlphanumeric(input) {
39
33
  return input.replace(/[-:.]/g, "");
40
34
  }
@@ -224,9 +218,19 @@ class RunTree {
224
218
  client = langChainTracer?.client;
225
219
  tracingEnabled = tracingEnabled || !!langChainTracer;
226
220
  }
221
+ if (!parentRun) {
222
+ return new RunTree({
223
+ client,
224
+ tracingEnabled,
225
+ project_name: projectName,
226
+ name: props.name,
227
+ tags: props.tags,
228
+ metadata: props.metadata,
229
+ });
230
+ }
227
231
  const parentRunTree = new RunTree({
228
- name: parentRun?.name ?? "<parent>",
229
- id: parentRun?.id,
232
+ name: parentRun.name,
233
+ id: parentRun.id,
230
234
  client,
231
235
  tracingEnabled,
232
236
  project_name: projectName,
@@ -241,7 +245,7 @@ class RunTree {
241
245
  },
242
246
  });
243
247
  return parentRunTree.createChild({
244
- name: props?.name ?? "<lambda>",
248
+ name: props.name,
245
249
  tags: props.tags,
246
250
  metadata: props.metadata,
247
251
  });
@@ -338,7 +342,7 @@ class RunTree {
338
342
  const runCreate = await this._convertToCreate(this, runtimeEnv, true);
339
343
  await this.client.createRun(runCreate);
340
344
  if (!excludeChildRuns) {
341
- warnOnce("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
345
+ (0, warn_js_1.warnOnce)("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
342
346
  for (const childRun of this.child_runs) {
343
347
  await childRun.postRun(false);
344
348
  }
package/dist/run_trees.js CHANGED
@@ -2,13 +2,7 @@ import * as uuid from "uuid";
2
2
  import { getEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
3
3
  import { Client } from "./client.js";
4
4
  import { isTracingEnabled } from "./env.js";
5
- const warnedMessages = {};
6
- function warnOnce(message) {
7
- if (!warnedMessages[message]) {
8
- console.warn(message);
9
- warnedMessages[message] = true;
10
- }
11
- }
5
+ import { warnOnce } from "./utils/warn.js";
12
6
  function stripNonAlphanumeric(input) {
13
7
  return input.replace(/[-:.]/g, "");
14
8
  }
@@ -197,9 +191,19 @@ export class RunTree {
197
191
  client = langChainTracer?.client;
198
192
  tracingEnabled = tracingEnabled || !!langChainTracer;
199
193
  }
194
+ if (!parentRun) {
195
+ return new RunTree({
196
+ client,
197
+ tracingEnabled,
198
+ project_name: projectName,
199
+ name: props.name,
200
+ tags: props.tags,
201
+ metadata: props.metadata,
202
+ });
203
+ }
200
204
  const parentRunTree = new RunTree({
201
- name: parentRun?.name ?? "<parent>",
202
- id: parentRun?.id,
205
+ name: parentRun.name,
206
+ id: parentRun.id,
203
207
  client,
204
208
  tracingEnabled,
205
209
  project_name: projectName,
@@ -214,7 +218,7 @@ export class RunTree {
214
218
  },
215
219
  });
216
220
  return parentRunTree.createChild({
217
- name: props?.name ?? "<lambda>",
221
+ name: props.name,
218
222
  tags: props.tags,
219
223
  metadata: props.metadata,
220
224
  });
package/dist/schemas.d.ts CHANGED
@@ -308,7 +308,7 @@ export type RetrieverOutput = Array<{
308
308
  export interface InvocationParamsSchema {
309
309
  ls_provider?: string;
310
310
  ls_model_name?: string;
311
- ls_model_type: "chat";
311
+ ls_model_type: "chat" | "text";
312
312
  ls_temperature?: number;
313
313
  ls_max_tokens?: number;
314
314
  ls_stop?: string[];
@@ -20,4 +20,4 @@ export declare const AsyncLocalStorageProviderSingleton: AsyncLocalStorageProvid
20
20
  export declare const getCurrentRunTree: () => RunTree;
21
21
  export declare const ROOT: unique symbol;
22
22
  export declare function isTraceableFunction(x: unknown): x is TraceableFunction<any>;
23
- export {};
23
+ export type { TraceableFunction } from "./types.js";
@@ -5,44 +5,8 @@ const node_async_hooks_1 = require("node:async_hooks");
5
5
  const run_trees_js_1 = require("./run_trees.cjs");
6
6
  const env_js_1 = require("./env.cjs");
7
7
  const traceable_js_1 = require("./singletons/traceable.cjs");
8
+ const asserts_js_1 = require("./utils/asserts.cjs");
8
9
  traceable_js_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new node_async_hooks_1.AsyncLocalStorage());
9
- function isPromiseMethod(x) {
10
- if (x === "then" || x === "catch" || x === "finally") {
11
- return true;
12
- }
13
- return false;
14
- }
15
- function isKVMap(x) {
16
- if (typeof x !== "object" || x == null) {
17
- return false;
18
- }
19
- const prototype = Object.getPrototypeOf(x);
20
- return ((prototype === null ||
21
- prototype === Object.prototype ||
22
- Object.getPrototypeOf(prototype) === null) &&
23
- !(Symbol.toStringTag in x) &&
24
- !(Symbol.iterator in x));
25
- }
26
- const isAsyncIterable = (x) => x != null &&
27
- typeof x === "object" &&
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- typeof x[Symbol.asyncIterator] === "function";
30
- const isIteratorLike = (x) => x != null &&
31
- typeof x === "object" &&
32
- "next" in x &&
33
- typeof x.next === "function";
34
- const GeneratorFunction = function* () { }.constructor;
35
- const isGenerator = (x) =>
36
- // eslint-disable-next-line no-instanceof/no-instanceof
37
- x != null && typeof x === "function" && x instanceof GeneratorFunction;
38
- const isThenable = (x) => x != null &&
39
- typeof x === "object" &&
40
- "then" in x &&
41
- typeof x.then === "function";
42
- const isReadableStream = (x) => x != null &&
43
- typeof x === "object" &&
44
- "getReader" in x &&
45
- typeof x.getReader === "function";
46
10
  const handleRunInputs = (rawInputs) => {
47
11
  const firstInput = rawInputs[0];
48
12
  if (firstInput == null) {
@@ -51,13 +15,13 @@ const handleRunInputs = (rawInputs) => {
51
15
  if (rawInputs.length > 1) {
52
16
  return { args: rawInputs };
53
17
  }
54
- if (isKVMap(firstInput)) {
18
+ if ((0, asserts_js_1.isKVMap)(firstInput)) {
55
19
  return firstInput;
56
20
  }
57
21
  return { input: firstInput };
58
22
  };
59
23
  const handleRunOutputs = (rawOutputs) => {
60
- if (isKVMap(rawOutputs)) {
24
+ if ((0, asserts_js_1.isKVMap)(rawOutputs)) {
61
25
  return rawOutputs;
62
26
  }
63
27
  return { outputs: rawOutputs };
@@ -122,7 +86,7 @@ const getSerializablePromise = (arg) => {
122
86
  return promiseProxy;
123
87
  };
124
88
  const convertSerializableArg = (arg) => {
125
- if (isReadableStream(arg)) {
89
+ if ((0, asserts_js_1.isReadableStream)(arg)) {
126
90
  const proxyState = [];
127
91
  const transform = new TransformStream({
128
92
  start: () => void 0,
@@ -136,7 +100,7 @@ const convertSerializableArg = (arg) => {
136
100
  Object.assign(pipeThrough, { toJSON: () => proxyState });
137
101
  return pipeThrough;
138
102
  }
139
- if (isAsyncIterable(arg)) {
103
+ if ((0, asserts_js_1.isAsyncIterable)(arg)) {
140
104
  const proxyState = { current: [] };
141
105
  return new Proxy(arg, {
142
106
  get(target, prop, receiver) {
@@ -179,7 +143,7 @@ const convertSerializableArg = (arg) => {
179
143
  },
180
144
  });
181
145
  }
182
- if (!Array.isArray(arg) && isIteratorLike(arg)) {
146
+ if (!Array.isArray(arg) && (0, asserts_js_1.isIteratorLike)(arg)) {
183
147
  const proxyState = [];
184
148
  return new Proxy(arg, {
185
149
  get(target, prop, receiver) {
@@ -207,7 +171,7 @@ const convertSerializableArg = (arg) => {
207
171
  },
208
172
  });
209
173
  }
210
- if (isThenable(arg)) {
174
+ if ((0, asserts_js_1.isThenable)(arg)) {
211
175
  return getSerializablePromise(arg);
212
176
  }
213
177
  return arg;
@@ -389,18 +353,18 @@ function traceable(wrappedFunc, config) {
389
353
  catch (err) {
390
354
  returnValue = Promise.reject(err);
391
355
  }
392
- if (isAsyncIterable(returnValue)) {
356
+ if ((0, asserts_js_1.isAsyncIterable)(returnValue)) {
393
357
  const snapshot = node_async_hooks_1.AsyncLocalStorage.snapshot();
394
358
  return wrapAsyncGeneratorForTracing(returnValue, snapshot);
395
359
  }
396
360
  const tracedPromise = new Promise((resolve, reject) => {
397
361
  Promise.resolve(returnValue)
398
362
  .then(async (rawOutput) => {
399
- if (isAsyncIterable(rawOutput)) {
363
+ if ((0, asserts_js_1.isAsyncIterable)(rawOutput)) {
400
364
  const snapshot = node_async_hooks_1.AsyncLocalStorage.snapshot();
401
365
  return resolve(wrapAsyncGeneratorForTracing(rawOutput, snapshot));
402
366
  }
403
- if (isGenerator(wrappedFunc) && isIteratorLike(rawOutput)) {
367
+ if ((0, asserts_js_1.isGenerator)(wrappedFunc) && (0, asserts_js_1.isIteratorLike)(rawOutput)) {
404
368
  const chunks = gatherAll(rawOutput);
405
369
  await currentRunTree?.end(handleRunOutputs(await handleChunks(chunks.reduce((memo, { value, done }) => {
406
370
  if (!done || typeof value !== "undefined") {
@@ -437,7 +401,7 @@ function traceable(wrappedFunc, config) {
437
401
  }
438
402
  return new Proxy(returnValue, {
439
403
  get(target, prop, receiver) {
440
- if (isPromiseMethod(prop)) {
404
+ if ((0, asserts_js_1.isPromiseMethod)(prop)) {
441
405
  return tracedPromise[prop].bind(tracedPromise);
442
406
  }
443
407
  return Reflect.get(target, prop, receiver);
package/dist/traceable.js CHANGED
@@ -2,44 +2,8 @@ import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { RunTree, isRunTree, isRunnableConfigLike, } from "./run_trees.js";
3
3
  import { isTracingEnabled } from "./env.js";
4
4
  import { ROOT, AsyncLocalStorageProviderSingleton, } from "./singletons/traceable.js";
5
+ import { isKVMap, isReadableStream, isAsyncIterable, isIteratorLike, isThenable, isGenerator, isPromiseMethod, } from "./utils/asserts.js";
5
6
  AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new AsyncLocalStorage());
6
- function isPromiseMethod(x) {
7
- if (x === "then" || x === "catch" || x === "finally") {
8
- return true;
9
- }
10
- return false;
11
- }
12
- function isKVMap(x) {
13
- if (typeof x !== "object" || x == null) {
14
- return false;
15
- }
16
- const prototype = Object.getPrototypeOf(x);
17
- return ((prototype === null ||
18
- prototype === Object.prototype ||
19
- Object.getPrototypeOf(prototype) === null) &&
20
- !(Symbol.toStringTag in x) &&
21
- !(Symbol.iterator in x));
22
- }
23
- const isAsyncIterable = (x) => x != null &&
24
- typeof x === "object" &&
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
- typeof x[Symbol.asyncIterator] === "function";
27
- const isIteratorLike = (x) => x != null &&
28
- typeof x === "object" &&
29
- "next" in x &&
30
- typeof x.next === "function";
31
- const GeneratorFunction = function* () { }.constructor;
32
- const isGenerator = (x) =>
33
- // eslint-disable-next-line no-instanceof/no-instanceof
34
- x != null && typeof x === "function" && x instanceof GeneratorFunction;
35
- const isThenable = (x) => x != null &&
36
- typeof x === "object" &&
37
- "then" in x &&
38
- typeof x.then === "function";
39
- const isReadableStream = (x) => x != null &&
40
- typeof x === "object" &&
41
- "getReader" in x &&
42
- typeof x.getReader === "function";
43
7
  const handleRunInputs = (rawInputs) => {
44
8
  const firstInput = rawInputs[0];
45
9
  if (firstInput == null) {
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isReadableStream = exports.isThenable = exports.isGenerator = exports.isIteratorLike = exports.isAsyncIterable = exports.isKVMap = exports.isPromiseMethod = void 0;
4
+ function isPromiseMethod(x) {
5
+ if (x === "then" || x === "catch" || x === "finally") {
6
+ return true;
7
+ }
8
+ return false;
9
+ }
10
+ exports.isPromiseMethod = isPromiseMethod;
11
+ function isKVMap(x) {
12
+ if (typeof x !== "object" || x == null) {
13
+ return false;
14
+ }
15
+ const prototype = Object.getPrototypeOf(x);
16
+ return ((prototype === null ||
17
+ prototype === Object.prototype ||
18
+ Object.getPrototypeOf(prototype) === null) &&
19
+ !(Symbol.toStringTag in x) &&
20
+ !(Symbol.iterator in x));
21
+ }
22
+ exports.isKVMap = isKVMap;
23
+ const isAsyncIterable = (x) => x != null &&
24
+ typeof x === "object" &&
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ typeof x[Symbol.asyncIterator] === "function";
27
+ exports.isAsyncIterable = isAsyncIterable;
28
+ const isIteratorLike = (x) => x != null &&
29
+ typeof x === "object" &&
30
+ "next" in x &&
31
+ typeof x.next === "function";
32
+ exports.isIteratorLike = isIteratorLike;
33
+ const GeneratorFunction = function* () { }.constructor;
34
+ const isGenerator = (x) =>
35
+ // eslint-disable-next-line no-instanceof/no-instanceof
36
+ x != null && typeof x === "function" && x instanceof GeneratorFunction;
37
+ exports.isGenerator = isGenerator;
38
+ const isThenable = (x) => x != null &&
39
+ typeof x === "object" &&
40
+ "then" in x &&
41
+ typeof x.then === "function";
42
+ exports.isThenable = isThenable;
43
+ const isReadableStream = (x) => x != null &&
44
+ typeof x === "object" &&
45
+ "getReader" in x &&
46
+ typeof x.getReader === "function";
47
+ exports.isReadableStream = isReadableStream;
@@ -0,0 +1,7 @@
1
+ export declare function isPromiseMethod(x: string | symbol): x is "then" | "catch" | "finally";
2
+ export declare function isKVMap(x: unknown): x is Record<string, unknown>;
3
+ export declare const isAsyncIterable: (x: unknown) => x is AsyncIterable<unknown>;
4
+ export declare const isIteratorLike: (x: unknown) => x is Iterator<unknown, any, undefined>;
5
+ export declare const isGenerator: (x: unknown) => x is Generator<unknown, any, unknown>;
6
+ export declare const isThenable: (x: unknown) => x is Promise<unknown>;
7
+ export declare const isReadableStream: (x: unknown) => x is ReadableStream<any>;
@@ -0,0 +1,37 @@
1
+ export function isPromiseMethod(x) {
2
+ if (x === "then" || x === "catch" || x === "finally") {
3
+ return true;
4
+ }
5
+ return false;
6
+ }
7
+ export function isKVMap(x) {
8
+ if (typeof x !== "object" || x == null) {
9
+ return false;
10
+ }
11
+ const prototype = Object.getPrototypeOf(x);
12
+ return ((prototype === null ||
13
+ prototype === Object.prototype ||
14
+ Object.getPrototypeOf(prototype) === null) &&
15
+ !(Symbol.toStringTag in x) &&
16
+ !(Symbol.iterator in x));
17
+ }
18
+ export const isAsyncIterable = (x) => x != null &&
19
+ typeof x === "object" &&
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ typeof x[Symbol.asyncIterator] === "function";
22
+ export const isIteratorLike = (x) => x != null &&
23
+ typeof x === "object" &&
24
+ "next" in x &&
25
+ typeof x.next === "function";
26
+ const GeneratorFunction = function* () { }.constructor;
27
+ export const isGenerator = (x) =>
28
+ // eslint-disable-next-line no-instanceof/no-instanceof
29
+ x != null && typeof x === "function" && x instanceof GeneratorFunction;
30
+ export const isThenable = (x) => x != null &&
31
+ typeof x === "object" &&
32
+ "then" in x &&
33
+ typeof x.then === "function";
34
+ export const isReadableStream = (x) => x != null &&
35
+ typeof x === "object" &&
36
+ "getReader" in x &&
37
+ typeof x.getReader === "function";
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.warnOnce = void 0;
4
+ const warnedMessages = {};
5
+ function warnOnce(message) {
6
+ if (!warnedMessages[message]) {
7
+ console.warn(message);
8
+ warnedMessages[message] = true;
9
+ }
10
+ }
11
+ exports.warnOnce = warnOnce;
@@ -0,0 +1 @@
1
+ export declare function warnOnce(message: string): void;
@@ -0,0 +1,7 @@
1
+ const warnedMessages = {};
2
+ export function warnOnce(message) {
3
+ if (!warnedMessages[message]) {
4
+ console.warn(message);
5
+ warnedMessages[message] = true;
6
+ }
7
+ }
@@ -179,7 +179,7 @@ const wrapOpenAI = (openai, options) => {
179
179
  undefined;
180
180
  return {
181
181
  ls_provider: "openai",
182
- ls_model_type: "chat",
182
+ ls_model_type: "text",
183
183
  ls_model_name: params.model,
184
184
  ls_max_tokens: params.max_tokens ?? undefined,
185
185
  ls_temperature: params.temperature ?? undefined,
@@ -176,7 +176,7 @@ export const wrapOpenAI = (openai, options) => {
176
176
  undefined;
177
177
  return {
178
178
  ls_provider: "openai",
179
- ls_model_type: "chat",
179
+ ls_model_type: "text",
180
180
  ls_model_name: params.model,
181
181
  ls_max_tokens: params.max_tokens ?? undefined,
182
182
  ls_temperature: params.temperature ?? undefined,
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/evaluation/langchain.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/evaluation/langchain.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/evaluation/langchain.js'
@@ -0,0 +1 @@
1
+ export * from '../dist/evaluation/langchain.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [
@@ -21,6 +21,10 @@
21
21
  "evaluation.js",
22
22
  "evaluation.d.ts",
23
23
  "evaluation.d.cts",
24
+ "evaluation/langchain.cjs",
25
+ "evaluation/langchain.js",
26
+ "evaluation/langchain.d.ts",
27
+ "evaluation/langchain.d.cts",
24
28
  "schemas.cjs",
25
29
  "schemas.js",
26
30
  "schemas.d.ts",
@@ -95,8 +99,9 @@
95
99
  "@babel/preset-env": "^7.22.4",
96
100
  "@faker-js/faker": "^8.4.1",
97
101
  "@jest/globals": "^29.5.0",
98
- "@langchain/core": "^0.1.32",
99
- "@langchain/langgraph": "^0.0.8",
102
+ "langchain": "^0.2.0",
103
+ "@langchain/core": "^0.2.0",
104
+ "@langchain/langgraph": "^0.0.19",
100
105
  "@tsconfig/recommended": "^1.0.2",
101
106
  "@types/jest": "^29.5.1",
102
107
  "@typescript-eslint/eslint-plugin": "^5.59.8",
@@ -118,16 +123,23 @@
118
123
  },
119
124
  "peerDependencies": {
120
125
  "openai": "*",
126
+ "langchain": "*",
121
127
  "@langchain/core": "*"
122
128
  },
123
129
  "peerDependenciesMeta": {
124
130
  "openai": {
125
131
  "optional": true
126
132
  },
133
+ "langchain": {
134
+ "optional": true
135
+ },
127
136
  "@langchain/core": {
128
137
  "optional": true
129
138
  }
130
139
  },
140
+ "resolutions": {
141
+ "@langchain/core": "0.2.0"
142
+ },
131
143
  "lint-staged": {
132
144
  "**/*.{ts,tsx}": [
133
145
  "prettier --write --ignore-unknown",
@@ -180,6 +192,15 @@
180
192
  "import": "./evaluation.js",
181
193
  "require": "./evaluation.cjs"
182
194
  },
195
+ "./evaluation/langchain": {
196
+ "types": {
197
+ "import": "./evaluation/langchain.d.ts",
198
+ "require": "./evaluation/langchain.d.cts",
199
+ "default": "./evaluation/langchain.d.ts"
200
+ },
201
+ "import": "./evaluation/langchain.js",
202
+ "require": "./evaluation/langchain.cjs"
203
+ },
183
204
  "./schemas": {
184
205
  "types": {
185
206
  "import": "./schemas.d.ts",
@@ -227,4 +248,4 @@
227
248
  },
228
249
  "./package.json": "./package.json"
229
250
  }
230
- }
251
+ }