langsmith 0.3.62-rc.2 → 0.3.63
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 +627 -424
- package/dist/client.d.ts +7 -1
- package/dist/client.js +626 -423
- package/dist/evaluation/evaluate_comparative.cjs +1 -0
- package/dist/evaluation/evaluate_comparative.d.ts +1 -0
- package/dist/evaluation/evaluate_comparative.js +1 -0
- package/dist/experimental/vercel/index.cjs +120 -21
- package/dist/experimental/vercel/index.d.ts +211 -1
- package/dist/experimental/vercel/index.js +119 -21
- package/dist/experimental/vercel/middleware.cjs +17 -8
- package/dist/experimental/vercel/middleware.d.ts +19 -2
- package/dist/experimental/vercel/middleware.js +17 -8
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/langchain.cjs +4 -0
- package/dist/langchain.d.ts +1 -0
- package/dist/langchain.js +4 -0
- package/dist/run_trees.cjs +17 -5
- package/dist/run_trees.d.ts +3 -1
- package/dist/run_trees.js +17 -5
- package/dist/singletons/fetch.cjs +5 -1
- package/dist/singletons/fetch.d.ts +1 -0
- package/dist/singletons/fetch.js +3 -0
- package/dist/traceable.cjs +24 -11
- package/dist/traceable.js +24 -11
- package/dist/utils/async_caller.cjs +15 -35
- package/dist/utils/async_caller.d.ts +0 -2
- package/dist/utils/async_caller.js +15 -35
- package/dist/utils/error.cjs +4 -4
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/error.js +4 -4
- package/package.json +2 -2
package/dist/client.js
CHANGED
|
@@ -164,11 +164,13 @@ export class AutoBatchQueue {
|
|
|
164
164
|
];
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const SERVER_INFO_REQUEST_TIMEOUT = 2500;
|
|
167
|
+
export const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
|
|
168
|
+
const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
|
|
170
169
|
const DEFAULT_API_URL = "https://api.smith.langchain.com";
|
|
171
170
|
export class Client {
|
|
171
|
+
get _fetch() {
|
|
172
|
+
return this.fetchImplementation || _getFetchImplementation(this.debug);
|
|
173
|
+
}
|
|
172
174
|
constructor(config = {}) {
|
|
173
175
|
Object.defineProperty(this, "apiKey", {
|
|
174
176
|
enumerable: true,
|
|
@@ -315,6 +317,12 @@ export class Client {
|
|
|
315
317
|
writable: true,
|
|
316
318
|
value: void 0
|
|
317
319
|
});
|
|
320
|
+
Object.defineProperty(this, "fetchImplementation", {
|
|
321
|
+
enumerable: true,
|
|
322
|
+
configurable: true,
|
|
323
|
+
writable: true,
|
|
324
|
+
value: void 0
|
|
325
|
+
});
|
|
318
326
|
Object.defineProperty(this, "multipartStreamingDisabled", {
|
|
319
327
|
enumerable: true,
|
|
320
328
|
configurable: true,
|
|
@@ -341,6 +349,7 @@ export class Client {
|
|
|
341
349
|
this.timeout_ms = config.timeout_ms ?? 90_000;
|
|
342
350
|
this.caller = new AsyncCaller({
|
|
343
351
|
...(config.callerOptions ?? {}),
|
|
352
|
+
maxRetries: 4,
|
|
344
353
|
debug: config.debug ?? this.debug,
|
|
345
354
|
});
|
|
346
355
|
this.traceBatchConcurrency =
|
|
@@ -349,6 +358,7 @@ export class Client {
|
|
|
349
358
|
throw new Error("Trace batch concurrency must be positive.");
|
|
350
359
|
}
|
|
351
360
|
this.debug = config.debug ?? this.debug;
|
|
361
|
+
this.fetchImplementation = config.fetchImplementation;
|
|
352
362
|
this.batchIngestCaller = new AsyncCaller({
|
|
353
363
|
maxRetries: 2,
|
|
354
364
|
maxConcurrency: this.traceBatchConcurrency,
|
|
@@ -468,13 +478,16 @@ export class Client {
|
|
|
468
478
|
async _getResponse(path, queryParams) {
|
|
469
479
|
const paramsString = queryParams?.toString() ?? "";
|
|
470
480
|
const url = `${this.apiUrl}${path}?${paramsString}`;
|
|
471
|
-
const response = await this.caller.call(
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
481
|
+
const response = await this.caller.call(async () => {
|
|
482
|
+
const res = await this._fetch(url, {
|
|
483
|
+
method: "GET",
|
|
484
|
+
headers: this.headers,
|
|
485
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
486
|
+
...this.fetchOptions,
|
|
487
|
+
});
|
|
488
|
+
await raiseForStatus(res, `Failed to fetch ${path}`);
|
|
489
|
+
return res;
|
|
476
490
|
});
|
|
477
|
-
await raiseForStatus(response, `Failed to fetch ${path}`);
|
|
478
491
|
return response;
|
|
479
492
|
}
|
|
480
493
|
async _get(path, queryParams) {
|
|
@@ -488,13 +501,16 @@ export class Client {
|
|
|
488
501
|
queryParams.set("offset", String(offset));
|
|
489
502
|
queryParams.set("limit", String(limit));
|
|
490
503
|
const url = `${this.apiUrl}${path}?${queryParams}`;
|
|
491
|
-
const response = await this.caller.call(
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
504
|
+
const response = await this.caller.call(async () => {
|
|
505
|
+
const res = await this._fetch(url, {
|
|
506
|
+
method: "GET",
|
|
507
|
+
headers: this.headers,
|
|
508
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
509
|
+
...this.fetchOptions,
|
|
510
|
+
});
|
|
511
|
+
await raiseForStatus(res, `Failed to fetch ${path}`);
|
|
512
|
+
return res;
|
|
496
513
|
});
|
|
497
|
-
await raiseForStatus(response, `Failed to fetch ${path}`);
|
|
498
514
|
const items = transform
|
|
499
515
|
? transform(await response.json())
|
|
500
516
|
: await response.json();
|
|
@@ -511,12 +527,17 @@ export class Client {
|
|
|
511
527
|
async *_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
|
|
512
528
|
const bodyParams = body ? { ...body } : {};
|
|
513
529
|
while (true) {
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
530
|
+
const body = JSON.stringify(bodyParams);
|
|
531
|
+
const response = await this.caller.call(async () => {
|
|
532
|
+
const res = await this._fetch(`${this.apiUrl}${path}`, {
|
|
533
|
+
method: requestMethod,
|
|
534
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
535
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
536
|
+
...this.fetchOptions,
|
|
537
|
+
body,
|
|
538
|
+
});
|
|
539
|
+
await raiseForStatus(res, `Failed to fetch ${path}`);
|
|
540
|
+
return res;
|
|
520
541
|
});
|
|
521
542
|
const responseBody = await response.json();
|
|
522
543
|
if (!responseBody) {
|
|
@@ -589,7 +610,7 @@ export class Client {
|
|
|
589
610
|
const serverInfo = await this._ensureServerInfo();
|
|
590
611
|
return (this.batchSizeBytesLimit ??
|
|
591
612
|
serverInfo.batch_ingest_config?.size_limit_bytes ??
|
|
592
|
-
|
|
613
|
+
DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES);
|
|
593
614
|
}
|
|
594
615
|
async _getDatasetExamplesMultiPartSupport() {
|
|
595
616
|
const serverInfo = await this._ensureServerInfo();
|
|
@@ -647,7 +668,7 @@ export class Client {
|
|
|
647
668
|
};
|
|
648
669
|
const serverInfo = await this._ensureServerInfo();
|
|
649
670
|
if (serverInfo?.batch_ingest_config?.use_multipart_endpoint) {
|
|
650
|
-
const useGzip = serverInfo?.
|
|
671
|
+
const useGzip = serverInfo?.instance_flags?.gzip_body_enabled;
|
|
651
672
|
await this.multipartIngestRuns(ingestParams, { ...options, useGzip });
|
|
652
673
|
}
|
|
653
674
|
else {
|
|
@@ -710,10 +731,10 @@ export class Client {
|
|
|
710
731
|
}
|
|
711
732
|
async _getServerInfo() {
|
|
712
733
|
const response = await this.caller.call(async () => {
|
|
713
|
-
const res = await
|
|
734
|
+
const res = await this._fetch(`${this.apiUrl}/info`, {
|
|
714
735
|
method: "GET",
|
|
715
736
|
headers: { Accept: "application/json" },
|
|
716
|
-
signal: AbortSignal.timeout(
|
|
737
|
+
signal: AbortSignal.timeout(SERVER_INFO_REQUEST_TIMEOUT_MS),
|
|
717
738
|
...this.fetchOptions,
|
|
718
739
|
});
|
|
719
740
|
await raiseForStatus(res, "get server info");
|
|
@@ -735,7 +756,7 @@ export class Client {
|
|
|
735
756
|
this._serverInfo = await this._getServerInfo();
|
|
736
757
|
}
|
|
737
758
|
catch (e) {
|
|
738
|
-
console.warn(`[
|
|
759
|
+
console.warn(`[LANGSMITH]: Failed to fetch info on supported operations. Falling back to batch operations and default limits. Info: ${e.status ?? "Unspecified status code"} ${e.message}`);
|
|
739
760
|
}
|
|
740
761
|
}
|
|
741
762
|
return this._serverInfo ?? {};
|
|
@@ -804,14 +825,18 @@ export class Client {
|
|
|
804
825
|
if (options?.apiKey !== undefined) {
|
|
805
826
|
headers["x-api-key"] = options.apiKey;
|
|
806
827
|
}
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
828
|
+
const body = serializePayloadForTracing(mergedRunCreateParam, `Creating run with id: ${mergedRunCreateParam.id}`);
|
|
829
|
+
await this.caller.call(async () => {
|
|
830
|
+
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs`, {
|
|
831
|
+
method: "POST",
|
|
832
|
+
headers,
|
|
833
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
834
|
+
...this.fetchOptions,
|
|
835
|
+
body,
|
|
836
|
+
});
|
|
837
|
+
await raiseForStatus(res, "create run", true);
|
|
838
|
+
return res;
|
|
813
839
|
});
|
|
814
|
-
await raiseForStatus(response, "create run", true);
|
|
815
840
|
}
|
|
816
841
|
/**
|
|
817
842
|
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
@@ -884,14 +909,17 @@ export class Client {
|
|
|
884
909
|
if (options?.apiKey !== undefined) {
|
|
885
910
|
headers["x-api-key"] = options.apiKey;
|
|
886
911
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
912
|
+
await this.batchIngestCaller.call(async () => {
|
|
913
|
+
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/batch`, {
|
|
914
|
+
method: "POST",
|
|
915
|
+
headers,
|
|
916
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
917
|
+
...this.fetchOptions,
|
|
918
|
+
body,
|
|
919
|
+
});
|
|
920
|
+
await raiseForStatus(res, "batch create run", true);
|
|
921
|
+
return res;
|
|
893
922
|
});
|
|
894
|
-
await raiseForStatus(response, "batch create run", true);
|
|
895
923
|
}
|
|
896
924
|
/**
|
|
897
925
|
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
@@ -1095,27 +1123,33 @@ export class Client {
|
|
|
1095
1123
|
const isNodeFetch = _globalFetchImplementationIsNodeFetch();
|
|
1096
1124
|
const buildBuffered = () => this._createNodeFetchBody(parts, boundary);
|
|
1097
1125
|
const buildStream = () => this._createMultipartStream(parts, boundary);
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1126
|
+
const sendWithRetry = async (bodyFactory) => {
|
|
1127
|
+
return this.batchIngestCaller.call(async () => {
|
|
1128
|
+
const body = await bodyFactory();
|
|
1129
|
+
const headers = {
|
|
1130
|
+
...this.headers,
|
|
1131
|
+
"Content-Type": `multipart/form-data; boundary=${boundary}`,
|
|
1132
|
+
};
|
|
1133
|
+
if (options?.apiKey !== undefined) {
|
|
1134
|
+
headers["x-api-key"] = options.apiKey;
|
|
1135
|
+
}
|
|
1136
|
+
let transformedBody = body;
|
|
1137
|
+
if (options?.useGzip &&
|
|
1138
|
+
typeof body === "object" &&
|
|
1139
|
+
"pipeThrough" in body) {
|
|
1140
|
+
transformedBody = body.pipeThrough(new CompressionStream("gzip"));
|
|
1141
|
+
headers["Content-Encoding"] = "gzip";
|
|
1142
|
+
}
|
|
1143
|
+
const response = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/multipart`, {
|
|
1144
|
+
method: "POST",
|
|
1145
|
+
headers,
|
|
1146
|
+
body: transformedBody,
|
|
1147
|
+
duplex: "half",
|
|
1148
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1149
|
+
...this.fetchOptions,
|
|
1150
|
+
});
|
|
1151
|
+
await raiseForStatus(response, `Failed to send multipart request`, true);
|
|
1152
|
+
return response;
|
|
1119
1153
|
});
|
|
1120
1154
|
};
|
|
1121
1155
|
try {
|
|
@@ -1124,10 +1158,10 @@ export class Client {
|
|
|
1124
1158
|
// attempt stream only if not disabled and not using node-fetch
|
|
1125
1159
|
if (!isNodeFetch && !this.multipartStreamingDisabled) {
|
|
1126
1160
|
streamedAttempt = true;
|
|
1127
|
-
res = await
|
|
1161
|
+
res = await sendWithRetry(buildStream);
|
|
1128
1162
|
}
|
|
1129
1163
|
else {
|
|
1130
|
-
res = await
|
|
1164
|
+
res = await sendWithRetry(buildBuffered);
|
|
1131
1165
|
}
|
|
1132
1166
|
// if stream fails, fallback to buffered body
|
|
1133
1167
|
if ((!this.multipartStreamingDisabled || streamedAttempt) &&
|
|
@@ -1139,10 +1173,8 @@ export class Client {
|
|
|
1139
1173
|
// Disable streaming for future requests
|
|
1140
1174
|
this.multipartStreamingDisabled = true;
|
|
1141
1175
|
// retry with fully-buffered body
|
|
1142
|
-
res = await
|
|
1176
|
+
res = await sendWithRetry(buildBuffered);
|
|
1143
1177
|
}
|
|
1144
|
-
// raise if still failing
|
|
1145
|
-
await raiseForStatus(res, "ingest multipart runs", true);
|
|
1146
1178
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1147
1179
|
}
|
|
1148
1180
|
catch (e) {
|
|
@@ -1199,14 +1231,18 @@ export class Client {
|
|
|
1199
1231
|
if (options?.apiKey !== undefined) {
|
|
1200
1232
|
headers["x-api-key"] = options.apiKey;
|
|
1201
1233
|
}
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1234
|
+
const body = serializePayloadForTracing(run, `Serializing payload to update run with id: ${runId}`);
|
|
1235
|
+
await this.caller.call(async () => {
|
|
1236
|
+
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
|
|
1237
|
+
method: "PATCH",
|
|
1238
|
+
headers,
|
|
1239
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1240
|
+
...this.fetchOptions,
|
|
1241
|
+
body,
|
|
1242
|
+
});
|
|
1243
|
+
await raiseForStatus(res, "update run", true);
|
|
1244
|
+
return res;
|
|
1208
1245
|
});
|
|
1209
|
-
await raiseForStatus(response, "update run", true);
|
|
1210
1246
|
}
|
|
1211
1247
|
async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
1212
1248
|
assertUuid(runId);
|
|
@@ -1464,14 +1500,18 @@ export class Client {
|
|
|
1464
1500
|
};
|
|
1465
1501
|
// Remove undefined values from the payload
|
|
1466
1502
|
const filteredPayload = Object.fromEntries(Object.entries(currentBody).filter(([_, value]) => value !== undefined));
|
|
1467
|
-
const
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1503
|
+
const body = JSON.stringify(filteredPayload);
|
|
1504
|
+
const response = await this.caller.call(async () => {
|
|
1505
|
+
const res = await this._fetch(url, {
|
|
1506
|
+
method: "POST",
|
|
1507
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1508
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1509
|
+
...this.fetchOptions,
|
|
1510
|
+
body,
|
|
1511
|
+
});
|
|
1512
|
+
await raiseForStatus(res, `Failed to fetch ${path}`);
|
|
1513
|
+
return res;
|
|
1473
1514
|
});
|
|
1474
|
-
await raiseForStatus(response, `Failed to fetch ${path}`);
|
|
1475
1515
|
const items = await response.json();
|
|
1476
1516
|
const { groups, total } = items;
|
|
1477
1517
|
if (groups.length === 0) {
|
|
@@ -1513,12 +1553,17 @@ export class Client {
|
|
|
1513
1553
|
};
|
|
1514
1554
|
// Remove undefined values from the payload
|
|
1515
1555
|
const filteredPayload = Object.fromEntries(Object.entries(payload).filter(([_, value]) => value !== undefined));
|
|
1516
|
-
const
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1556
|
+
const body = JSON.stringify(filteredPayload);
|
|
1557
|
+
const response = await this.caller.call(async () => {
|
|
1558
|
+
const res = await this._fetch(`${this.apiUrl}/runs/stats`, {
|
|
1559
|
+
method: "POST",
|
|
1560
|
+
headers: this.headers,
|
|
1561
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1562
|
+
...this.fetchOptions,
|
|
1563
|
+
body,
|
|
1564
|
+
});
|
|
1565
|
+
await raiseForStatus(res, "get run stats");
|
|
1566
|
+
return res;
|
|
1522
1567
|
});
|
|
1523
1568
|
const result = await response.json();
|
|
1524
1569
|
return result;
|
|
@@ -1529,12 +1574,17 @@ export class Client {
|
|
|
1529
1574
|
share_token: shareId || uuid.v4(),
|
|
1530
1575
|
};
|
|
1531
1576
|
assertUuid(runId);
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1577
|
+
const body = JSON.stringify(data);
|
|
1578
|
+
const response = await this.caller.call(async () => {
|
|
1579
|
+
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
1580
|
+
method: "PUT",
|
|
1581
|
+
headers: this.headers,
|
|
1582
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1583
|
+
...this.fetchOptions,
|
|
1584
|
+
body,
|
|
1585
|
+
});
|
|
1586
|
+
await raiseForStatus(res, "share run");
|
|
1587
|
+
return res;
|
|
1538
1588
|
});
|
|
1539
1589
|
const result = await response.json();
|
|
1540
1590
|
if (result === null || !("share_token" in result)) {
|
|
@@ -1544,21 +1594,28 @@ export class Client {
|
|
|
1544
1594
|
}
|
|
1545
1595
|
async unshareRun(runId) {
|
|
1546
1596
|
assertUuid(runId);
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1597
|
+
await this.caller.call(async () => {
|
|
1598
|
+
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
1599
|
+
method: "DELETE",
|
|
1600
|
+
headers: this.headers,
|
|
1601
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1602
|
+
...this.fetchOptions,
|
|
1603
|
+
});
|
|
1604
|
+
await raiseForStatus(res, "unshare run", true);
|
|
1605
|
+
return res;
|
|
1552
1606
|
});
|
|
1553
|
-
await raiseForStatus(response, "unshare run", true);
|
|
1554
1607
|
}
|
|
1555
1608
|
async readRunSharedLink(runId) {
|
|
1556
1609
|
assertUuid(runId);
|
|
1557
|
-
const response = await this.caller.call(
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1610
|
+
const response = await this.caller.call(async () => {
|
|
1611
|
+
const res = await this._fetch(`${this.apiUrl}/runs/${runId}/share`, {
|
|
1612
|
+
method: "GET",
|
|
1613
|
+
headers: this.headers,
|
|
1614
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1615
|
+
...this.fetchOptions,
|
|
1616
|
+
});
|
|
1617
|
+
await raiseForStatus(res, "read run shared link");
|
|
1618
|
+
return res;
|
|
1562
1619
|
});
|
|
1563
1620
|
const result = await response.json();
|
|
1564
1621
|
if (result === null || !("share_token" in result)) {
|
|
@@ -1576,11 +1633,15 @@ export class Client {
|
|
|
1576
1633
|
}
|
|
1577
1634
|
}
|
|
1578
1635
|
assertUuid(shareToken);
|
|
1579
|
-
const response = await this.caller.call(
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1636
|
+
const response = await this.caller.call(async () => {
|
|
1637
|
+
const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/runs${queryParams}`, {
|
|
1638
|
+
method: "GET",
|
|
1639
|
+
headers: this.headers,
|
|
1640
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1641
|
+
...this.fetchOptions,
|
|
1642
|
+
});
|
|
1643
|
+
await raiseForStatus(res, "list shared runs");
|
|
1644
|
+
return res;
|
|
1584
1645
|
});
|
|
1585
1646
|
const runs = await response.json();
|
|
1586
1647
|
return runs;
|
|
@@ -1594,11 +1655,15 @@ export class Client {
|
|
|
1594
1655
|
datasetId = dataset.id;
|
|
1595
1656
|
}
|
|
1596
1657
|
assertUuid(datasetId);
|
|
1597
|
-
const response = await this.caller.call(
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1658
|
+
const response = await this.caller.call(async () => {
|
|
1659
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
|
|
1660
|
+
method: "GET",
|
|
1661
|
+
headers: this.headers,
|
|
1662
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1663
|
+
...this.fetchOptions,
|
|
1664
|
+
});
|
|
1665
|
+
await raiseForStatus(res, "read dataset shared schema");
|
|
1666
|
+
return res;
|
|
1602
1667
|
});
|
|
1603
1668
|
const shareSchema = await response.json();
|
|
1604
1669
|
shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
|
|
@@ -1616,12 +1681,17 @@ export class Client {
|
|
|
1616
1681
|
dataset_id: datasetId,
|
|
1617
1682
|
};
|
|
1618
1683
|
assertUuid(datasetId);
|
|
1619
|
-
const
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1684
|
+
const body = JSON.stringify(data);
|
|
1685
|
+
const response = await this.caller.call(async () => {
|
|
1686
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
|
|
1687
|
+
method: "PUT",
|
|
1688
|
+
headers: this.headers,
|
|
1689
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1690
|
+
...this.fetchOptions,
|
|
1691
|
+
body,
|
|
1692
|
+
});
|
|
1693
|
+
await raiseForStatus(res, "share dataset");
|
|
1694
|
+
return res;
|
|
1625
1695
|
});
|
|
1626
1696
|
const shareSchema = await response.json();
|
|
1627
1697
|
shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
|
|
@@ -1629,21 +1699,28 @@ export class Client {
|
|
|
1629
1699
|
}
|
|
1630
1700
|
async unshareDataset(datasetId) {
|
|
1631
1701
|
assertUuid(datasetId);
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1702
|
+
await this.caller.call(async () => {
|
|
1703
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/share`, {
|
|
1704
|
+
method: "DELETE",
|
|
1705
|
+
headers: this.headers,
|
|
1706
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1707
|
+
...this.fetchOptions,
|
|
1708
|
+
});
|
|
1709
|
+
await raiseForStatus(res, "unshare dataset", true);
|
|
1710
|
+
return res;
|
|
1637
1711
|
});
|
|
1638
|
-
await raiseForStatus(response, "unshare dataset", true);
|
|
1639
1712
|
}
|
|
1640
1713
|
async readSharedDataset(shareToken) {
|
|
1641
1714
|
assertUuid(shareToken);
|
|
1642
|
-
const response = await this.caller.call(
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1715
|
+
const response = await this.caller.call(async () => {
|
|
1716
|
+
const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/datasets`, {
|
|
1717
|
+
method: "GET",
|
|
1718
|
+
headers: this.headers,
|
|
1719
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1720
|
+
...this.fetchOptions,
|
|
1721
|
+
});
|
|
1722
|
+
await raiseForStatus(res, "read shared dataset");
|
|
1723
|
+
return res;
|
|
1647
1724
|
});
|
|
1648
1725
|
const dataset = await response.json();
|
|
1649
1726
|
return dataset;
|
|
@@ -1670,11 +1747,15 @@ export class Client {
|
|
|
1670
1747
|
urlParams.append(key, value);
|
|
1671
1748
|
}
|
|
1672
1749
|
});
|
|
1673
|
-
const response = await this.caller.call(
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1750
|
+
const response = await this.caller.call(async () => {
|
|
1751
|
+
const res = await this._fetch(`${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
|
|
1752
|
+
method: "GET",
|
|
1753
|
+
headers: this.headers,
|
|
1754
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1755
|
+
...this.fetchOptions,
|
|
1756
|
+
});
|
|
1757
|
+
await raiseForStatus(res, "list shared examples");
|
|
1758
|
+
return res;
|
|
1678
1759
|
});
|
|
1679
1760
|
const result = await response.json();
|
|
1680
1761
|
if (!response.ok) {
|
|
@@ -1705,14 +1786,18 @@ export class Client {
|
|
|
1705
1786
|
if (referenceDatasetId !== null) {
|
|
1706
1787
|
body["reference_dataset_id"] = referenceDatasetId;
|
|
1707
1788
|
}
|
|
1708
|
-
const
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1789
|
+
const serializedBody = JSON.stringify(body);
|
|
1790
|
+
const response = await this.caller.call(async () => {
|
|
1791
|
+
const res = await this._fetch(endpoint, {
|
|
1792
|
+
method: "POST",
|
|
1793
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1794
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1795
|
+
...this.fetchOptions,
|
|
1796
|
+
body: serializedBody,
|
|
1797
|
+
});
|
|
1798
|
+
await raiseForStatus(res, "create project");
|
|
1799
|
+
return res;
|
|
1714
1800
|
});
|
|
1715
|
-
await raiseForStatus(response, "create project");
|
|
1716
1801
|
const result = await response.json();
|
|
1717
1802
|
return result;
|
|
1718
1803
|
}
|
|
@@ -1722,20 +1807,23 @@ export class Client {
|
|
|
1722
1807
|
if (metadata) {
|
|
1723
1808
|
extra = { ...(extra || {}), metadata };
|
|
1724
1809
|
}
|
|
1725
|
-
const body = {
|
|
1810
|
+
const body = JSON.stringify({
|
|
1726
1811
|
name,
|
|
1727
1812
|
extra,
|
|
1728
1813
|
description,
|
|
1729
1814
|
end_time: endTime ? new Date(endTime).toISOString() : null,
|
|
1730
|
-
};
|
|
1731
|
-
const response = await this.caller.call(
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1815
|
+
});
|
|
1816
|
+
const response = await this.caller.call(async () => {
|
|
1817
|
+
const res = await this._fetch(endpoint, {
|
|
1818
|
+
method: "PATCH",
|
|
1819
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1820
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1821
|
+
...this.fetchOptions,
|
|
1822
|
+
body,
|
|
1823
|
+
});
|
|
1824
|
+
await raiseForStatus(res, "update project");
|
|
1825
|
+
return res;
|
|
1826
|
+
});
|
|
1739
1827
|
const result = await response.json();
|
|
1740
1828
|
return result;
|
|
1741
1829
|
}
|
|
@@ -1756,11 +1844,15 @@ export class Client {
|
|
|
1756
1844
|
else {
|
|
1757
1845
|
throw new Error("Must provide projectName or projectId");
|
|
1758
1846
|
}
|
|
1759
|
-
const response = await this.caller.call(
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1847
|
+
const response = await this.caller.call(async () => {
|
|
1848
|
+
const res = await this._fetch(`${this.apiUrl}${path}?${params}`, {
|
|
1849
|
+
method: "GET",
|
|
1850
|
+
headers: this.headers,
|
|
1851
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1852
|
+
...this.fetchOptions,
|
|
1853
|
+
});
|
|
1854
|
+
await raiseForStatus(res, "has project");
|
|
1855
|
+
return res;
|
|
1764
1856
|
});
|
|
1765
1857
|
// consume the response body to release the connection
|
|
1766
1858
|
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
@@ -1886,13 +1978,16 @@ export class Client {
|
|
|
1886
1978
|
projectId_ = projectId;
|
|
1887
1979
|
}
|
|
1888
1980
|
assertUuid(projectId_);
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1981
|
+
await this.caller.call(async () => {
|
|
1982
|
+
const res = await this._fetch(`${this.apiUrl}/sessions/${projectId_}`, {
|
|
1983
|
+
method: "DELETE",
|
|
1984
|
+
headers: this.headers,
|
|
1985
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1986
|
+
...this.fetchOptions,
|
|
1987
|
+
});
|
|
1988
|
+
await raiseForStatus(res, `delete session ${projectId_} (${projectName})`, true);
|
|
1989
|
+
return res;
|
|
1894
1990
|
});
|
|
1895
|
-
await raiseForStatus(response, `delete session ${projectId_} (${projectName})`, true);
|
|
1896
1991
|
}
|
|
1897
1992
|
async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }) {
|
|
1898
1993
|
const url = `${this.apiUrl}/datasets/upload`;
|
|
@@ -1913,14 +2008,17 @@ export class Client {
|
|
|
1913
2008
|
if (name) {
|
|
1914
2009
|
formData.append("name", name);
|
|
1915
2010
|
}
|
|
1916
|
-
const response = await this.caller.call(
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
2011
|
+
const response = await this.caller.call(async () => {
|
|
2012
|
+
const res = await this._fetch(url, {
|
|
2013
|
+
method: "POST",
|
|
2014
|
+
headers: this.headers,
|
|
2015
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2016
|
+
...this.fetchOptions,
|
|
2017
|
+
body: formData,
|
|
2018
|
+
});
|
|
2019
|
+
await raiseForStatus(res, "upload CSV");
|
|
2020
|
+
return res;
|
|
1922
2021
|
});
|
|
1923
|
-
await raiseForStatus(response, "upload CSV");
|
|
1924
2022
|
const result = await response.json();
|
|
1925
2023
|
return result;
|
|
1926
2024
|
}
|
|
@@ -1939,14 +2037,18 @@ export class Client {
|
|
|
1939
2037
|
if (outputsSchema) {
|
|
1940
2038
|
body.outputs_schema_definition = outputsSchema;
|
|
1941
2039
|
}
|
|
1942
|
-
const
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2040
|
+
const serializedBody = JSON.stringify(body);
|
|
2041
|
+
const response = await this.caller.call(async () => {
|
|
2042
|
+
const res = await this._fetch(`${this.apiUrl}/datasets`, {
|
|
2043
|
+
method: "POST",
|
|
2044
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2045
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2046
|
+
...this.fetchOptions,
|
|
2047
|
+
body: serializedBody,
|
|
2048
|
+
});
|
|
2049
|
+
await raiseForStatus(res, "create dataset");
|
|
2050
|
+
return res;
|
|
1948
2051
|
});
|
|
1949
|
-
await raiseForStatus(response, "create dataset");
|
|
1950
2052
|
const result = await response.json();
|
|
1951
2053
|
return result;
|
|
1952
2054
|
}
|
|
@@ -2071,14 +2173,18 @@ export class Client {
|
|
|
2071
2173
|
}
|
|
2072
2174
|
const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
|
|
2073
2175
|
assertUuid(_datasetId);
|
|
2074
|
-
const
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2176
|
+
const body = JSON.stringify(update);
|
|
2177
|
+
const response = await this.caller.call(async () => {
|
|
2178
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}`, {
|
|
2179
|
+
method: "PATCH",
|
|
2180
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2181
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2182
|
+
...this.fetchOptions,
|
|
2183
|
+
body,
|
|
2184
|
+
});
|
|
2185
|
+
await raiseForStatus(res, "update dataset");
|
|
2186
|
+
return res;
|
|
2187
|
+
});
|
|
2082
2188
|
return (await response.json());
|
|
2083
2189
|
}
|
|
2084
2190
|
/**
|
|
@@ -2103,17 +2209,21 @@ export class Client {
|
|
|
2103
2209
|
}
|
|
2104
2210
|
const _datasetId = datasetId ?? (await this.readDataset({ datasetName })).id;
|
|
2105
2211
|
assertUuid(_datasetId);
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2212
|
+
const body = JSON.stringify({
|
|
2213
|
+
as_of: typeof asOf === "string" ? asOf : asOf.toISOString(),
|
|
2214
|
+
tag,
|
|
2215
|
+
});
|
|
2216
|
+
await this.caller.call(async () => {
|
|
2217
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${_datasetId}/tags`, {
|
|
2218
|
+
method: "PUT",
|
|
2219
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2220
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2221
|
+
...this.fetchOptions,
|
|
2222
|
+
body,
|
|
2223
|
+
});
|
|
2224
|
+
await raiseForStatus(res, "update dataset tags", true);
|
|
2225
|
+
return res;
|
|
2115
2226
|
});
|
|
2116
|
-
await raiseForStatus(response, "update dataset tags");
|
|
2117
2227
|
}
|
|
2118
2228
|
async deleteDataset({ datasetId, datasetName, }) {
|
|
2119
2229
|
let path = "/datasets";
|
|
@@ -2132,14 +2242,16 @@ export class Client {
|
|
|
2132
2242
|
else {
|
|
2133
2243
|
throw new Error("Must provide datasetName or datasetId");
|
|
2134
2244
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2245
|
+
await this.caller.call(async () => {
|
|
2246
|
+
const res = await this._fetch(this.apiUrl + path, {
|
|
2247
|
+
method: "DELETE",
|
|
2248
|
+
headers: this.headers,
|
|
2249
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2250
|
+
...this.fetchOptions,
|
|
2251
|
+
});
|
|
2252
|
+
await raiseForStatus(res, `delete ${path}`, true);
|
|
2253
|
+
return res;
|
|
2140
2254
|
});
|
|
2141
|
-
await raiseForStatus(response, `delete ${path}`);
|
|
2142
|
-
await response.json();
|
|
2143
2255
|
}
|
|
2144
2256
|
async indexDataset({ datasetId, datasetName, tag, }) {
|
|
2145
2257
|
let datasetId_ = datasetId;
|
|
@@ -2157,14 +2269,18 @@ export class Client {
|
|
|
2157
2269
|
const data = {
|
|
2158
2270
|
tag: tag,
|
|
2159
2271
|
};
|
|
2160
|
-
const
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2272
|
+
const body = JSON.stringify(data);
|
|
2273
|
+
const response = await this.caller.call(async () => {
|
|
2274
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/index`, {
|
|
2275
|
+
method: "POST",
|
|
2276
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2277
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2278
|
+
...this.fetchOptions,
|
|
2279
|
+
body,
|
|
2280
|
+
});
|
|
2281
|
+
await raiseForStatus(res, "index dataset");
|
|
2282
|
+
return res;
|
|
2283
|
+
});
|
|
2168
2284
|
await response.json();
|
|
2169
2285
|
}
|
|
2170
2286
|
/**
|
|
@@ -2206,14 +2322,18 @@ export class Client {
|
|
|
2206
2322
|
data["filter"] = filter;
|
|
2207
2323
|
}
|
|
2208
2324
|
assertUuid(datasetId);
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2325
|
+
const body = JSON.stringify(data);
|
|
2326
|
+
const response = await this.caller.call(async () => {
|
|
2327
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId}/search`, {
|
|
2328
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2329
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2330
|
+
...this.fetchOptions,
|
|
2331
|
+
method: "POST",
|
|
2332
|
+
body,
|
|
2333
|
+
});
|
|
2334
|
+
await raiseForStatus(res, "fetch similar examples");
|
|
2335
|
+
return res;
|
|
2336
|
+
});
|
|
2217
2337
|
const result = await response.json();
|
|
2218
2338
|
return result["examples"];
|
|
2219
2339
|
}
|
|
@@ -2425,14 +2545,16 @@ export class Client {
|
|
|
2425
2545
|
async deleteExample(exampleId) {
|
|
2426
2546
|
assertUuid(exampleId);
|
|
2427
2547
|
const path = `/examples/${exampleId}`;
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2548
|
+
await this.caller.call(async () => {
|
|
2549
|
+
const res = await this._fetch(this.apiUrl + path, {
|
|
2550
|
+
method: "DELETE",
|
|
2551
|
+
headers: this.headers,
|
|
2552
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2553
|
+
...this.fetchOptions,
|
|
2554
|
+
});
|
|
2555
|
+
await raiseForStatus(res, `delete ${path}`, true);
|
|
2556
|
+
return res;
|
|
2433
2557
|
});
|
|
2434
|
-
await raiseForStatus(response, `delete ${path}`);
|
|
2435
|
-
await response.json();
|
|
2436
2558
|
}
|
|
2437
2559
|
async updateExample(exampleIdOrUpdate, update) {
|
|
2438
2560
|
let exampleId;
|
|
@@ -2504,13 +2626,16 @@ export class Client {
|
|
|
2504
2626
|
if (tag !== undefined) {
|
|
2505
2627
|
params.append("tag", tag);
|
|
2506
2628
|
}
|
|
2507
|
-
const response = await this.caller.call(
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2629
|
+
const response = await this.caller.call(async () => {
|
|
2630
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${resolvedDatasetId}/version?${params.toString()}`, {
|
|
2631
|
+
method: "GET",
|
|
2632
|
+
headers: { ...this.headers },
|
|
2633
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2634
|
+
...this.fetchOptions,
|
|
2635
|
+
});
|
|
2636
|
+
await raiseForStatus(res, "read dataset version");
|
|
2637
|
+
return res;
|
|
2512
2638
|
});
|
|
2513
|
-
await raiseForStatus(response, "read dataset version");
|
|
2514
2639
|
return await response.json();
|
|
2515
2640
|
}
|
|
2516
2641
|
async listDatasetSplits({ datasetId, datasetName, asOf, }) {
|
|
@@ -2565,14 +2690,18 @@ export class Client {
|
|
|
2565
2690
|
}),
|
|
2566
2691
|
remove,
|
|
2567
2692
|
};
|
|
2568
|
-
const
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2693
|
+
const body = JSON.stringify(data);
|
|
2694
|
+
await this.caller.call(async () => {
|
|
2695
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/${datasetId_}/splits`, {
|
|
2696
|
+
method: "PUT",
|
|
2697
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2698
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2699
|
+
...this.fetchOptions,
|
|
2700
|
+
body,
|
|
2701
|
+
});
|
|
2702
|
+
await raiseForStatus(res, "update dataset splits", true);
|
|
2703
|
+
return res;
|
|
2574
2704
|
});
|
|
2575
|
-
await raiseForStatus(response, "update dataset splits", true);
|
|
2576
2705
|
}
|
|
2577
2706
|
/**
|
|
2578
2707
|
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
|
|
@@ -2630,15 +2759,19 @@ export class Client {
|
|
|
2630
2759
|
feedbackConfig,
|
|
2631
2760
|
session_id: projectId,
|
|
2632
2761
|
};
|
|
2762
|
+
const body = JSON.stringify(feedback);
|
|
2633
2763
|
const url = `${this.apiUrl}/feedback`;
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2764
|
+
await this.caller.call(async () => {
|
|
2765
|
+
const res = await this._fetch(url, {
|
|
2766
|
+
method: "POST",
|
|
2767
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2768
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2769
|
+
...this.fetchOptions,
|
|
2770
|
+
body,
|
|
2771
|
+
});
|
|
2772
|
+
await raiseForStatus(res, "create feedback", true);
|
|
2773
|
+
return res;
|
|
2774
|
+
});
|
|
2642
2775
|
return feedback;
|
|
2643
2776
|
}
|
|
2644
2777
|
async updateFeedback(feedbackId, { score, value, correction, comment, }) {
|
|
@@ -2656,14 +2789,18 @@ export class Client {
|
|
|
2656
2789
|
feedbackUpdate["comment"] = comment;
|
|
2657
2790
|
}
|
|
2658
2791
|
assertUuid(feedbackId);
|
|
2659
|
-
const
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2792
|
+
const body = JSON.stringify(feedbackUpdate);
|
|
2793
|
+
await this.caller.call(async () => {
|
|
2794
|
+
const res = await this._fetch(`${this.apiUrl}/feedback/${feedbackId}`, {
|
|
2795
|
+
method: "PATCH",
|
|
2796
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2797
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2798
|
+
...this.fetchOptions,
|
|
2799
|
+
body,
|
|
2800
|
+
});
|
|
2801
|
+
await raiseForStatus(res, "update feedback", true);
|
|
2802
|
+
return res;
|
|
2665
2803
|
});
|
|
2666
|
-
await raiseForStatus(response, "update feedback", true);
|
|
2667
2804
|
}
|
|
2668
2805
|
async readFeedback(feedbackId) {
|
|
2669
2806
|
assertUuid(feedbackId);
|
|
@@ -2674,14 +2811,16 @@ export class Client {
|
|
|
2674
2811
|
async deleteFeedback(feedbackId) {
|
|
2675
2812
|
assertUuid(feedbackId);
|
|
2676
2813
|
const path = `/feedback/${feedbackId}`;
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2814
|
+
await this.caller.call(async () => {
|
|
2815
|
+
const res = await this._fetch(this.apiUrl + path, {
|
|
2816
|
+
method: "DELETE",
|
|
2817
|
+
headers: this.headers,
|
|
2818
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2819
|
+
...this.fetchOptions,
|
|
2820
|
+
});
|
|
2821
|
+
await raiseForStatus(res, `delete ${path}`, true);
|
|
2822
|
+
return res;
|
|
2682
2823
|
});
|
|
2683
|
-
await raiseForStatus(response, `delete ${path}`);
|
|
2684
|
-
await response.json();
|
|
2685
2824
|
}
|
|
2686
2825
|
async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
|
|
2687
2826
|
const queryParams = new URLSearchParams();
|
|
@@ -2736,15 +2875,19 @@ export class Client {
|
|
|
2736
2875
|
hours: 3,
|
|
2737
2876
|
};
|
|
2738
2877
|
}
|
|
2739
|
-
const
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2878
|
+
const serializedBody = JSON.stringify(body);
|
|
2879
|
+
const response = await this.caller.call(async () => {
|
|
2880
|
+
const res = await this._fetch(`${this.apiUrl}/feedback/tokens`, {
|
|
2881
|
+
method: "POST",
|
|
2882
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2883
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2884
|
+
...this.fetchOptions,
|
|
2885
|
+
body: serializedBody,
|
|
2886
|
+
});
|
|
2887
|
+
await raiseForStatus(res, "create presigned feedback token");
|
|
2888
|
+
return res;
|
|
2745
2889
|
});
|
|
2746
|
-
|
|
2747
|
-
return result;
|
|
2890
|
+
return await response.json();
|
|
2748
2891
|
}
|
|
2749
2892
|
async createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id, }) {
|
|
2750
2893
|
if (experimentIds.length === 0) {
|
|
@@ -2769,14 +2912,19 @@ export class Client {
|
|
|
2769
2912
|
};
|
|
2770
2913
|
if (metadata)
|
|
2771
2914
|
body.extra["metadata"] = metadata;
|
|
2772
|
-
const
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2915
|
+
const serializedBody = JSON.stringify(body);
|
|
2916
|
+
const response = await this.caller.call(async () => {
|
|
2917
|
+
const res = await this._fetch(`${this.apiUrl}/datasets/comparative`, {
|
|
2918
|
+
method: "POST",
|
|
2919
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
2920
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2921
|
+
...this.fetchOptions,
|
|
2922
|
+
body: serializedBody,
|
|
2923
|
+
});
|
|
2924
|
+
await raiseForStatus(res, "create comparative experiment");
|
|
2925
|
+
return res;
|
|
2778
2926
|
});
|
|
2779
|
-
return
|
|
2927
|
+
return response.json();
|
|
2780
2928
|
}
|
|
2781
2929
|
/**
|
|
2782
2930
|
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
@@ -2885,16 +3033,19 @@ export class Client {
|
|
|
2885
3033
|
id: queueId || uuid.v4(),
|
|
2886
3034
|
rubric_instructions: rubricInstructions,
|
|
2887
3035
|
};
|
|
2888
|
-
const
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
3036
|
+
const serializedBody = JSON.stringify(Object.fromEntries(Object.entries(body).filter(([_, v]) => v !== undefined)));
|
|
3037
|
+
const response = await this.caller.call(async () => {
|
|
3038
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues`, {
|
|
3039
|
+
method: "POST",
|
|
3040
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3041
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3042
|
+
...this.fetchOptions,
|
|
3043
|
+
body: serializedBody,
|
|
3044
|
+
});
|
|
3045
|
+
await raiseForStatus(res, "create annotation queue");
|
|
3046
|
+
return res;
|
|
2894
3047
|
});
|
|
2895
|
-
|
|
2896
|
-
const data = await response.json();
|
|
2897
|
-
return data;
|
|
3048
|
+
return response.json();
|
|
2898
3049
|
}
|
|
2899
3050
|
/**
|
|
2900
3051
|
* Read an annotation queue with the specified queue ID.
|
|
@@ -2902,15 +3053,17 @@ export class Client {
|
|
|
2902
3053
|
* @returns The AnnotationQueueWithDetails object
|
|
2903
3054
|
*/
|
|
2904
3055
|
async readAnnotationQueue(queueId) {
|
|
2905
|
-
const response = await this.caller.call(
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
3056
|
+
const response = await this.caller.call(async () => {
|
|
3057
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}`, {
|
|
3058
|
+
method: "GET",
|
|
3059
|
+
headers: this.headers,
|
|
3060
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3061
|
+
...this.fetchOptions,
|
|
3062
|
+
});
|
|
3063
|
+
await raiseForStatus(res, "read annotation queue");
|
|
3064
|
+
return res;
|
|
2910
3065
|
});
|
|
2911
|
-
|
|
2912
|
-
const data = await response.json();
|
|
2913
|
-
return data;
|
|
3066
|
+
return response.json();
|
|
2914
3067
|
}
|
|
2915
3068
|
/**
|
|
2916
3069
|
* Update an annotation queue with the specified queue ID.
|
|
@@ -2921,31 +3074,38 @@ export class Client {
|
|
|
2921
3074
|
*/
|
|
2922
3075
|
async updateAnnotationQueue(queueId, options) {
|
|
2923
3076
|
const { name, description, rubricInstructions } = options;
|
|
2924
|
-
const
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
3077
|
+
const body = JSON.stringify({
|
|
3078
|
+
name,
|
|
3079
|
+
description,
|
|
3080
|
+
rubric_instructions: rubricInstructions,
|
|
3081
|
+
});
|
|
3082
|
+
await this.caller.call(async () => {
|
|
3083
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}`, {
|
|
3084
|
+
method: "PATCH",
|
|
3085
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3086
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3087
|
+
...this.fetchOptions,
|
|
3088
|
+
body,
|
|
3089
|
+
});
|
|
3090
|
+
await raiseForStatus(res, "update annotation queue", true);
|
|
3091
|
+
return res;
|
|
2934
3092
|
});
|
|
2935
|
-
await raiseForStatus(response, "update annotation queue");
|
|
2936
3093
|
}
|
|
2937
3094
|
/**
|
|
2938
3095
|
* Delete an annotation queue with the specified queue ID.
|
|
2939
3096
|
* @param queueId - The ID of the annotation queue to delete
|
|
2940
3097
|
*/
|
|
2941
3098
|
async deleteAnnotationQueue(queueId) {
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
3099
|
+
await this.caller.call(async () => {
|
|
3100
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}`, {
|
|
3101
|
+
method: "DELETE",
|
|
3102
|
+
headers: { ...this.headers, Accept: "application/json" },
|
|
3103
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3104
|
+
...this.fetchOptions,
|
|
3105
|
+
});
|
|
3106
|
+
await raiseForStatus(res, "delete annotation queue", true);
|
|
3107
|
+
return res;
|
|
2947
3108
|
});
|
|
2948
|
-
await raiseForStatus(response, "delete annotation queue");
|
|
2949
3109
|
}
|
|
2950
3110
|
/**
|
|
2951
3111
|
* Add runs to an annotation queue with the specified queue ID.
|
|
@@ -2953,14 +3113,18 @@ export class Client {
|
|
|
2953
3113
|
* @param runIds - The IDs of the runs to be added to the annotation queue
|
|
2954
3114
|
*/
|
|
2955
3115
|
async addRunsToAnnotationQueue(queueId, runIds) {
|
|
2956
|
-
const
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
3116
|
+
const body = JSON.stringify(runIds.map((id, i) => assertUuid(id, `runIds[${i}]`).toString()));
|
|
3117
|
+
await this.caller.call(async () => {
|
|
3118
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}/runs`, {
|
|
3119
|
+
method: "POST",
|
|
3120
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3121
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3122
|
+
...this.fetchOptions,
|
|
3123
|
+
body,
|
|
3124
|
+
});
|
|
3125
|
+
await raiseForStatus(res, "add runs to annotation queue", true);
|
|
3126
|
+
return res;
|
|
2962
3127
|
});
|
|
2963
|
-
await raiseForStatus(response, "add runs to annotation queue");
|
|
2964
3128
|
}
|
|
2965
3129
|
/**
|
|
2966
3130
|
* Get a run from an annotation queue at the specified index.
|
|
@@ -2971,14 +3135,17 @@ export class Client {
|
|
|
2971
3135
|
*/
|
|
2972
3136
|
async getRunFromAnnotationQueue(queueId, index) {
|
|
2973
3137
|
const baseUrl = `/annotation-queues/${assertUuid(queueId, "queueId")}/run`;
|
|
2974
|
-
const response = await this.caller.call(
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
3138
|
+
const response = await this.caller.call(async () => {
|
|
3139
|
+
const res = await this._fetch(`${this.apiUrl}${baseUrl}/${index}`, {
|
|
3140
|
+
method: "GET",
|
|
3141
|
+
headers: this.headers,
|
|
3142
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3143
|
+
...this.fetchOptions,
|
|
3144
|
+
});
|
|
3145
|
+
await raiseForStatus(res, "get run from annotation queue");
|
|
3146
|
+
return res;
|
|
2979
3147
|
});
|
|
2980
|
-
|
|
2981
|
-
return await response.json();
|
|
3148
|
+
return response.json();
|
|
2982
3149
|
}
|
|
2983
3150
|
/**
|
|
2984
3151
|
* Delete a run from an an annotation queue.
|
|
@@ -2986,27 +3153,33 @@ export class Client {
|
|
|
2986
3153
|
* @param queueRunId - The ID of the run to delete from the annotation queue
|
|
2987
3154
|
*/
|
|
2988
3155
|
async deleteRunFromAnnotationQueue(queueId, queueRunId) {
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
3156
|
+
await this.caller.call(async () => {
|
|
3157
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}/runs/${assertUuid(queueRunId, "queueRunId")}`, {
|
|
3158
|
+
method: "DELETE",
|
|
3159
|
+
headers: { ...this.headers, Accept: "application/json" },
|
|
3160
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3161
|
+
...this.fetchOptions,
|
|
3162
|
+
});
|
|
3163
|
+
await raiseForStatus(res, "delete run from annotation queue", true);
|
|
3164
|
+
return res;
|
|
2994
3165
|
});
|
|
2995
|
-
await raiseForStatus(response, "delete run from annotation queue");
|
|
2996
3166
|
}
|
|
2997
3167
|
/**
|
|
2998
3168
|
* Get the size of an annotation queue.
|
|
2999
3169
|
* @param queueId - The ID of the annotation queue
|
|
3000
3170
|
*/
|
|
3001
3171
|
async getSizeFromAnnotationQueue(queueId) {
|
|
3002
|
-
const response = await this.caller.call(
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3172
|
+
const response = await this.caller.call(async () => {
|
|
3173
|
+
const res = await this._fetch(`${this.apiUrl}/annotation-queues/${assertUuid(queueId, "queueId")}/size`, {
|
|
3174
|
+
method: "GET",
|
|
3175
|
+
headers: this.headers,
|
|
3176
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3177
|
+
...this.fetchOptions,
|
|
3178
|
+
});
|
|
3179
|
+
await raiseForStatus(res, "get size from annotation queue");
|
|
3180
|
+
return res;
|
|
3007
3181
|
});
|
|
3008
|
-
|
|
3009
|
-
return await response.json();
|
|
3182
|
+
return response.json();
|
|
3010
3183
|
}
|
|
3011
3184
|
async _currentTenantIsOwner(owner) {
|
|
3012
3185
|
const settings = await this._getSettings();
|
|
@@ -3019,22 +3192,17 @@ export class Client {
|
|
|
3019
3192
|
Requested tenant: ${owner}`);
|
|
3020
3193
|
}
|
|
3021
3194
|
async _getLatestCommitHash(promptOwnerAndName) {
|
|
3022
|
-
const
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
const error = new Error(`Error ${res.status}: ${res.statusText}\n${detail}`);
|
|
3034
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3035
|
-
error.statusCode = res.status;
|
|
3036
|
-
throw error;
|
|
3037
|
-
}
|
|
3195
|
+
const response = await this.caller.call(async () => {
|
|
3196
|
+
const res = await this._fetch(`${this.apiUrl}/commits/${promptOwnerAndName}/?limit=${1}&offset=${0}`, {
|
|
3197
|
+
method: "GET",
|
|
3198
|
+
headers: this.headers,
|
|
3199
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3200
|
+
...this.fetchOptions,
|
|
3201
|
+
});
|
|
3202
|
+
await raiseForStatus(res, "get latest commit hash");
|
|
3203
|
+
return res;
|
|
3204
|
+
});
|
|
3205
|
+
const json = await response.json();
|
|
3038
3206
|
if (json.commits.length === 0) {
|
|
3039
3207
|
return undefined;
|
|
3040
3208
|
}
|
|
@@ -3042,15 +3210,19 @@ export class Client {
|
|
|
3042
3210
|
}
|
|
3043
3211
|
async _likeOrUnlikePrompt(promptIdentifier, like) {
|
|
3044
3212
|
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
|
|
3045
|
-
const
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3213
|
+
const body = JSON.stringify({ like: like });
|
|
3214
|
+
const response = await this.caller.call(async () => {
|
|
3215
|
+
const res = await this._fetch(`${this.apiUrl}/likes/${owner}/${promptName}`, {
|
|
3216
|
+
method: "POST",
|
|
3217
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3218
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3219
|
+
...this.fetchOptions,
|
|
3220
|
+
body,
|
|
3221
|
+
});
|
|
3222
|
+
await raiseForStatus(res, `${like ? "like" : "unlike"} prompt`);
|
|
3223
|
+
return res;
|
|
3224
|
+
});
|
|
3225
|
+
return response.json();
|
|
3054
3226
|
}
|
|
3055
3227
|
async _getPromptUrl(promptIdentifier) {
|
|
3056
3228
|
const [owner, promptName, commitHash] = parsePromptIdentifier(promptIdentifier);
|
|
@@ -3104,18 +3276,21 @@ export class Client {
|
|
|
3104
3276
|
}
|
|
3105
3277
|
async getPrompt(promptIdentifier) {
|
|
3106
3278
|
const [owner, promptName, _] = parsePromptIdentifier(promptIdentifier);
|
|
3107
|
-
const response = await this.caller.call(
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3279
|
+
const response = await this.caller.call(async () => {
|
|
3280
|
+
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
|
|
3281
|
+
method: "GET",
|
|
3282
|
+
headers: this.headers,
|
|
3283
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3284
|
+
...this.fetchOptions,
|
|
3285
|
+
});
|
|
3286
|
+
if (res?.status === 404) {
|
|
3287
|
+
return null;
|
|
3288
|
+
}
|
|
3289
|
+
await raiseForStatus(res, "get prompt");
|
|
3290
|
+
return res;
|
|
3112
3291
|
});
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
}
|
|
3116
|
-
await raiseForStatus(response, "get prompt");
|
|
3117
|
-
const result = await response.json();
|
|
3118
|
-
if (result.repo) {
|
|
3292
|
+
const result = await response?.json();
|
|
3293
|
+
if (result?.repo) {
|
|
3119
3294
|
return result.repo;
|
|
3120
3295
|
}
|
|
3121
3296
|
else {
|
|
@@ -3141,14 +3316,18 @@ export class Client {
|
|
|
3141
3316
|
...(options?.tags && { tags: options.tags }),
|
|
3142
3317
|
is_public: !!options?.isPublic,
|
|
3143
3318
|
};
|
|
3144
|
-
const
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3319
|
+
const body = JSON.stringify(data);
|
|
3320
|
+
const response = await this.caller.call(async () => {
|
|
3321
|
+
const res = await this._fetch(`${this.apiUrl}/repos/`, {
|
|
3322
|
+
method: "POST",
|
|
3323
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3324
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3325
|
+
...this.fetchOptions,
|
|
3326
|
+
body,
|
|
3327
|
+
});
|
|
3328
|
+
await raiseForStatus(res, "create prompt");
|
|
3329
|
+
return res;
|
|
3330
|
+
});
|
|
3152
3331
|
const { repo } = await response.json();
|
|
3153
3332
|
return repo;
|
|
3154
3333
|
}
|
|
@@ -3164,14 +3343,18 @@ export class Client {
|
|
|
3164
3343
|
manifest: JSON.parse(JSON.stringify(object)),
|
|
3165
3344
|
parent_commit: resolvedParentCommitHash,
|
|
3166
3345
|
};
|
|
3167
|
-
const
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3346
|
+
const body = JSON.stringify(payload);
|
|
3347
|
+
const response = await this.caller.call(async () => {
|
|
3348
|
+
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}`, {
|
|
3349
|
+
method: "POST",
|
|
3350
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
3351
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3352
|
+
...this.fetchOptions,
|
|
3353
|
+
body,
|
|
3354
|
+
});
|
|
3355
|
+
await raiseForStatus(res, "create commit");
|
|
3356
|
+
return res;
|
|
3357
|
+
});
|
|
3175
3358
|
const result = await response.json();
|
|
3176
3359
|
return this._getPromptUrl(`${owner}/${promptName}${result.commit_hash ? `:${result.commit_hash}` : ""}`);
|
|
3177
3360
|
}
|
|
@@ -3244,13 +3427,18 @@ export class Client {
|
|
|
3244
3427
|
}
|
|
3245
3428
|
}
|
|
3246
3429
|
const datasetIdToUse = datasetId ?? updates[0]?.dataset_id;
|
|
3247
|
-
const response = await this.caller.call(
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3430
|
+
const response = await this.caller.call(async () => {
|
|
3431
|
+
const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetIdToUse}/examples`)}`, {
|
|
3432
|
+
method: "PATCH",
|
|
3433
|
+
headers: this.headers,
|
|
3434
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3435
|
+
...this.fetchOptions,
|
|
3436
|
+
body: formData,
|
|
3437
|
+
});
|
|
3438
|
+
await raiseForStatus(res, "update examples");
|
|
3439
|
+
return res;
|
|
3251
3440
|
});
|
|
3252
|
-
|
|
3253
|
-
return result;
|
|
3441
|
+
return response.json();
|
|
3254
3442
|
}
|
|
3255
3443
|
/**
|
|
3256
3444
|
* Upload examples with attachments using multipart form data.
|
|
@@ -3322,14 +3510,18 @@ export class Client {
|
|
|
3322
3510
|
}
|
|
3323
3511
|
}
|
|
3324
3512
|
}
|
|
3325
|
-
const response = await this.caller.call(
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3513
|
+
const response = await this.caller.call(async () => {
|
|
3514
|
+
const res = await this._fetch(`${this.apiUrl}${this._getPlatformEndpointPath(`datasets/${datasetId}/examples`)}`, {
|
|
3515
|
+
method: "POST",
|
|
3516
|
+
headers: this.headers,
|
|
3517
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3518
|
+
...this.fetchOptions,
|
|
3519
|
+
body: formData,
|
|
3520
|
+
});
|
|
3521
|
+
await raiseForStatus(res, "upload examples");
|
|
3522
|
+
return res;
|
|
3329
3523
|
});
|
|
3330
|
-
|
|
3331
|
-
const result = await response.json();
|
|
3332
|
-
return result;
|
|
3524
|
+
return response.json();
|
|
3333
3525
|
}
|
|
3334
3526
|
async updatePrompt(promptIdentifier, options) {
|
|
3335
3527
|
if (!(await this.promptExists(promptIdentifier))) {
|
|
@@ -3354,17 +3546,21 @@ export class Client {
|
|
|
3354
3546
|
if (Object.keys(payload).length === 0) {
|
|
3355
3547
|
throw new Error("No valid update options provided");
|
|
3356
3548
|
}
|
|
3357
|
-
const
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3549
|
+
const body = JSON.stringify(payload);
|
|
3550
|
+
const response = await this.caller.call(async () => {
|
|
3551
|
+
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
|
|
3552
|
+
method: "PATCH",
|
|
3553
|
+
headers: {
|
|
3554
|
+
...this.headers,
|
|
3555
|
+
"Content-Type": "application/json",
|
|
3556
|
+
},
|
|
3557
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3558
|
+
...this.fetchOptions,
|
|
3559
|
+
body,
|
|
3560
|
+
});
|
|
3561
|
+
await raiseForStatus(res, "update prompt");
|
|
3562
|
+
return res;
|
|
3366
3563
|
});
|
|
3367
|
-
await raiseForStatus(response, "update prompt");
|
|
3368
3564
|
return response.json();
|
|
3369
3565
|
}
|
|
3370
3566
|
async deletePrompt(promptIdentifier) {
|
|
@@ -3375,23 +3571,30 @@ export class Client {
|
|
|
3375
3571
|
if (!(await this._currentTenantIsOwner(owner))) {
|
|
3376
3572
|
throw await this._ownerConflictError("delete a prompt", owner);
|
|
3377
3573
|
}
|
|
3378
|
-
const response = await this.caller.call(
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3574
|
+
const response = await this.caller.call(async () => {
|
|
3575
|
+
const res = await this._fetch(`${this.apiUrl}/repos/${owner}/${promptName}`, {
|
|
3576
|
+
method: "DELETE",
|
|
3577
|
+
headers: this.headers,
|
|
3578
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3579
|
+
...this.fetchOptions,
|
|
3580
|
+
});
|
|
3581
|
+
await raiseForStatus(res, "delete prompt");
|
|
3582
|
+
return res;
|
|
3383
3583
|
});
|
|
3384
|
-
return
|
|
3584
|
+
return response.json();
|
|
3385
3585
|
}
|
|
3386
3586
|
async pullPromptCommit(promptIdentifier, options) {
|
|
3387
3587
|
const [owner, promptName, commitHash] = parsePromptIdentifier(promptIdentifier);
|
|
3388
|
-
const response = await this.caller.call(
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3588
|
+
const response = await this.caller.call(async () => {
|
|
3589
|
+
const res = await this._fetch(`${this.apiUrl}/commits/${owner}/${promptName}/${commitHash}${options?.includeModel ? "?include_model=true" : ""}`, {
|
|
3590
|
+
method: "GET",
|
|
3591
|
+
headers: this.headers,
|
|
3592
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
3593
|
+
...this.fetchOptions,
|
|
3594
|
+
});
|
|
3595
|
+
await raiseForStatus(res, "pull prompt commit");
|
|
3596
|
+
return res;
|
|
3393
3597
|
});
|
|
3394
|
-
await raiseForStatus(response, "pull prompt commit");
|
|
3395
3598
|
const result = await response.json();
|
|
3396
3599
|
return {
|
|
3397
3600
|
owner,
|