langsmith 0.1.6 → 0.1.7
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 +54 -7
- package/dist/client.d.ts +4 -0
- package/dist/client.js +53 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.Client = exports.Queue = void 0;
|
|
26
|
+
exports.Client = exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = exports.Queue = void 0;
|
|
27
27
|
const uuid = __importStar(require("uuid"));
|
|
28
28
|
const async_caller_js_1 = require("./utils/async_caller.cjs");
|
|
29
29
|
const messages_js_1 = require("./utils/messages.cjs");
|
|
@@ -147,6 +147,8 @@ class Queue {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
exports.Queue = Queue;
|
|
150
|
+
// 20 MB
|
|
151
|
+
exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20971520;
|
|
150
152
|
class Client {
|
|
151
153
|
constructor(config = {}) {
|
|
152
154
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -257,6 +259,12 @@ class Client {
|
|
|
257
259
|
writable: true,
|
|
258
260
|
value: 50
|
|
259
261
|
});
|
|
262
|
+
Object.defineProperty(this, "serverInfo", {
|
|
263
|
+
enumerable: true,
|
|
264
|
+
configurable: true,
|
|
265
|
+
writable: true,
|
|
266
|
+
value: void 0
|
|
267
|
+
});
|
|
260
268
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
261
269
|
this.tracingSampleRate = getTracingSamplingRate();
|
|
262
270
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
@@ -479,7 +487,7 @@ class Client {
|
|
|
479
487
|
}
|
|
480
488
|
return itemPromise;
|
|
481
489
|
}
|
|
482
|
-
async
|
|
490
|
+
async _getServerInfo() {
|
|
483
491
|
const response = await fetch(`${this.apiUrl}/info`, {
|
|
484
492
|
method: "GET",
|
|
485
493
|
headers: { Accept: "application/json" },
|
|
@@ -489,6 +497,15 @@ class Client {
|
|
|
489
497
|
// consume the response body to release the connection
|
|
490
498
|
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
491
499
|
await response.text();
|
|
500
|
+
throw new Error("Failed to retrieve server info.");
|
|
501
|
+
}
|
|
502
|
+
return response.json();
|
|
503
|
+
}
|
|
504
|
+
async batchEndpointIsSupported() {
|
|
505
|
+
try {
|
|
506
|
+
this.serverInfo = await this._getServerInfo();
|
|
507
|
+
}
|
|
508
|
+
catch (e) {
|
|
492
509
|
return false;
|
|
493
510
|
}
|
|
494
511
|
return true;
|
|
@@ -558,11 +575,11 @@ class Client {
|
|
|
558
575
|
preparedCreateParams = Object.values(createById);
|
|
559
576
|
preparedUpdateParams = standaloneUpdates;
|
|
560
577
|
}
|
|
561
|
-
const
|
|
578
|
+
const rawBatch = {
|
|
562
579
|
post: this._filterForSampling(preparedCreateParams),
|
|
563
580
|
patch: this._filterForSampling(preparedUpdateParams, true),
|
|
564
581
|
};
|
|
565
|
-
if (!
|
|
582
|
+
if (!rawBatch.post.length && !rawBatch.patch.length) {
|
|
566
583
|
return;
|
|
567
584
|
}
|
|
568
585
|
preparedCreateParams = await mergeRuntimeEnvIntoRunCreates(preparedCreateParams);
|
|
@@ -571,16 +588,46 @@ class Client {
|
|
|
571
588
|
}
|
|
572
589
|
if (!this.batchEndpointSupported) {
|
|
573
590
|
this.autoBatchTracing = false;
|
|
574
|
-
for (const preparedCreateParam of
|
|
591
|
+
for (const preparedCreateParam of rawBatch.post) {
|
|
575
592
|
await this.createRun(preparedCreateParam);
|
|
576
593
|
}
|
|
577
|
-
for (const preparedUpdateParam of
|
|
594
|
+
for (const preparedUpdateParam of rawBatch.patch) {
|
|
578
595
|
if (preparedUpdateParam.id !== undefined) {
|
|
579
596
|
await this.updateRun(preparedUpdateParam.id, preparedUpdateParam);
|
|
580
597
|
}
|
|
581
598
|
}
|
|
582
599
|
return;
|
|
583
600
|
}
|
|
601
|
+
const sizeLimitBytes = this.serverInfo?.batch_ingest_config?.size_limit_bytes ??
|
|
602
|
+
exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES;
|
|
603
|
+
const batchChunks = {
|
|
604
|
+
post: [],
|
|
605
|
+
patch: [],
|
|
606
|
+
};
|
|
607
|
+
let currentBatchSizeBytes = 0;
|
|
608
|
+
for (const k of ["post", "patch"]) {
|
|
609
|
+
const key = k;
|
|
610
|
+
const batchItems = rawBatch[key].reverse();
|
|
611
|
+
let batchItem = batchItems.pop();
|
|
612
|
+
while (batchItem !== undefined) {
|
|
613
|
+
const stringifiedBatchItem = JSON.stringify(batchItem);
|
|
614
|
+
if (currentBatchSizeBytes > 0 &&
|
|
615
|
+
currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
|
|
616
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
617
|
+
currentBatchSizeBytes = 0;
|
|
618
|
+
batchChunks.post = [];
|
|
619
|
+
batchChunks.patch = [];
|
|
620
|
+
}
|
|
621
|
+
currentBatchSizeBytes += stringifiedBatchItem.length;
|
|
622
|
+
batchChunks[key].push(batchItem);
|
|
623
|
+
batchItem = batchItems.pop();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
|
|
627
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
async _postBatchIngestRuns(body) {
|
|
584
631
|
const headers = {
|
|
585
632
|
...this.headers,
|
|
586
633
|
"Content-Type": "application/json",
|
|
@@ -589,7 +636,7 @@ class Client {
|
|
|
589
636
|
const response = await this.batchIngestCaller.call(fetch, `${this.apiUrl}/runs/batch`, {
|
|
590
637
|
method: "POST",
|
|
591
638
|
headers,
|
|
592
|
-
body:
|
|
639
|
+
body: body,
|
|
593
640
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
594
641
|
});
|
|
595
642
|
await raiseForStatus(response, "batch create run");
|
package/dist/client.d.ts
CHANGED
|
@@ -72,6 +72,7 @@ export declare class Queue<T> {
|
|
|
72
72
|
push(item: T): Promise<void>;
|
|
73
73
|
pop(upToN: number): [T[], () => void];
|
|
74
74
|
}
|
|
75
|
+
export declare const DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20971520;
|
|
75
76
|
export declare class Client {
|
|
76
77
|
private apiKey?;
|
|
77
78
|
private apiUrl;
|
|
@@ -91,6 +92,7 @@ export declare class Client {
|
|
|
91
92
|
private autoBatchTimeout;
|
|
92
93
|
private autoBatchInitialDelayMs;
|
|
93
94
|
private autoBatchAggregationDelayMs;
|
|
95
|
+
private serverInfo;
|
|
94
96
|
constructor(config?: ClientConfig);
|
|
95
97
|
static getDefaultClientConfig(): {
|
|
96
98
|
apiUrl: string;
|
|
@@ -111,6 +113,7 @@ export declare class Client {
|
|
|
111
113
|
private _filterForSampling;
|
|
112
114
|
private drainAutoBatchQueue;
|
|
113
115
|
private processRunOperation;
|
|
116
|
+
protected _getServerInfo(): Promise<any>;
|
|
114
117
|
protected batchEndpointIsSupported(): Promise<boolean>;
|
|
115
118
|
createRun(run: CreateRunParams): Promise<void>;
|
|
116
119
|
/**
|
|
@@ -121,6 +124,7 @@ export declare class Client {
|
|
|
121
124
|
runCreates?: RunCreate[];
|
|
122
125
|
runUpdates?: RunUpdate[];
|
|
123
126
|
}): Promise<void>;
|
|
127
|
+
private _postBatchIngestRuns;
|
|
124
128
|
updateRun(runId: string, run: RunUpdate): Promise<void>;
|
|
125
129
|
readRun(runId: string, { loadChildRuns }?: {
|
|
126
130
|
loadChildRuns: boolean;
|
package/dist/client.js
CHANGED
|
@@ -120,6 +120,8 @@ export class Queue {
|
|
|
120
120
|
return [popped.map((it) => it[0]), () => popped.forEach((it) => it[1]())];
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
|
+
// 20 MB
|
|
124
|
+
export const DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20971520;
|
|
123
125
|
export class Client {
|
|
124
126
|
constructor(config = {}) {
|
|
125
127
|
Object.defineProperty(this, "apiKey", {
|
|
@@ -230,6 +232,12 @@ export class Client {
|
|
|
230
232
|
writable: true,
|
|
231
233
|
value: 50
|
|
232
234
|
});
|
|
235
|
+
Object.defineProperty(this, "serverInfo", {
|
|
236
|
+
enumerable: true,
|
|
237
|
+
configurable: true,
|
|
238
|
+
writable: true,
|
|
239
|
+
value: void 0
|
|
240
|
+
});
|
|
233
241
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
234
242
|
this.tracingSampleRate = getTracingSamplingRate();
|
|
235
243
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
@@ -452,7 +460,7 @@ export class Client {
|
|
|
452
460
|
}
|
|
453
461
|
return itemPromise;
|
|
454
462
|
}
|
|
455
|
-
async
|
|
463
|
+
async _getServerInfo() {
|
|
456
464
|
const response = await fetch(`${this.apiUrl}/info`, {
|
|
457
465
|
method: "GET",
|
|
458
466
|
headers: { Accept: "application/json" },
|
|
@@ -462,6 +470,15 @@ export class Client {
|
|
|
462
470
|
// consume the response body to release the connection
|
|
463
471
|
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
464
472
|
await response.text();
|
|
473
|
+
throw new Error("Failed to retrieve server info.");
|
|
474
|
+
}
|
|
475
|
+
return response.json();
|
|
476
|
+
}
|
|
477
|
+
async batchEndpointIsSupported() {
|
|
478
|
+
try {
|
|
479
|
+
this.serverInfo = await this._getServerInfo();
|
|
480
|
+
}
|
|
481
|
+
catch (e) {
|
|
465
482
|
return false;
|
|
466
483
|
}
|
|
467
484
|
return true;
|
|
@@ -531,11 +548,11 @@ export class Client {
|
|
|
531
548
|
preparedCreateParams = Object.values(createById);
|
|
532
549
|
preparedUpdateParams = standaloneUpdates;
|
|
533
550
|
}
|
|
534
|
-
const
|
|
551
|
+
const rawBatch = {
|
|
535
552
|
post: this._filterForSampling(preparedCreateParams),
|
|
536
553
|
patch: this._filterForSampling(preparedUpdateParams, true),
|
|
537
554
|
};
|
|
538
|
-
if (!
|
|
555
|
+
if (!rawBatch.post.length && !rawBatch.patch.length) {
|
|
539
556
|
return;
|
|
540
557
|
}
|
|
541
558
|
preparedCreateParams = await mergeRuntimeEnvIntoRunCreates(preparedCreateParams);
|
|
@@ -544,16 +561,46 @@ export class Client {
|
|
|
544
561
|
}
|
|
545
562
|
if (!this.batchEndpointSupported) {
|
|
546
563
|
this.autoBatchTracing = false;
|
|
547
|
-
for (const preparedCreateParam of
|
|
564
|
+
for (const preparedCreateParam of rawBatch.post) {
|
|
548
565
|
await this.createRun(preparedCreateParam);
|
|
549
566
|
}
|
|
550
|
-
for (const preparedUpdateParam of
|
|
567
|
+
for (const preparedUpdateParam of rawBatch.patch) {
|
|
551
568
|
if (preparedUpdateParam.id !== undefined) {
|
|
552
569
|
await this.updateRun(preparedUpdateParam.id, preparedUpdateParam);
|
|
553
570
|
}
|
|
554
571
|
}
|
|
555
572
|
return;
|
|
556
573
|
}
|
|
574
|
+
const sizeLimitBytes = this.serverInfo?.batch_ingest_config?.size_limit_bytes ??
|
|
575
|
+
DEFAULT_BATCH_SIZE_LIMIT_BYTES;
|
|
576
|
+
const batchChunks = {
|
|
577
|
+
post: [],
|
|
578
|
+
patch: [],
|
|
579
|
+
};
|
|
580
|
+
let currentBatchSizeBytes = 0;
|
|
581
|
+
for (const k of ["post", "patch"]) {
|
|
582
|
+
const key = k;
|
|
583
|
+
const batchItems = rawBatch[key].reverse();
|
|
584
|
+
let batchItem = batchItems.pop();
|
|
585
|
+
while (batchItem !== undefined) {
|
|
586
|
+
const stringifiedBatchItem = JSON.stringify(batchItem);
|
|
587
|
+
if (currentBatchSizeBytes > 0 &&
|
|
588
|
+
currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
|
|
589
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
590
|
+
currentBatchSizeBytes = 0;
|
|
591
|
+
batchChunks.post = [];
|
|
592
|
+
batchChunks.patch = [];
|
|
593
|
+
}
|
|
594
|
+
currentBatchSizeBytes += stringifiedBatchItem.length;
|
|
595
|
+
batchChunks[key].push(batchItem);
|
|
596
|
+
batchItem = batchItems.pop();
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
|
|
600
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async _postBatchIngestRuns(body) {
|
|
557
604
|
const headers = {
|
|
558
605
|
...this.headers,
|
|
559
606
|
"Content-Type": "application/json",
|
|
@@ -562,7 +609,7 @@ export class Client {
|
|
|
562
609
|
const response = await this.batchIngestCaller.call(fetch, `${this.apiUrl}/runs/batch`, {
|
|
563
610
|
method: "POST",
|
|
564
611
|
headers,
|
|
565
|
-
body:
|
|
612
|
+
body: body,
|
|
566
613
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
567
614
|
});
|
|
568
615
|
await raiseForStatus(response, "batch create run");
|
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.
|
|
9
|
+
exports.__version__ = "0.1.7";
|
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, } from "./schemas.js";
|
|
3
3
|
export { RunTree, type RunTreeConfig } from "./run_trees.js";
|
|
4
|
-
export declare const __version__ = "0.1.
|
|
4
|
+
export declare const __version__ = "0.1.7";
|
package/dist/index.js
CHANGED