langsmith 0.3.65 → 0.3.66

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/index.cjs CHANGED
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
10
10
  var project_js_1 = require("./utils/project.cjs");
11
11
  Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
12
12
  // Update using yarn bump-version
13
- exports.__version__ = "0.3.65";
13
+ exports.__version__ = "0.3.66";
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
- export declare const __version__ = "0.3.65";
6
+ export declare const __version__ = "0.3.66";
package/dist/index.js CHANGED
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export { getDefaultProjectName } from "./utils/project.js";
5
5
  // Update using yarn bump-version
6
- export const __version__ = "0.3.65";
6
+ export const __version__ = "0.3.66";
@@ -105,25 +105,6 @@ const _extractUsage = (runData) => {
105
105
  .usage_metadata;
106
106
  return runData.outputs?.usage_metadata ?? usageMetadataFromMetadata;
107
107
  };
108
- function validateExtractedUsageMetadata(data) {
109
- const allowedKeys = new Set([
110
- "input_tokens",
111
- "output_tokens",
112
- "total_tokens",
113
- "input_token_details",
114
- "output_token_details",
115
- "input_cost",
116
- "output_cost",
117
- "total_cost",
118
- "input_cost_details",
119
- "output_cost_details",
120
- ]);
121
- const extraKeys = Object.keys(data).filter((key) => !allowedKeys.has(key));
122
- if (extraKeys.length > 0) {
123
- throw new Error(`Unexpected keys in usage metadata: ${extraKeys.join(", ")}`);
124
- }
125
- return data;
126
- }
127
108
  async function handleEnd(params) {
128
109
  const { runTree, on_end, postRunPromise, excludeInputs } = params;
129
110
  const onEnd = on_end;
@@ -152,7 +133,7 @@ const _populateUsageMetadata = (processedOutputs, runTree) => {
152
133
  if (usageMetadata !== undefined) {
153
134
  runTree.extra.metadata = {
154
135
  ...runTree.extra.metadata,
155
- usage_metadata: validateExtractedUsageMetadata(usageMetadata),
136
+ usage_metadata: usageMetadata,
156
137
  };
157
138
  processedOutputs.usage_metadata = usageMetadata;
158
139
  }
package/dist/traceable.js CHANGED
@@ -101,25 +101,6 @@ const _extractUsage = (runData) => {
101
101
  .usage_metadata;
102
102
  return runData.outputs?.usage_metadata ?? usageMetadataFromMetadata;
103
103
  };
104
- function validateExtractedUsageMetadata(data) {
105
- const allowedKeys = new Set([
106
- "input_tokens",
107
- "output_tokens",
108
- "total_tokens",
109
- "input_token_details",
110
- "output_token_details",
111
- "input_cost",
112
- "output_cost",
113
- "total_cost",
114
- "input_cost_details",
115
- "output_cost_details",
116
- ]);
117
- const extraKeys = Object.keys(data).filter((key) => !allowedKeys.has(key));
118
- if (extraKeys.length > 0) {
119
- throw new Error(`Unexpected keys in usage metadata: ${extraKeys.join(", ")}`);
120
- }
121
- return data;
122
- }
123
104
  async function handleEnd(params) {
124
105
  const { runTree, on_end, postRunPromise, excludeInputs } = params;
125
106
  const onEnd = on_end;
@@ -148,7 +129,7 @@ const _populateUsageMetadata = (processedOutputs, runTree) => {
148
129
  if (usageMetadata !== undefined) {
149
130
  runTree.extra.metadata = {
150
131
  ...runTree.extra.metadata,
151
- usage_metadata: validateExtractedUsageMetadata(usageMetadata),
132
+ usage_metadata: usageMetadata,
152
133
  };
153
134
  processedOutputs.usage_metadata = usageMetadata;
154
135
  }
@@ -161,17 +161,29 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
161
161
  return (0, uuid_1.v5)(identifier, constants_js_1.UUID5_NAMESPACE);
162
162
  }
163
163
  async function syncExample(params) {
164
- const { client, exampleId, inputs, outputs, metadata, createdAt, datasetId, } = params;
164
+ const { client, exampleId, inputs, outputs, metadata, split, createdAt, datasetId, } = params;
165
165
  let example;
166
166
  try {
167
167
  example = await client.readExample(exampleId);
168
+ const normalizedSplit = split
169
+ ? typeof split === "string"
170
+ ? [split]
171
+ : split
172
+ : undefined;
173
+ const { dataset_split, ...restMetadata } = example.metadata ?? {};
168
174
  if (_objectHash(example.inputs) !== _objectHash(inputs) ||
169
175
  _objectHash(example.outputs ?? {}) !== _objectHash(outputs ?? {}) ||
170
- example.dataset_id !== datasetId) {
176
+ example.dataset_id !== datasetId ||
177
+ (normalizedSplit !== undefined &&
178
+ _objectHash(dataset_split ?? []) !==
179
+ _objectHash(normalizedSplit ?? [])) ||
180
+ (metadata !== undefined &&
181
+ _objectHash(restMetadata ?? {}) !== _objectHash(metadata ?? {}))) {
171
182
  await client.updateExample(exampleId, {
172
183
  inputs,
173
184
  outputs,
174
185
  metadata,
186
+ split,
175
187
  dataset_id: datasetId,
176
188
  });
177
189
  }
@@ -182,6 +194,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
182
194
  exampleId,
183
195
  datasetId,
184
196
  createdAt: new Date(createdAt ?? new Date()),
197
+ split,
185
198
  metadata,
186
199
  });
187
200
  }
@@ -398,7 +411,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
398
411
  lsParams.config?.enableTestTracking !== undefined) {
399
412
  context.enableTestTracking = lsParams.config.enableTestTracking;
400
413
  }
401
- const { id, config, inputs, ...rest } = lsParams;
414
+ const { id, config, inputs, split, metadata, ...rest } = lsParams;
402
415
  let referenceOutputs = rest.referenceOutputs;
403
416
  if (!referenceOutputs && "outputs" in rest) {
404
417
  referenceOutputs = rest.outputs;
@@ -471,6 +484,7 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
471
484
  datasetId: dataset?.id,
472
485
  testTrackingEnabled: (0, globals_js_1.trackingEnabled)(testContext),
473
486
  repetition: i,
487
+ split,
474
488
  },
475
489
  }));
476
490
  (0, globals_js_1._logTestFeedback)({
@@ -536,7 +550,8 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
536
550
  datasetId: dataset.id,
537
551
  inputs,
538
552
  outputs: referenceOutputs ?? {},
539
- metadata: {},
553
+ metadata,
554
+ split,
540
555
  createdAt,
541
556
  }));
542
557
  }
@@ -6,7 +6,7 @@ export declare function logFeedback(feedback: SimpleEvaluationResult, config?: {
6
6
  sourceRunId?: string;
7
7
  }): void;
8
8
  export declare function logOutputs(output: Record<string, unknown>): void;
9
- export declare function _objectHash(obj: KVMap, depth?: number): string;
9
+ export declare function _objectHash(obj: KVMap | unknown[], depth?: number): string;
10
10
  export declare function generateWrapperFromJestlikeMethods(methods: Record<string, any>, testRunnerName: string): {
11
11
  test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: LangSmithJestlikeTestFunction<I, O>, timeout?: number) => void) & {
12
12
  only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: LangSmithJestlikeTestFunction<I, O>, timeout?: number) => void) & {
@@ -114,17 +114,29 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
114
114
  return v5(identifier, UUID5_NAMESPACE);
115
115
  }
116
116
  async function syncExample(params) {
117
- const { client, exampleId, inputs, outputs, metadata, createdAt, datasetId, } = params;
117
+ const { client, exampleId, inputs, outputs, metadata, split, createdAt, datasetId, } = params;
118
118
  let example;
119
119
  try {
120
120
  example = await client.readExample(exampleId);
121
+ const normalizedSplit = split
122
+ ? typeof split === "string"
123
+ ? [split]
124
+ : split
125
+ : undefined;
126
+ const { dataset_split, ...restMetadata } = example.metadata ?? {};
121
127
  if (_objectHash(example.inputs) !== _objectHash(inputs) ||
122
128
  _objectHash(example.outputs ?? {}) !== _objectHash(outputs ?? {}) ||
123
- example.dataset_id !== datasetId) {
129
+ example.dataset_id !== datasetId ||
130
+ (normalizedSplit !== undefined &&
131
+ _objectHash(dataset_split ?? []) !==
132
+ _objectHash(normalizedSplit ?? [])) ||
133
+ (metadata !== undefined &&
134
+ _objectHash(restMetadata ?? {}) !== _objectHash(metadata ?? {}))) {
124
135
  await client.updateExample(exampleId, {
125
136
  inputs,
126
137
  outputs,
127
138
  metadata,
139
+ split,
128
140
  dataset_id: datasetId,
129
141
  });
130
142
  }
@@ -135,6 +147,7 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
135
147
  exampleId,
136
148
  datasetId,
137
149
  createdAt: new Date(createdAt ?? new Date()),
150
+ split,
138
151
  metadata,
139
152
  });
140
153
  }
@@ -351,7 +364,7 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
351
364
  lsParams.config?.enableTestTracking !== undefined) {
352
365
  context.enableTestTracking = lsParams.config.enableTestTracking;
353
366
  }
354
- const { id, config, inputs, ...rest } = lsParams;
367
+ const { id, config, inputs, split, metadata, ...rest } = lsParams;
355
368
  let referenceOutputs = rest.referenceOutputs;
356
369
  if (!referenceOutputs && "outputs" in rest) {
357
370
  referenceOutputs = rest.outputs;
@@ -424,6 +437,7 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
424
437
  datasetId: dataset?.id,
425
438
  testTrackingEnabled: trackingEnabled(testContext),
426
439
  repetition: i,
440
+ split,
427
441
  },
428
442
  }));
429
443
  _logTestFeedback({
@@ -489,7 +503,8 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
489
503
  datasetId: dataset.id,
490
504
  inputs,
491
505
  outputs: referenceOutputs ?? {},
492
- metadata: {},
506
+ metadata,
507
+ split,
493
508
  createdAt,
494
509
  }));
495
510
  }
@@ -1,6 +1,5 @@
1
- import { CreateProjectParams } from "../../client.js";
2
- import { EvaluationResult } from "../../evaluation/evaluator.js";
3
- import { Client } from "../../index.js";
1
+ import type { CreateProjectParams, CreateExampleOptions, Client } from "../../client.js";
2
+ import type { EvaluationResult } from "../../evaluation/evaluator.js";
4
3
  import type { RunTreeConfig } from "../../run_trees.js";
5
4
  import type { SimpleEvaluator } from "./vendor/evaluatedBy.js";
6
5
  export { type SimpleEvaluator };
@@ -15,7 +14,7 @@ export type LangSmithJestlikeWrapperParams<I, O> = {
15
14
  inputs: I;
16
15
  referenceOutputs?: O;
17
16
  config?: LangSmithJestlikeWrapperConfig;
18
- };
17
+ } & Pick<CreateExampleOptions, "split" | "metadata">;
19
18
  export type LangSmithJestlikeDescribeWrapperConfig = {
20
19
  client?: Client;
21
20
  enableTestTracking?: boolean;
@@ -35,6 +34,7 @@ export type LangSmithJestlikeTestMetadata = {
35
34
  datasetId?: string;
36
35
  testTrackingEnabled: boolean;
37
36
  repetition: number;
37
+ split?: string | string[];
38
38
  };
39
39
  export type LangSmithJestlikeTestFunction<I, O> = (data: {
40
40
  inputs: I;
@@ -72,7 +72,8 @@ function _combineChatCompletionChoices(choices
72
72
  }
73
73
  return {
74
74
  index: choices[0].index,
75
- finish_reason: reversedChoices.find((c) => c.finish_reason) || null,
75
+ finish_reason: (reversedChoices.find((c) => c.finish_reason) || null)
76
+ ?.finish_reason,
76
77
  message: message,
77
78
  };
78
79
  }
@@ -69,7 +69,8 @@ function _combineChatCompletionChoices(choices
69
69
  }
70
70
  return {
71
71
  index: choices[0].index,
72
- finish_reason: reversedChoices.find((c) => c.finish_reason) || null,
72
+ finish_reason: (reversedChoices.find((c) => c.finish_reason) || null)
73
+ ?.finish_reason,
73
74
  message: message,
74
75
  };
75
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.65",
3
+ "version": "0.3.66",
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": [