langsmith 0.1.31 → 0.1.32

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.
package/dist/client.cjs CHANGED
@@ -30,6 +30,7 @@ const messages_js_1 = require("./utils/messages.cjs");
30
30
  const env_js_1 = require("./utils/env.cjs");
31
31
  const index_js_1 = require("./index.cjs");
32
32
  const _uuid_js_1 = require("./utils/_uuid.cjs");
33
+ const warn_js_1 = require("./utils/warn.cjs");
33
34
  async function mergeRuntimeEnvIntoRunCreates(runs) {
34
35
  const runtimeEnv = await (0, env_js_1.getRuntimeEnvironment)();
35
36
  const envVars = (0, env_js_1.getLangChainEnvVarsMetadata)();
@@ -1616,7 +1617,11 @@ class Client {
1616
1617
  const result = await response.json();
1617
1618
  return result;
1618
1619
  }
1620
+ /**
1621
+ * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
1622
+ */
1619
1623
  async evaluateRun(run, evaluator, { sourceInfo, loadChildRuns, referenceExample, } = { loadChildRuns: false }) {
1624
+ (0, warn_js_1.warnOnce)("This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.");
1620
1625
  let run_;
1621
1626
  if (typeof run === "string") {
1622
1627
  run_ = await this.readRun(run, { loadChildRuns });
@@ -1632,20 +1637,8 @@ class Client {
1632
1637
  referenceExample = await this.readExample(run_.reference_example_id);
1633
1638
  }
1634
1639
  const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
1635
- let sourceInfo_ = sourceInfo ?? {};
1636
- if (feedbackResult.evaluatorInfo) {
1637
- sourceInfo_ = { ...sourceInfo_, ...feedbackResult.evaluatorInfo };
1638
- }
1639
- const runId = feedbackResult.targetRunId ?? run_.id;
1640
- return await this.createFeedback(runId, feedbackResult.key, {
1641
- score: feedbackResult?.score,
1642
- value: feedbackResult?.value,
1643
- comment: feedbackResult?.comment,
1644
- correction: feedbackResult?.correction,
1645
- sourceInfo: sourceInfo_,
1646
- feedbackSourceType: "model",
1647
- sourceRunId: feedbackResult?.sourceRunId,
1648
- });
1640
+ const [_, feedbacks] = await this._logEvaluationFeedback(feedbackResult, run_, sourceInfo);
1641
+ return feedbacks[0];
1649
1642
  }
1650
1643
  async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }) {
1651
1644
  if (!runId && !projectId) {
@@ -1852,9 +1845,10 @@ class Client {
1852
1845
  }
1853
1846
  return results_;
1854
1847
  }
1855
- async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1856
- const results = this._selectEvalResults(evaluatorResponse);
1857
- for (const res of results) {
1848
+ async _logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1849
+ const evalResults = this._selectEvalResults(evaluatorResponse);
1850
+ const feedbacks = [];
1851
+ for (const res of evalResults) {
1858
1852
  let sourceInfo_ = sourceInfo || {};
1859
1853
  if (res.evaluatorInfo) {
1860
1854
  sourceInfo_ = { ...res.evaluatorInfo, ...sourceInfo_ };
@@ -1866,7 +1860,7 @@ class Client {
1866
1860
  else if (run) {
1867
1861
  runId_ = run.id;
1868
1862
  }
1869
- await this.createFeedback(runId_, res.key, {
1863
+ feedbacks.push(await this.createFeedback(runId_, res.key, {
1870
1864
  score: res.score,
1871
1865
  value: res.value,
1872
1866
  comment: res.comment,
@@ -1875,8 +1869,12 @@ class Client {
1875
1869
  sourceRunId: res.sourceRunId,
1876
1870
  feedbackConfig: res.feedbackConfig,
1877
1871
  feedbackSourceType: "model",
1878
- });
1872
+ }));
1879
1873
  }
1874
+ return [evalResults, feedbacks];
1875
+ }
1876
+ async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1877
+ const [results] = await this._logEvaluationFeedback(evaluatorResponse, run, sourceInfo);
1880
1878
  return results;
1881
1879
  }
1882
1880
  }
package/dist/client.d.ts CHANGED
@@ -415,6 +415,9 @@ export declare class Client {
415
415
  }): AsyncIterable<Example>;
416
416
  deleteExample(exampleId: string): Promise<void>;
417
417
  updateExample(exampleId: string, update: ExampleUpdate): Promise<object>;
418
+ /**
419
+ * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
420
+ */
418
421
  evaluateRun(run: Run | string, evaluator: RunEvaluator, { sourceInfo, loadChildRuns, referenceExample, }?: {
419
422
  sourceInfo?: KVMap;
420
423
  loadChildRuns: boolean;
@@ -482,6 +485,9 @@ export declare class Client {
482
485
  */
483
486
  listPresignedFeedbackTokens(runId: string): AsyncIterable<FeedbackIngestToken>;
484
487
  _selectEvalResults(results: EvaluationResult | EvaluationResults): Array<EvaluationResult>;
488
+ _logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResults, run?: Run, sourceInfo?: {
489
+ [key: string]: any;
490
+ }): Promise<[results: EvaluationResult[], feedbacks: Feedback[]]>;
485
491
  logEvaluationFeedback(evaluatorResponse: EvaluationResult | EvaluationResults, run?: Run, sourceInfo?: {
486
492
  [key: string]: any;
487
493
  }): Promise<EvaluationResult[]>;
package/dist/client.js CHANGED
@@ -4,6 +4,7 @@ import { convertLangChainMessageToExample, isLangChainMessage, } from "./utils/m
4
4
  import { getEnvironmentVariable, getLangChainEnvVarsMetadata, getRuntimeEnvironment, } from "./utils/env.js";
5
5
  import { __version__ } from "./index.js";
6
6
  import { assertUuid } from "./utils/_uuid.js";
7
+ import { warnOnce } from "./utils/warn.js";
7
8
  async function mergeRuntimeEnvIntoRunCreates(runs) {
8
9
  const runtimeEnv = await getRuntimeEnvironment();
9
10
  const envVars = getLangChainEnvVarsMetadata();
@@ -1589,7 +1590,11 @@ export class Client {
1589
1590
  const result = await response.json();
1590
1591
  return result;
1591
1592
  }
1593
+ /**
1594
+ * @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
1595
+ */
1592
1596
  async evaluateRun(run, evaluator, { sourceInfo, loadChildRuns, referenceExample, } = { loadChildRuns: false }) {
1597
+ warnOnce("This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.");
1593
1598
  let run_;
1594
1599
  if (typeof run === "string") {
1595
1600
  run_ = await this.readRun(run, { loadChildRuns });
@@ -1605,20 +1610,8 @@ export class Client {
1605
1610
  referenceExample = await this.readExample(run_.reference_example_id);
1606
1611
  }
1607
1612
  const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
1608
- let sourceInfo_ = sourceInfo ?? {};
1609
- if (feedbackResult.evaluatorInfo) {
1610
- sourceInfo_ = { ...sourceInfo_, ...feedbackResult.evaluatorInfo };
1611
- }
1612
- const runId = feedbackResult.targetRunId ?? run_.id;
1613
- return await this.createFeedback(runId, feedbackResult.key, {
1614
- score: feedbackResult?.score,
1615
- value: feedbackResult?.value,
1616
- comment: feedbackResult?.comment,
1617
- correction: feedbackResult?.correction,
1618
- sourceInfo: sourceInfo_,
1619
- feedbackSourceType: "model",
1620
- sourceRunId: feedbackResult?.sourceRunId,
1621
- });
1613
+ const [_, feedbacks] = await this._logEvaluationFeedback(feedbackResult, run_, sourceInfo);
1614
+ return feedbacks[0];
1622
1615
  }
1623
1616
  async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, }) {
1624
1617
  if (!runId && !projectId) {
@@ -1825,9 +1818,10 @@ export class Client {
1825
1818
  }
1826
1819
  return results_;
1827
1820
  }
1828
- async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1829
- const results = this._selectEvalResults(evaluatorResponse);
1830
- for (const res of results) {
1821
+ async _logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1822
+ const evalResults = this._selectEvalResults(evaluatorResponse);
1823
+ const feedbacks = [];
1824
+ for (const res of evalResults) {
1831
1825
  let sourceInfo_ = sourceInfo || {};
1832
1826
  if (res.evaluatorInfo) {
1833
1827
  sourceInfo_ = { ...res.evaluatorInfo, ...sourceInfo_ };
@@ -1839,7 +1833,7 @@ export class Client {
1839
1833
  else if (run) {
1840
1834
  runId_ = run.id;
1841
1835
  }
1842
- await this.createFeedback(runId_, res.key, {
1836
+ feedbacks.push(await this.createFeedback(runId_, res.key, {
1843
1837
  score: res.score,
1844
1838
  value: res.value,
1845
1839
  comment: res.comment,
@@ -1848,8 +1842,12 @@ export class Client {
1848
1842
  sourceRunId: res.sourceRunId,
1849
1843
  feedbackConfig: res.feedbackConfig,
1850
1844
  feedbackSourceType: "model",
1851
- });
1845
+ }));
1852
1846
  }
1847
+ return [evalResults, feedbacks];
1848
+ }
1849
+ async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
1850
+ const [results] = await this._logEvaluationFeedback(evaluatorResponse, run, sourceInfo);
1853
1851
  return results;
1854
1852
  }
1855
1853
  }
@@ -8,7 +8,7 @@ type TargetT<TInput = any, TOutput = KVMap> = ((input: TInput, config?: KVMap) =
8
8
  };
9
9
  type DataT = string | AsyncIterable<Example> | Example[];
10
10
  type SummaryEvaluatorT = ((runs: Array<Run>, examples: Array<Example>) => Promise<EvaluationResult | EvaluationResults>) | ((runs: Array<Run>, examples: Array<Example>) => EvaluationResult | EvaluationResults);
11
- type EvaluatorT = RunEvaluator | ((run: Run, example?: Example) => EvaluationResult) | ((run: Run, example?: Example) => Promise<EvaluationResult>);
11
+ type EvaluatorT = RunEvaluator | ((run: Run, example?: Example) => EvaluationResult | EvaluationResults) | ((run: Run, example?: Example) => Promise<EvaluationResult | EvaluationResults>);
12
12
  interface _ForwardResults {
13
13
  run: Run;
14
14
  example: Example;
@@ -19,9 +19,18 @@ class DynamicRunEvaluator {
19
19
  return evaluator(run, example);
20
20
  });
21
21
  }
22
+ isEvaluationResults(x) {
23
+ return (typeof x === "object" &&
24
+ x != null &&
25
+ "results" in x &&
26
+ Array.isArray(x.results) &&
27
+ x.results.length > 0);
28
+ }
22
29
  coerceEvaluationResults(results, sourceRunId) {
23
- if ("results" in results) {
24
- throw new Error("EvaluationResults not supported yet.");
30
+ if (this.isEvaluationResults(results)) {
31
+ return {
32
+ results: results.results.map((r) => this.coerceEvaluationResult(r, sourceRunId, false)),
33
+ };
25
34
  }
26
35
  return this.coerceEvaluationResult(results, sourceRunId, true);
27
36
  }
@@ -70,7 +70,7 @@ export type EvaluationResults = {
70
70
  results: Array<EvaluationResult>;
71
71
  };
72
72
  export interface RunEvaluator {
73
- evaluateRun(run: Run, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult>;
73
+ evaluateRun(run: Run, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult | EvaluationResults>;
74
74
  }
75
75
  export type RunEvaluatorLike = ((run: Run, example?: Example) => Promise<EvaluationResult | EvaluationResults>) | ((run: Run, example?: Example) => EvaluationResult | EvaluationResults);
76
76
  /**
@@ -79,6 +79,7 @@ export type RunEvaluatorLike = ((run: Run, example?: Example) => Promise<Evaluat
79
79
  export declare class DynamicRunEvaluator<Func extends (...args: any[]) => any> implements RunEvaluator {
80
80
  func: Func;
81
81
  constructor(evaluator: Func);
82
+ private isEvaluationResults;
82
83
  private coerceEvaluationResults;
83
84
  private coerceEvaluationResult;
84
85
  /**
@@ -87,6 +88,6 @@ export declare class DynamicRunEvaluator<Func extends (...args: any[]) => any> i
87
88
  * @param example The optional example to use for evaluation.
88
89
  * @returns A promise that extracts to the evaluation result.
89
90
  */
90
- evaluateRun(run: Run, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult>;
91
+ evaluateRun(run: Run, example?: Example, options?: Partial<RunTreeConfig>): Promise<EvaluationResult | EvaluationResults>;
91
92
  }
92
93
  export declare function runEvaluator(func: RunEvaluatorLike): RunEvaluator;
@@ -16,9 +16,18 @@ export class DynamicRunEvaluator {
16
16
  return evaluator(run, example);
17
17
  });
18
18
  }
19
+ isEvaluationResults(x) {
20
+ return (typeof x === "object" &&
21
+ x != null &&
22
+ "results" in x &&
23
+ Array.isArray(x.results) &&
24
+ x.results.length > 0);
25
+ }
19
26
  coerceEvaluationResults(results, sourceRunId) {
20
- if ("results" in results) {
21
- throw new Error("EvaluationResults not supported yet.");
27
+ if (this.isEvaluationResults(results)) {
28
+ return {
29
+ results: results.results.map((r) => this.coerceEvaluationResult(r, sourceRunId, false)),
30
+ };
22
31
  }
23
32
  return this.coerceEvaluationResult(results, sourceRunId, true);
24
33
  }
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.31";
9
+ exports.__version__ = "0.1.32";
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.31";
4
+ export declare const __version__ = "0.1.32";
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.31";
4
+ export const __version__ = "0.1.32";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
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": [