langsmith 0.1.67 → 0.2.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.
package/dist/client.cjs CHANGED
@@ -293,7 +293,13 @@ class Client {
293
293
  enumerable: true,
294
294
  configurable: true,
295
295
  writable: true,
296
- value: true
296
+ value: (0, env_js_1.getEnvironmentVariable)("LANGSMITH_TRACING_BACKGROUND") === "false"
297
+ });
298
+ Object.defineProperty(this, "traceBatchConcurrency", {
299
+ enumerable: true,
300
+ configurable: true,
301
+ writable: true,
302
+ value: 5
297
303
  });
298
304
  Object.defineProperty(this, "_serverInfo", {
299
305
  enumerable: true,
@@ -319,9 +325,16 @@ class Client {
319
325
  if (this.webUrl?.endsWith("/")) {
320
326
  this.webUrl = this.webUrl.slice(0, -1);
321
327
  }
322
- this.timeout_ms = config.timeout_ms ?? 12_000;
328
+ this.timeout_ms = config.timeout_ms ?? 90_000;
323
329
  this.caller = new async_caller_js_1.AsyncCaller(config.callerOptions ?? {});
330
+ this.traceBatchConcurrency =
331
+ config.traceBatchConcurrency ?? this.traceBatchConcurrency;
332
+ if (this.traceBatchConcurrency < 1) {
333
+ throw new Error("Trace batch concurrency must be positive.");
334
+ }
324
335
  this.batchIngestCaller = new async_caller_js_1.AsyncCaller({
336
+ maxRetries: 2,
337
+ maxConcurrency: this.traceBatchConcurrency,
325
338
  ...(config.callerOptions ?? {}),
326
339
  onFailedResponseHook: handle429,
327
340
  });
@@ -527,33 +540,43 @@ class Client {
527
540
  exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES);
528
541
  }
529
542
  async drainAutoBatchQueue() {
530
- while (this.autoBatchQueue.items.length >= 0) {
531
- const [batch, done] = this.autoBatchQueue.pop(await this._getBatchSizeLimitBytes());
532
- if (!batch.length) {
533
- done();
534
- return;
535
- }
536
- try {
537
- const ingestParams = {
538
- runCreates: batch
539
- .filter((item) => item.action === "create")
540
- .map((item) => item.item),
541
- runUpdates: batch
542
- .filter((item) => item.action === "update")
543
- .map((item) => item.item),
544
- };
545
- const serverInfo = await this._ensureServerInfo();
546
- if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
547
- await this.multipartIngestRuns(ingestParams);
548
- }
549
- else {
550
- await this.batchIngestRuns(ingestParams);
543
+ const batchSizeLimit = await this._getBatchSizeLimitBytes();
544
+ while (this.autoBatchQueue.items.length > 0) {
545
+ for (let i = 0; i < this.traceBatchConcurrency; i++) {
546
+ const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
547
+ if (!batch.length) {
548
+ done();
549
+ break;
551
550
  }
551
+ await this.processBatch(batch, done);
552
+ }
553
+ }
554
+ }
555
+ async processBatch(batch, done) {
556
+ if (!batch.length) {
557
+ done();
558
+ return;
559
+ }
560
+ try {
561
+ const ingestParams = {
562
+ runCreates: batch
563
+ .filter((item) => item.action === "create")
564
+ .map((item) => item.item),
565
+ runUpdates: batch
566
+ .filter((item) => item.action === "update")
567
+ .map((item) => item.item),
568
+ };
569
+ const serverInfo = await this._ensureServerInfo();
570
+ if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
571
+ await this.multipartIngestRuns(ingestParams);
552
572
  }
553
- finally {
554
- done();
573
+ else {
574
+ await this.batchIngestRuns(ingestParams);
555
575
  }
556
576
  }
577
+ finally {
578
+ done();
579
+ }
557
580
  }
558
581
  async processRunOperation(item, immediatelyTriggerBatch) {
559
582
  const oldTimeout = this.autoBatchTimeout;
@@ -2877,7 +2900,10 @@ class Client {
2877
2900
  * @returns A promise that resolves once all currently pending traces have sent.
2878
2901
  */
2879
2902
  awaitPendingTraceBatches() {
2880
- return Promise.all(this.autoBatchQueue.items.map(({ itemPromise }) => itemPromise));
2903
+ return Promise.all([
2904
+ ...this.autoBatchQueue.items.map(({ itemPromise }) => itemPromise),
2905
+ this.batchIngestCaller.queue.onIdle(),
2906
+ ]);
2881
2907
  }
2882
2908
  }
2883
2909
  exports.Client = Client;
package/dist/client.d.ts CHANGED
@@ -13,6 +13,7 @@ export interface ClientConfig {
13
13
  autoBatchTracing?: boolean;
14
14
  batchSizeBytesLimit?: number;
15
15
  blockOnRootRunFinalization?: boolean;
16
+ traceBatchConcurrency?: number;
16
17
  fetchOptions?: RequestInit;
17
18
  }
18
19
  /**
@@ -204,6 +205,7 @@ export declare class Client {
204
205
  private fetchOptions;
205
206
  private settings;
206
207
  private blockOnRootRunFinalization;
208
+ private traceBatchConcurrency;
207
209
  private _serverInfo;
208
210
  private _getServerInfoPromise?;
209
211
  constructor(config?: ClientConfig);
@@ -226,6 +228,7 @@ export declare class Client {
226
228
  private _filterForSampling;
227
229
  private _getBatchSizeLimitBytes;
228
230
  private drainAutoBatchQueue;
231
+ private processBatch;
229
232
  private processRunOperation;
230
233
  protected _getServerInfo(): Promise<any>;
231
234
  protected _ensureServerInfo(): Promise<Record<string, any>>;
@@ -788,6 +791,6 @@ export declare class Client {
788
791
  *
789
792
  * @returns A promise that resolves once all currently pending traces have sent.
790
793
  */
791
- awaitPendingTraceBatches(): Promise<void[]>;
794
+ awaitPendingTraceBatches(): Promise<[...void[], void]>;
792
795
  }
793
796
  export {};
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as uuid from "uuid";
2
2
  import { AsyncCaller } from "./utils/async_caller.js";
3
3
  import { convertLangChainMessageToExample, isLangChainMessage, } from "./utils/messages.js";
4
- import { getLangChainEnvVarsMetadata, getLangSmithEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
4
+ import { getEnvironmentVariable, getLangChainEnvVarsMetadata, getLangSmithEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
5
5
  import { __version__ } from "./index.js";
6
6
  import { assertUuid } from "./utils/_uuid.js";
7
7
  import { warnOnce } from "./utils/warn.js";
@@ -265,7 +265,13 @@ export class Client {
265
265
  enumerable: true,
266
266
  configurable: true,
267
267
  writable: true,
268
- value: true
268
+ value: getEnvironmentVariable("LANGSMITH_TRACING_BACKGROUND") === "false"
269
+ });
270
+ Object.defineProperty(this, "traceBatchConcurrency", {
271
+ enumerable: true,
272
+ configurable: true,
273
+ writable: true,
274
+ value: 5
269
275
  });
270
276
  Object.defineProperty(this, "_serverInfo", {
271
277
  enumerable: true,
@@ -291,9 +297,16 @@ export class Client {
291
297
  if (this.webUrl?.endsWith("/")) {
292
298
  this.webUrl = this.webUrl.slice(0, -1);
293
299
  }
294
- this.timeout_ms = config.timeout_ms ?? 12_000;
300
+ this.timeout_ms = config.timeout_ms ?? 90_000;
295
301
  this.caller = new AsyncCaller(config.callerOptions ?? {});
302
+ this.traceBatchConcurrency =
303
+ config.traceBatchConcurrency ?? this.traceBatchConcurrency;
304
+ if (this.traceBatchConcurrency < 1) {
305
+ throw new Error("Trace batch concurrency must be positive.");
306
+ }
296
307
  this.batchIngestCaller = new AsyncCaller({
308
+ maxRetries: 2,
309
+ maxConcurrency: this.traceBatchConcurrency,
297
310
  ...(config.callerOptions ?? {}),
298
311
  onFailedResponseHook: handle429,
299
312
  });
@@ -499,33 +512,43 @@ export class Client {
499
512
  DEFAULT_BATCH_SIZE_LIMIT_BYTES);
500
513
  }
501
514
  async drainAutoBatchQueue() {
502
- while (this.autoBatchQueue.items.length >= 0) {
503
- const [batch, done] = this.autoBatchQueue.pop(await this._getBatchSizeLimitBytes());
504
- if (!batch.length) {
505
- done();
506
- return;
507
- }
508
- try {
509
- const ingestParams = {
510
- runCreates: batch
511
- .filter((item) => item.action === "create")
512
- .map((item) => item.item),
513
- runUpdates: batch
514
- .filter((item) => item.action === "update")
515
- .map((item) => item.item),
516
- };
517
- const serverInfo = await this._ensureServerInfo();
518
- if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
519
- await this.multipartIngestRuns(ingestParams);
520
- }
521
- else {
522
- await this.batchIngestRuns(ingestParams);
515
+ const batchSizeLimit = await this._getBatchSizeLimitBytes();
516
+ while (this.autoBatchQueue.items.length > 0) {
517
+ for (let i = 0; i < this.traceBatchConcurrency; i++) {
518
+ const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
519
+ if (!batch.length) {
520
+ done();
521
+ break;
523
522
  }
523
+ await this.processBatch(batch, done);
524
+ }
525
+ }
526
+ }
527
+ async processBatch(batch, done) {
528
+ if (!batch.length) {
529
+ done();
530
+ return;
531
+ }
532
+ try {
533
+ const ingestParams = {
534
+ runCreates: batch
535
+ .filter((item) => item.action === "create")
536
+ .map((item) => item.item),
537
+ runUpdates: batch
538
+ .filter((item) => item.action === "update")
539
+ .map((item) => item.item),
540
+ };
541
+ const serverInfo = await this._ensureServerInfo();
542
+ if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
543
+ await this.multipartIngestRuns(ingestParams);
524
544
  }
525
- finally {
526
- done();
545
+ else {
546
+ await this.batchIngestRuns(ingestParams);
527
547
  }
528
548
  }
549
+ finally {
550
+ done();
551
+ }
529
552
  }
530
553
  async processRunOperation(item, immediatelyTriggerBatch) {
531
554
  const oldTimeout = this.autoBatchTimeout;
@@ -2849,6 +2872,9 @@ export class Client {
2849
2872
  * @returns A promise that resolves once all currently pending traces have sent.
2850
2873
  */
2851
2874
  awaitPendingTraceBatches() {
2852
- return Promise.all(this.autoBatchQueue.items.map(({ itemPromise }) => itemPromise));
2875
+ return Promise.all([
2876
+ ...this.autoBatchQueue.items.map(({ itemPromise }) => itemPromise),
2877
+ this.batchIngestCaller.queue.onIdle(),
2878
+ ]);
2853
2879
  }
2854
2880
  }
package/dist/index.cjs CHANGED
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
8
8
  var fetch_js_1 = require("./singletons/fetch.cjs");
9
9
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
10
10
  // Update using yarn bump-version
11
- exports.__version__ = "0.1.67";
11
+ exports.__version__ = "0.2.0";
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { Client, type ClientConfig } 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
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
- export declare const __version__ = "0.1.67";
5
+ export declare const __version__ = "0.2.0";
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ export { Client } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  // Update using yarn bump-version
5
- export const __version__ = "0.1.67";
5
+ export const __version__ = "0.2.0";
@@ -31,7 +31,7 @@ export interface AsyncCallerCallOptions {
31
31
  export declare class AsyncCaller {
32
32
  protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
33
33
  protected maxRetries: AsyncCallerParams["maxRetries"];
34
- private queue;
34
+ queue: typeof import("p-queue")["default"]["prototype"];
35
35
  private onFailedResponseHook?;
36
36
  constructor(params: AsyncCallerParams);
37
37
  call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.67",
3
+ "version": "0.2.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": [
@@ -109,9 +109,9 @@
109
109
  "@babel/preset-env": "^7.22.4",
110
110
  "@faker-js/faker": "^8.4.1",
111
111
  "@jest/globals": "^29.5.0",
112
- "@langchain/core": "^0.3.1",
113
- "@langchain/langgraph": "^0.2.3",
114
- "@langchain/openai": "^0.3.0",
112
+ "@langchain/core": "^0.3.14",
113
+ "@langchain/langgraph": "^0.2.18",
114
+ "@langchain/openai": "^0.3.11",
115
115
  "@tsconfig/recommended": "^1.0.2",
116
116
  "@types/jest": "^29.5.1",
117
117
  "@typescript-eslint/eslint-plugin": "^5.59.8",
@@ -126,7 +126,7 @@
126
126
  "eslint-plugin-no-instanceof": "^1.0.1",
127
127
  "eslint-plugin-prettier": "^4.2.1",
128
128
  "jest": "^29.5.0",
129
- "langchain": "^0.3.2",
129
+ "langchain": "^0.3.3",
130
130
  "openai": "^4.67.3",
131
131
  "prettier": "^2.8.8",
132
132
  "ts-jest": "^29.1.0",