langsmith 0.1.30 → 0.1.31-rc.0

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.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluate = void 0;
4
4
  const index_js_1 = require("../index.cjs");
5
+ const langchain_js_1 = require("../langchain.cjs");
5
6
  const traceable_js_1 = require("../traceable.cjs");
6
7
  const _git_js_1 = require("../utils/_git.cjs");
7
8
  const _uuid_js_1 = require("../utils/_uuid.cjs");
@@ -368,8 +369,8 @@ class _ExperimentManager {
368
369
  }
369
370
  // Private methods
370
371
  /**
371
- * Run the target function on the examples.
372
- * @param {TargetNoInvoke} target The target function to evaluate.
372
+ * Run the target function or runnable on the examples.
373
+ * @param {TargetT} target The target function or runnable to evaluate.
373
374
  * @param options
374
375
  * @returns {AsyncGenerator<_ForwardResults>} An async generator of the results.
375
376
  */
@@ -614,12 +615,6 @@ class ExperimentResults {
614
615
  return this.results.length;
615
616
  }
616
617
  }
617
- function convertInvokeToTopLevel(fn) {
618
- if ("invoke" in fn) {
619
- return fn.invoke.bind(fn);
620
- }
621
- return fn;
622
- }
623
618
  async function _evaluate(target, fields) {
624
619
  const client = fields.client ?? new index_js_1.Client();
625
620
  const runs = _isCallable(target) ? null : target;
@@ -634,7 +629,9 @@ async function _evaluate(target, fields) {
634
629
  numRepetitions: fields.numRepetitions ?? 1,
635
630
  }).start();
636
631
  if (_isCallable(target)) {
637
- manager = await manager.withPredictions(convertInvokeToTopLevel(target), { maxConcurrency: fields.maxConcurrency });
632
+ manager = await manager.withPredictions(target, {
633
+ maxConcurrency: fields.maxConcurrency,
634
+ });
638
635
  }
639
636
  if (fields.evaluators) {
640
637
  manager = await manager.withEvaluators(fields.evaluators, {
@@ -665,11 +662,14 @@ async function _forward(fn, example, experimentName, metadata, client) {
665
662
  : new Date(example.created_at).toISOString(),
666
663
  },
667
664
  client,
668
- };
669
- const wrappedFn = (0, traceable_js_1.traceable)(fn, {
670
- ...options,
671
665
  tracingEnabled: true,
672
- });
666
+ };
667
+ const wrappedFn = "invoke" in fn
668
+ ? (0, traceable_js_1.traceable)(async (inputs) => {
669
+ const callbacks = await (0, langchain_js_1.getLangchainCallbacks)();
670
+ return fn.invoke(inputs, { callbacks });
671
+ }, options)
672
+ : (0, traceable_js_1.traceable)(fn, options);
673
673
  try {
674
674
  await wrappedFn(example.inputs);
675
675
  }
@@ -6,7 +6,6 @@ type TargetT<TInput = any, TOutput = KVMap> = ((input: TInput, config?: KVMap) =
6
6
  } | {
7
7
  invoke: (input: TInput, config?: KVMap) => Promise<TOutput>;
8
8
  };
9
- type TargetNoInvoke<TInput = any, TOutput = KVMap> = ((input: TInput, config?: KVMap) => Promise<TOutput>) | ((input: TInput, config?: KVMap) => TOutput);
10
9
  type DataT = string | AsyncIterable<Example> | Example[];
11
10
  type SummaryEvaluatorT = ((runs: Array<Run>, examples: Array<Example>) => Promise<EvaluationResult | EvaluationResults>) | ((runs: Array<Run>, examples: Array<Example>) => EvaluationResult | EvaluationResults);
12
11
  type EvaluatorT = RunEvaluator | ((run: Run, example?: Example) => EvaluationResult) | ((run: Run, example?: Example) => Promise<EvaluationResult>);
@@ -114,7 +113,7 @@ declare class _ExperimentManager {
114
113
  _getProject(firstExample: Example): Promise<TracerSession>;
115
114
  protected _printExperimentStart(): Promise<void>;
116
115
  start(): Promise<_ExperimentManager>;
117
- withPredictions(target: TargetNoInvoke, options?: {
116
+ withPredictions(target: TargetT, options?: {
118
117
  maxConcurrency?: number;
119
118
  }): Promise<_ExperimentManager>;
120
119
  withEvaluators(evaluators: Array<EvaluatorT | RunEvaluator>, options?: {
@@ -124,12 +123,12 @@ declare class _ExperimentManager {
124
123
  getResults(): AsyncGenerator<ExperimentResultRow>;
125
124
  getSummaryScores(): Promise<EvaluationResults>;
126
125
  /**
127
- * Run the target function on the examples.
128
- * @param {TargetNoInvoke} target The target function to evaluate.
126
+ * Run the target function or runnable on the examples.
127
+ * @param {TargetT} target The target function or runnable to evaluate.
129
128
  * @param options
130
129
  * @returns {AsyncGenerator<_ForwardResults>} An async generator of the results.
131
130
  */
132
- _predict(target: TargetNoInvoke, options?: {
131
+ _predict(target: TargetT, options?: {
133
132
  maxConcurrency?: number;
134
133
  }): AsyncGenerator<_ForwardResults>;
135
134
  _runEvaluators(evaluators: Array<RunEvaluator>, currentResults: ExperimentResultRow, fields: {
@@ -1,4 +1,5 @@
1
1
  import { Client } from "../index.js";
2
+ import { getLangchainCallbacks } from "../langchain.js";
2
3
  import { traceable } from "../traceable.js";
3
4
  import { getDefaultRevisionId, getGitInfo } from "../utils/_git.js";
4
5
  import { assertUuid } from "../utils/_uuid.js";
@@ -364,8 +365,8 @@ class _ExperimentManager {
364
365
  }
365
366
  // Private methods
366
367
  /**
367
- * Run the target function on the examples.
368
- * @param {TargetNoInvoke} target The target function to evaluate.
368
+ * Run the target function or runnable on the examples.
369
+ * @param {TargetT} target The target function or runnable to evaluate.
369
370
  * @param options
370
371
  * @returns {AsyncGenerator<_ForwardResults>} An async generator of the results.
371
372
  */
@@ -610,12 +611,6 @@ class ExperimentResults {
610
611
  return this.results.length;
611
612
  }
612
613
  }
613
- function convertInvokeToTopLevel(fn) {
614
- if ("invoke" in fn) {
615
- return fn.invoke.bind(fn);
616
- }
617
- return fn;
618
- }
619
614
  async function _evaluate(target, fields) {
620
615
  const client = fields.client ?? new Client();
621
616
  const runs = _isCallable(target) ? null : target;
@@ -630,7 +625,9 @@ async function _evaluate(target, fields) {
630
625
  numRepetitions: fields.numRepetitions ?? 1,
631
626
  }).start();
632
627
  if (_isCallable(target)) {
633
- manager = await manager.withPredictions(convertInvokeToTopLevel(target), { maxConcurrency: fields.maxConcurrency });
628
+ manager = await manager.withPredictions(target, {
629
+ maxConcurrency: fields.maxConcurrency,
630
+ });
634
631
  }
635
632
  if (fields.evaluators) {
636
633
  manager = await manager.withEvaluators(fields.evaluators, {
@@ -661,11 +658,14 @@ async function _forward(fn, example, experimentName, metadata, client) {
661
658
  : new Date(example.created_at).toISOString(),
662
659
  },
663
660
  client,
664
- };
665
- const wrappedFn = traceable(fn, {
666
- ...options,
667
661
  tracingEnabled: true,
668
- });
662
+ };
663
+ const wrappedFn = "invoke" in fn
664
+ ? traceable(async (inputs) => {
665
+ const callbacks = await getLangchainCallbacks();
666
+ return fn.invoke(inputs, { callbacks });
667
+ }, options)
668
+ : traceable(fn, options);
669
669
  try {
670
670
  await wrappedFn(example.inputs);
671
671
  }
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.30";
9
+ exports.__version__ = "0.1.31";
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.30";
4
+ export declare const __version__ = "0.1.31";
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.30";
4
+ export const __version__ = "0.1.31";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.30",
3
+ "version": "0.1.31-rc.0",
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": [