langsmith 0.1.27 → 0.1.30

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.
@@ -48,7 +48,16 @@ class _ExperimentManager {
48
48
  for await (const example of unresolvedData) {
49
49
  exs.push(example);
50
50
  }
51
- this.setExamples(exs);
51
+ if (this._numRepetitions && this._numRepetitions > 0) {
52
+ const repeatedExamples = [];
53
+ for (let i = 0; i < this._numRepetitions; i++) {
54
+ repeatedExamples.push(...exs);
55
+ }
56
+ this.setExamples(repeatedExamples);
57
+ }
58
+ else {
59
+ this.setExamples(exs);
60
+ }
52
61
  }
53
62
  return this._examples;
54
63
  }
@@ -120,6 +129,12 @@ class _ExperimentManager {
120
129
  writable: true,
121
130
  value: void 0
122
131
  });
132
+ Object.defineProperty(this, "_numRepetitions", {
133
+ enumerable: true,
134
+ configurable: true,
135
+ writable: true,
136
+ value: void 0
137
+ });
123
138
  Object.defineProperty(this, "_runsArray", {
124
139
  enumerable: true,
125
140
  configurable: true,
@@ -188,6 +203,7 @@ class _ExperimentManager {
188
203
  this._runs = args.runs;
189
204
  this._evaluationResults = args.evaluationResults;
190
205
  this._summaryResults = args.summaryResults;
206
+ this._numRepetitions = args.numRepetitions;
191
207
  }
192
208
  _getExperiment() {
193
209
  if (!this._experiment) {
@@ -226,6 +242,7 @@ class _ExperimentManager {
226
242
  metadata: projectMetadata,
227
243
  description: this._description,
228
244
  });
245
+ this._experiment = project;
229
246
  }
230
247
  catch (e) {
231
248
  if (String(e).includes("already exists")) {
@@ -254,6 +271,7 @@ class _ExperimentManager {
254
271
  const firstExample = examples[0];
255
272
  const project = await this._getProject(firstExample);
256
273
  await this._printExperimentStart();
274
+ this._metadata["num_repetitions"] = this._numRepetitions;
257
275
  return new _ExperimentManager({
258
276
  examples,
259
277
  experiment: project,
@@ -613,6 +631,7 @@ async function _evaluate(target, fields) {
613
631
  metadata: fields.metadata,
614
632
  experiment: experiment_ ?? fields.experimentPrefix,
615
633
  runs: newRuns ?? undefined,
634
+ numRepetitions: fields.numRepetitions ?? 1,
616
635
  }).start();
617
636
  if (_isCallable(target)) {
618
637
  manager = await manager.withPredictions(convertInvokeToTopLevel(target), { maxConcurrency: fields.maxConcurrency });
@@ -23,6 +23,7 @@ interface _ExperimentManagerArgs {
23
23
  evaluationResults?: AsyncGenerator<EvaluationResults>;
24
24
  summaryResults?: AsyncGenerator<(runsArray: Run[]) => AsyncGenerator<EvaluationResults, any, unknown>, any, unknown>;
25
25
  examples?: Example[];
26
+ numRepetitions?: number;
26
27
  _runsArray?: Run[];
27
28
  }
28
29
  export interface EvaluateOptions {
@@ -65,6 +66,12 @@ export interface EvaluateOptions {
65
66
  * @default undefined
66
67
  */
67
68
  client?: Client;
69
+ /**
70
+ * The number of repetitions to perform. Each example
71
+ * will be run this many times.
72
+ * @default 1
73
+ */
74
+ numRepetitions?: number;
68
75
  }
69
76
  export declare function evaluate(
70
77
  /**
@@ -88,6 +95,7 @@ declare class _ExperimentManager {
88
95
  _evaluationResults?: AsyncGenerator<EvaluationResults>;
89
96
  _summaryResults?: AsyncGenerator<(runsArray: Run[]) => AsyncGenerator<EvaluationResults, any, unknown>, any, unknown>;
90
97
  _examples?: Example[];
98
+ _numRepetitions?: number;
91
99
  _runsArray?: Run[];
92
100
  client: Client;
93
101
  _experiment?: TracerSession;
@@ -44,7 +44,16 @@ class _ExperimentManager {
44
44
  for await (const example of unresolvedData) {
45
45
  exs.push(example);
46
46
  }
47
- this.setExamples(exs);
47
+ if (this._numRepetitions && this._numRepetitions > 0) {
48
+ const repeatedExamples = [];
49
+ for (let i = 0; i < this._numRepetitions; i++) {
50
+ repeatedExamples.push(...exs);
51
+ }
52
+ this.setExamples(repeatedExamples);
53
+ }
54
+ else {
55
+ this.setExamples(exs);
56
+ }
48
57
  }
49
58
  return this._examples;
50
59
  }
@@ -116,6 +125,12 @@ class _ExperimentManager {
116
125
  writable: true,
117
126
  value: void 0
118
127
  });
128
+ Object.defineProperty(this, "_numRepetitions", {
129
+ enumerable: true,
130
+ configurable: true,
131
+ writable: true,
132
+ value: void 0
133
+ });
119
134
  Object.defineProperty(this, "_runsArray", {
120
135
  enumerable: true,
121
136
  configurable: true,
@@ -184,6 +199,7 @@ class _ExperimentManager {
184
199
  this._runs = args.runs;
185
200
  this._evaluationResults = args.evaluationResults;
186
201
  this._summaryResults = args.summaryResults;
202
+ this._numRepetitions = args.numRepetitions;
187
203
  }
188
204
  _getExperiment() {
189
205
  if (!this._experiment) {
@@ -222,6 +238,7 @@ class _ExperimentManager {
222
238
  metadata: projectMetadata,
223
239
  description: this._description,
224
240
  });
241
+ this._experiment = project;
225
242
  }
226
243
  catch (e) {
227
244
  if (String(e).includes("already exists")) {
@@ -250,6 +267,7 @@ class _ExperimentManager {
250
267
  const firstExample = examples[0];
251
268
  const project = await this._getProject(firstExample);
252
269
  await this._printExperimentStart();
270
+ this._metadata["num_repetitions"] = this._numRepetitions;
253
271
  return new _ExperimentManager({
254
272
  examples,
255
273
  experiment: project,
@@ -609,6 +627,7 @@ async function _evaluate(target, fields) {
609
627
  metadata: fields.metadata,
610
628
  experiment: experiment_ ?? fields.experimentPrefix,
611
629
  runs: newRuns ?? undefined,
630
+ numRepetitions: fields.numRepetitions ?? 1,
612
631
  }).start();
613
632
  if (_isCallable(target)) {
614
633
  manager = await manager.withPredictions(convertInvokeToTopLevel(target), { maxConcurrency: fields.maxConcurrency });
@@ -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.30";
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.30";
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.30";
@@ -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
  }
@@ -45,6 +39,53 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
45
39
  return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`) + runId);
46
40
  }
47
41
  exports.convertToDottedOrderFormat = convertToDottedOrderFormat;
42
+ /**
43
+ * Baggage header information
44
+ */
45
+ class Baggage {
46
+ constructor(metadata, tags) {
47
+ Object.defineProperty(this, "metadata", {
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ Object.defineProperty(this, "tags", {
54
+ enumerable: true,
55
+ configurable: true,
56
+ writable: true,
57
+ value: void 0
58
+ });
59
+ this.metadata = metadata;
60
+ this.tags = tags;
61
+ }
62
+ static fromHeader(value) {
63
+ const items = value.split(",");
64
+ let metadata = {};
65
+ let tags = [];
66
+ for (const item of items) {
67
+ const [key, uriValue] = item.split("=");
68
+ const value = decodeURIComponent(uriValue);
69
+ if (key === "langsmith-metadata") {
70
+ metadata = JSON.parse(value);
71
+ }
72
+ else if (key === "langsmith-tags") {
73
+ tags = value.split(",");
74
+ }
75
+ }
76
+ return new Baggage(metadata, tags);
77
+ }
78
+ toHeader() {
79
+ const items = [];
80
+ if (this.metadata && Object.keys(this.metadata).length > 0) {
81
+ items.push(`langsmith-metadata=${encodeURIComponent(JSON.stringify(this.metadata))}`);
82
+ }
83
+ if (this.tags && this.tags.length > 0) {
84
+ items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
85
+ }
86
+ return items.join(",");
87
+ }
88
+ }
48
89
  class RunTree {
49
90
  constructor(originalConfig) {
50
91
  Object.defineProperty(this, "id", {
@@ -209,43 +250,6 @@ class RunTree {
209
250
  }
210
251
  }
211
252
  }
212
- static fromRunnableConfig(parentConfig, props) {
213
- // We only handle the callback manager case for now
214
- const callbackManager = parentConfig?.callbacks;
215
- let parentRun;
216
- let projectName;
217
- let client;
218
- let tracingEnabled = (0, env_js_2.isTracingEnabled)();
219
- if (callbackManager) {
220
- const parentRunId = callbackManager?.getParentRunId?.() ?? "";
221
- const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name == "langchain_tracer");
222
- parentRun = langChainTracer?.getRun?.(parentRunId);
223
- projectName = langChainTracer?.projectName;
224
- client = langChainTracer?.client;
225
- tracingEnabled = tracingEnabled || !!langChainTracer;
226
- }
227
- const parentRunTree = new RunTree({
228
- name: parentRun?.name ?? "<parent>",
229
- id: parentRun?.id,
230
- client,
231
- tracingEnabled,
232
- project_name: projectName,
233
- tags: [
234
- ...new Set((parentRun?.tags ?? []).concat(parentConfig?.tags ?? [])),
235
- ],
236
- extra: {
237
- metadata: {
238
- ...parentRun?.extra?.metadata,
239
- ...parentConfig?.metadata,
240
- },
241
- },
242
- });
243
- return parentRunTree.createChild({
244
- name: props?.name ?? "<lambda>",
245
- tags: props.tags,
246
- metadata: props.metadata,
247
- });
248
- }
249
253
  static getDefaultConfig() {
250
254
  return {
251
255
  id: uuid.v4(),
@@ -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
  }
@@ -363,6 +367,82 @@ class RunTree {
363
367
  toJSON() {
364
368
  return this._convertToCreate(this, undefined, false);
365
369
  }
370
+ static fromRunnableConfig(parentConfig, props) {
371
+ // We only handle the callback manager case for now
372
+ const callbackManager = parentConfig?.callbacks;
373
+ let parentRun;
374
+ let projectName;
375
+ let client;
376
+ let tracingEnabled = (0, env_js_2.isTracingEnabled)();
377
+ if (callbackManager) {
378
+ const parentRunId = callbackManager?.getParentRunId?.() ?? "";
379
+ const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name == "langchain_tracer");
380
+ parentRun = langChainTracer?.getRun?.(parentRunId);
381
+ projectName = langChainTracer?.projectName;
382
+ client = langChainTracer?.client;
383
+ tracingEnabled = tracingEnabled || !!langChainTracer;
384
+ }
385
+ if (!parentRun) {
386
+ return new RunTree({
387
+ ...props,
388
+ client,
389
+ tracingEnabled,
390
+ project_name: projectName,
391
+ });
392
+ }
393
+ const parentRunTree = new RunTree({
394
+ name: parentRun.name,
395
+ id: parentRun.id,
396
+ client,
397
+ tracingEnabled,
398
+ project_name: projectName,
399
+ tags: [
400
+ ...new Set((parentRun?.tags ?? []).concat(parentConfig?.tags ?? [])),
401
+ ],
402
+ extra: {
403
+ metadata: {
404
+ ...parentRun?.extra?.metadata,
405
+ ...parentConfig?.metadata,
406
+ },
407
+ },
408
+ });
409
+ return parentRunTree.createChild(props);
410
+ }
411
+ static fromDottedOrder(dottedOrder) {
412
+ return this.fromHeaders({ "langsmith-trace": dottedOrder });
413
+ }
414
+ static fromHeaders(headers, inheritArgs) {
415
+ const headerTrace = headers["langsmith-trace"];
416
+ if (!headerTrace || typeof headerTrace !== "string")
417
+ return undefined;
418
+ const parentDottedOrder = headerTrace.trim();
419
+ const parsedDottedOrder = parentDottedOrder.split(".").map((part) => {
420
+ const [strTime, uuid] = part.split("Z");
421
+ return { strTime, time: Date.parse(strTime + "Z"), uuid };
422
+ });
423
+ const traceId = parsedDottedOrder[0].uuid;
424
+ const config = {
425
+ ...inheritArgs,
426
+ name: inheritArgs?.["name"] ?? "parent",
427
+ run_type: inheritArgs?.["run_type"] ?? "chain",
428
+ start_time: inheritArgs?.["start_time"] ?? Date.now(),
429
+ id: parsedDottedOrder.at(-1)?.uuid,
430
+ trace_id: traceId,
431
+ dotted_order: parentDottedOrder,
432
+ };
433
+ if (headers["baggage"]) {
434
+ const baggage = Baggage.fromHeader(headers["baggage"]);
435
+ config.metadata = baggage.metadata;
436
+ config.tags = baggage.tags;
437
+ }
438
+ return new RunTree(config);
439
+ }
440
+ toHeaders() {
441
+ return {
442
+ "langsmith-trace": this.dotted_order,
443
+ baggage: new Baggage(this.extra?.metadata, this.tags).toHeader(),
444
+ };
445
+ }
366
446
  }
367
447
  exports.RunTree = RunTree;
368
448
  function isRunTree(x) {
@@ -24,6 +24,8 @@ export interface RunTreeConfig {
24
24
  on_end?: (runTree: RunTree) => void;
25
25
  execution_order?: number;
26
26
  child_execution_order?: number;
27
+ trace_id?: string;
28
+ dotted_order?: string;
27
29
  }
28
30
  export interface RunnableConfigLike {
29
31
  /**
@@ -66,11 +68,6 @@ export declare class RunTree implements BaseRun {
66
68
  execution_order: number;
67
69
  child_execution_order: number;
68
70
  constructor(originalConfig: RunTreeConfig);
69
- static fromRunnableConfig(parentConfig: RunnableConfigLike, props: {
70
- name: string;
71
- tags?: string[];
72
- metadata?: KVMap;
73
- }): RunTree;
74
71
  private static getDefaultConfig;
75
72
  createChild(config: RunTreeConfig): RunTree;
76
73
  end(outputs?: KVMap, error?: string, endTime?: number): Promise<void>;
@@ -78,6 +75,13 @@ export declare class RunTree implements BaseRun {
78
75
  postRun(excludeChildRuns?: boolean): Promise<void>;
79
76
  patchRun(): Promise<void>;
80
77
  toJSON(): RunCreate;
78
+ static fromRunnableConfig(parentConfig: RunnableConfigLike, props: RunTreeConfig): RunTree;
79
+ static fromDottedOrder(dottedOrder: string): RunTree | undefined;
80
+ static fromHeaders(headers: Record<string, string>, inheritArgs?: RunTreeConfig): RunTree | undefined;
81
+ toHeaders(): {
82
+ "langsmith-trace": string;
83
+ baggage: string;
84
+ };
81
85
  }
82
86
  export declare function isRunTree(x?: unknown): x is RunTree;
83
87
  export declare function isRunnableConfigLike(x?: unknown): x is RunnableConfigLike;
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
  }
@@ -18,6 +12,53 @@ export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
18
12
  const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
19
13
  return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`) + runId);
20
14
  }
15
+ /**
16
+ * Baggage header information
17
+ */
18
+ class Baggage {
19
+ constructor(metadata, tags) {
20
+ Object.defineProperty(this, "metadata", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.defineProperty(this, "tags", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ this.metadata = metadata;
33
+ this.tags = tags;
34
+ }
35
+ static fromHeader(value) {
36
+ const items = value.split(",");
37
+ let metadata = {};
38
+ let tags = [];
39
+ for (const item of items) {
40
+ const [key, uriValue] = item.split("=");
41
+ const value = decodeURIComponent(uriValue);
42
+ if (key === "langsmith-metadata") {
43
+ metadata = JSON.parse(value);
44
+ }
45
+ else if (key === "langsmith-tags") {
46
+ tags = value.split(",");
47
+ }
48
+ }
49
+ return new Baggage(metadata, tags);
50
+ }
51
+ toHeader() {
52
+ const items = [];
53
+ if (this.metadata && Object.keys(this.metadata).length > 0) {
54
+ items.push(`langsmith-metadata=${encodeURIComponent(JSON.stringify(this.metadata))}`);
55
+ }
56
+ if (this.tags && this.tags.length > 0) {
57
+ items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
58
+ }
59
+ return items.join(",");
60
+ }
61
+ }
21
62
  export class RunTree {
22
63
  constructor(originalConfig) {
23
64
  Object.defineProperty(this, "id", {
@@ -182,43 +223,6 @@ export class RunTree {
182
223
  }
183
224
  }
184
225
  }
185
- static fromRunnableConfig(parentConfig, props) {
186
- // We only handle the callback manager case for now
187
- const callbackManager = parentConfig?.callbacks;
188
- let parentRun;
189
- let projectName;
190
- let client;
191
- let tracingEnabled = isTracingEnabled();
192
- if (callbackManager) {
193
- const parentRunId = callbackManager?.getParentRunId?.() ?? "";
194
- const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name == "langchain_tracer");
195
- parentRun = langChainTracer?.getRun?.(parentRunId);
196
- projectName = langChainTracer?.projectName;
197
- client = langChainTracer?.client;
198
- tracingEnabled = tracingEnabled || !!langChainTracer;
199
- }
200
- const parentRunTree = new RunTree({
201
- name: parentRun?.name ?? "<parent>",
202
- id: parentRun?.id,
203
- client,
204
- tracingEnabled,
205
- project_name: projectName,
206
- tags: [
207
- ...new Set((parentRun?.tags ?? []).concat(parentConfig?.tags ?? [])),
208
- ],
209
- extra: {
210
- metadata: {
211
- ...parentRun?.extra?.metadata,
212
- ...parentConfig?.metadata,
213
- },
214
- },
215
- });
216
- return parentRunTree.createChild({
217
- name: props?.name ?? "<lambda>",
218
- tags: props.tags,
219
- metadata: props.metadata,
220
- });
221
- }
222
226
  static getDefaultConfig() {
223
227
  return {
224
228
  id: uuid.v4(),
@@ -336,6 +340,82 @@ export class RunTree {
336
340
  toJSON() {
337
341
  return this._convertToCreate(this, undefined, false);
338
342
  }
343
+ static fromRunnableConfig(parentConfig, props) {
344
+ // We only handle the callback manager case for now
345
+ const callbackManager = parentConfig?.callbacks;
346
+ let parentRun;
347
+ let projectName;
348
+ let client;
349
+ let tracingEnabled = isTracingEnabled();
350
+ if (callbackManager) {
351
+ const parentRunId = callbackManager?.getParentRunId?.() ?? "";
352
+ const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name == "langchain_tracer");
353
+ parentRun = langChainTracer?.getRun?.(parentRunId);
354
+ projectName = langChainTracer?.projectName;
355
+ client = langChainTracer?.client;
356
+ tracingEnabled = tracingEnabled || !!langChainTracer;
357
+ }
358
+ if (!parentRun) {
359
+ return new RunTree({
360
+ ...props,
361
+ client,
362
+ tracingEnabled,
363
+ project_name: projectName,
364
+ });
365
+ }
366
+ const parentRunTree = new RunTree({
367
+ name: parentRun.name,
368
+ id: parentRun.id,
369
+ client,
370
+ tracingEnabled,
371
+ project_name: projectName,
372
+ tags: [
373
+ ...new Set((parentRun?.tags ?? []).concat(parentConfig?.tags ?? [])),
374
+ ],
375
+ extra: {
376
+ metadata: {
377
+ ...parentRun?.extra?.metadata,
378
+ ...parentConfig?.metadata,
379
+ },
380
+ },
381
+ });
382
+ return parentRunTree.createChild(props);
383
+ }
384
+ static fromDottedOrder(dottedOrder) {
385
+ return this.fromHeaders({ "langsmith-trace": dottedOrder });
386
+ }
387
+ static fromHeaders(headers, inheritArgs) {
388
+ const headerTrace = headers["langsmith-trace"];
389
+ if (!headerTrace || typeof headerTrace !== "string")
390
+ return undefined;
391
+ const parentDottedOrder = headerTrace.trim();
392
+ const parsedDottedOrder = parentDottedOrder.split(".").map((part) => {
393
+ const [strTime, uuid] = part.split("Z");
394
+ return { strTime, time: Date.parse(strTime + "Z"), uuid };
395
+ });
396
+ const traceId = parsedDottedOrder[0].uuid;
397
+ const config = {
398
+ ...inheritArgs,
399
+ name: inheritArgs?.["name"] ?? "parent",
400
+ run_type: inheritArgs?.["run_type"] ?? "chain",
401
+ start_time: inheritArgs?.["start_time"] ?? Date.now(),
402
+ id: parsedDottedOrder.at(-1)?.uuid,
403
+ trace_id: traceId,
404
+ dotted_order: parentDottedOrder,
405
+ };
406
+ if (headers["baggage"]) {
407
+ const baggage = Baggage.fromHeader(headers["baggage"]);
408
+ config.metadata = baggage.metadata;
409
+ config.tags = baggage.tags;
410
+ }
411
+ return new RunTree(config);
412
+ }
413
+ toHeaders() {
414
+ return {
415
+ "langsmith-trace": this.dotted_order,
416
+ baggage: new Baggage(this.extra?.metadata, this.tags).toHeader(),
417
+ };
418
+ }
339
419
  }
340
420
  export function isRunTree(x) {
341
421
  return (x !== undefined &&
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.30",
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
+ }