langsmith 0.1.43 → 0.1.44
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 +154 -97
- package/dist/client.d.ts +28 -1
- package/dist/client.js +154 -97
- package/dist/evaluation/_runner.cjs +29 -5
- package/dist/evaluation/_runner.d.ts +2 -1
- package/dist/evaluation/_runner.js +28 -5
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/schemas.d.ts +2 -0
- package/dist/utils/error.cjs +65 -1
- package/dist/utils/error.d.ts +43 -0
- package/dist/utils/error.js +62 -0
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -32,6 +32,7 @@ const index_js_1 = require("./index.cjs");
|
|
|
32
32
|
const _uuid_js_1 = require("./utils/_uuid.cjs");
|
|
33
33
|
const warn_js_1 = require("./utils/warn.cjs");
|
|
34
34
|
const prompts_js_1 = require("./utils/prompts.cjs");
|
|
35
|
+
const error_js_1 = require("./utils/error.cjs");
|
|
35
36
|
async function mergeRuntimeEnvIntoRunCreates(runs) {
|
|
36
37
|
const runtimeEnv = await (0, env_js_1.getRuntimeEnvironment)();
|
|
37
38
|
const envVars = (0, env_js_1.getLangChainEnvVarsMetadata)();
|
|
@@ -72,14 +73,6 @@ const isLocalhost = (url) => {
|
|
|
72
73
|
const hostname = strippedUrl.split("/")[0].split(":")[0];
|
|
73
74
|
return (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1");
|
|
74
75
|
};
|
|
75
|
-
const raiseForStatus = async (response, operation) => {
|
|
76
|
-
// consume the response body to release the connection
|
|
77
|
-
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
78
|
-
const body = await response.text();
|
|
79
|
-
if (!response.ok) {
|
|
80
|
-
throw new Error(`Failed to ${operation}: ${response.status} ${response.statusText} ${body}`);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
76
|
async function toArray(iterable) {
|
|
84
77
|
const result = [];
|
|
85
78
|
for await (const item of iterable) {
|
|
@@ -387,9 +380,7 @@ class Client {
|
|
|
387
380
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
388
381
|
...this.fetchOptions,
|
|
389
382
|
});
|
|
390
|
-
|
|
391
|
-
throw new Error(`Failed to fetch ${path}: ${response.status} ${response.statusText}`);
|
|
392
|
-
}
|
|
383
|
+
await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
|
|
393
384
|
return response;
|
|
394
385
|
}
|
|
395
386
|
async _get(path, queryParams) {
|
|
@@ -409,9 +400,7 @@ class Client {
|
|
|
409
400
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
410
401
|
...this.fetchOptions,
|
|
411
402
|
});
|
|
412
|
-
|
|
413
|
-
throw new Error(`Failed to fetch ${path}: ${response.status} ${response.statusText}`);
|
|
414
|
-
}
|
|
403
|
+
await (0, error_js_1.raiseForStatus)(response, `Failed to fetch ${path}`);
|
|
415
404
|
const items = transform
|
|
416
405
|
? transform(await response.json())
|
|
417
406
|
: await response.json();
|
|
@@ -528,12 +517,7 @@ class Client {
|
|
|
528
517
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
529
518
|
...this.fetchOptions,
|
|
530
519
|
});
|
|
531
|
-
|
|
532
|
-
// consume the response body to release the connection
|
|
533
|
-
// https://undici.nodejs.org/#/?id=garbage-collection
|
|
534
|
-
await response.text();
|
|
535
|
-
throw new Error("Failed to retrieve server info.");
|
|
536
|
-
}
|
|
520
|
+
await (0, error_js_1.raiseForStatus)(response, "get server info");
|
|
537
521
|
return response.json();
|
|
538
522
|
}
|
|
539
523
|
async batchEndpointIsSupported() {
|
|
@@ -582,7 +566,7 @@ class Client {
|
|
|
582
566
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
583
567
|
...this.fetchOptions,
|
|
584
568
|
});
|
|
585
|
-
await raiseForStatus(response, "create run");
|
|
569
|
+
await (0, error_js_1.raiseForStatus)(response, "create run", true);
|
|
586
570
|
}
|
|
587
571
|
/**
|
|
588
572
|
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
@@ -682,7 +666,7 @@ class Client {
|
|
|
682
666
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
683
667
|
...this.fetchOptions,
|
|
684
668
|
});
|
|
685
|
-
await raiseForStatus(response, "batch create run");
|
|
669
|
+
await (0, error_js_1.raiseForStatus)(response, "batch create run", true);
|
|
686
670
|
}
|
|
687
671
|
async updateRun(runId, run) {
|
|
688
672
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
@@ -719,7 +703,7 @@ class Client {
|
|
|
719
703
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
720
704
|
...this.fetchOptions,
|
|
721
705
|
});
|
|
722
|
-
await raiseForStatus(response, "update run");
|
|
706
|
+
await (0, error_js_1.raiseForStatus)(response, "update run", true);
|
|
723
707
|
}
|
|
724
708
|
async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
725
709
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
@@ -1012,7 +996,7 @@ class Client {
|
|
|
1012
996
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1013
997
|
...this.fetchOptions,
|
|
1014
998
|
});
|
|
1015
|
-
await raiseForStatus(response, "unshare run");
|
|
999
|
+
await (0, error_js_1.raiseForStatus)(response, "unshare run", true);
|
|
1016
1000
|
}
|
|
1017
1001
|
async readRunSharedLink(runId) {
|
|
1018
1002
|
(0, _uuid_js_1.assertUuid)(runId);
|
|
@@ -1097,7 +1081,7 @@ class Client {
|
|
|
1097
1081
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1098
1082
|
...this.fetchOptions,
|
|
1099
1083
|
});
|
|
1100
|
-
await raiseForStatus(response, "unshare dataset");
|
|
1084
|
+
await (0, error_js_1.raiseForStatus)(response, "unshare dataset", true);
|
|
1101
1085
|
}
|
|
1102
1086
|
async readSharedDataset(shareToken) {
|
|
1103
1087
|
(0, _uuid_js_1.assertUuid)(shareToken);
|
|
@@ -1110,6 +1094,46 @@ class Client {
|
|
|
1110
1094
|
const dataset = await response.json();
|
|
1111
1095
|
return dataset;
|
|
1112
1096
|
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Get shared examples.
|
|
1099
|
+
*
|
|
1100
|
+
* @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
|
|
1101
|
+
* @param {Object} [options] Additional options for listing the examples.
|
|
1102
|
+
* @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
|
|
1103
|
+
* @returns {Promise<Example[]>} The shared examples.
|
|
1104
|
+
*/
|
|
1105
|
+
async listSharedExamples(shareToken, options) {
|
|
1106
|
+
const params = {};
|
|
1107
|
+
if (options?.exampleIds) {
|
|
1108
|
+
params.id = options.exampleIds;
|
|
1109
|
+
}
|
|
1110
|
+
const urlParams = new URLSearchParams();
|
|
1111
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
1112
|
+
if (Array.isArray(value)) {
|
|
1113
|
+
value.forEach((v) => urlParams.append(key, v));
|
|
1114
|
+
}
|
|
1115
|
+
else {
|
|
1116
|
+
urlParams.append(key, value);
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/examples?${urlParams.toString()}`, {
|
|
1120
|
+
method: "GET",
|
|
1121
|
+
headers: this.headers,
|
|
1122
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1123
|
+
...this.fetchOptions,
|
|
1124
|
+
});
|
|
1125
|
+
const result = await response.json();
|
|
1126
|
+
if (!response.ok) {
|
|
1127
|
+
if ("detail" in result) {
|
|
1128
|
+
throw new Error(`Failed to list shared examples.\nStatus: ${response.status}\nMessage: ${result.detail.join("\n")}`);
|
|
1129
|
+
}
|
|
1130
|
+
throw new Error(`Failed to list shared examples: ${response.status} ${response.statusText}`);
|
|
1131
|
+
}
|
|
1132
|
+
return result.map((example) => ({
|
|
1133
|
+
...example,
|
|
1134
|
+
_hostUrl: this.getHostUrl(),
|
|
1135
|
+
}));
|
|
1136
|
+
}
|
|
1113
1137
|
async createProject({ projectName, description = null, metadata = null, upsert = false, projectExtra = null, referenceDatasetId = null, }) {
|
|
1114
1138
|
const upsert_ = upsert ? `?upsert=true` : "";
|
|
1115
1139
|
const endpoint = `${this.apiUrl}/sessions${upsert_}`;
|
|
@@ -1132,10 +1156,8 @@ class Client {
|
|
|
1132
1156
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1133
1157
|
...this.fetchOptions,
|
|
1134
1158
|
});
|
|
1159
|
+
await (0, error_js_1.raiseForStatus)(response, "create project");
|
|
1135
1160
|
const result = await response.json();
|
|
1136
|
-
if (!response.ok) {
|
|
1137
|
-
throw new Error(`Failed to create session ${projectName}: ${response.status} ${response.statusText}`);
|
|
1138
|
-
}
|
|
1139
1161
|
return result;
|
|
1140
1162
|
}
|
|
1141
1163
|
async updateProject(projectId, { name = null, description = null, metadata = null, projectExtra = null, endTime = null, }) {
|
|
@@ -1157,10 +1179,8 @@ class Client {
|
|
|
1157
1179
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1158
1180
|
...this.fetchOptions,
|
|
1159
1181
|
});
|
|
1182
|
+
await (0, error_js_1.raiseForStatus)(response, "update project");
|
|
1160
1183
|
const result = await response.json();
|
|
1161
|
-
if (!response.ok) {
|
|
1162
|
-
throw new Error(`Failed to update project ${projectId}: ${response.status} ${response.statusText}`);
|
|
1163
|
-
}
|
|
1164
1184
|
return result;
|
|
1165
1185
|
}
|
|
1166
1186
|
async hasProject({ projectId, projectName, }) {
|
|
@@ -1316,7 +1336,7 @@ class Client {
|
|
|
1316
1336
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1317
1337
|
...this.fetchOptions,
|
|
1318
1338
|
});
|
|
1319
|
-
await raiseForStatus(response, `delete session ${projectId_} (${projectName})
|
|
1339
|
+
await (0, error_js_1.raiseForStatus)(response, `delete session ${projectId_} (${projectName})`, true);
|
|
1320
1340
|
}
|
|
1321
1341
|
async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name, }) {
|
|
1322
1342
|
const url = `${this.apiUrl}/datasets/upload`;
|
|
@@ -1344,13 +1364,7 @@ class Client {
|
|
|
1344
1364
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1345
1365
|
...this.fetchOptions,
|
|
1346
1366
|
});
|
|
1347
|
-
|
|
1348
|
-
const result = await response.json();
|
|
1349
|
-
if (result.detail && result.detail.includes("already exists")) {
|
|
1350
|
-
throw new Error(`Dataset ${fileName} already exists`);
|
|
1351
|
-
}
|
|
1352
|
-
throw new Error(`Failed to upload CSV: ${response.status} ${response.statusText}`);
|
|
1353
|
-
}
|
|
1367
|
+
await (0, error_js_1.raiseForStatus)(response, "upload CSV");
|
|
1354
1368
|
const result = await response.json();
|
|
1355
1369
|
return result;
|
|
1356
1370
|
}
|
|
@@ -1375,13 +1389,7 @@ class Client {
|
|
|
1375
1389
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1376
1390
|
...this.fetchOptions,
|
|
1377
1391
|
});
|
|
1378
|
-
|
|
1379
|
-
const result = await response.json();
|
|
1380
|
-
if (result.detail && result.detail.includes("already exists")) {
|
|
1381
|
-
throw new Error(`Dataset ${name} already exists`);
|
|
1382
|
-
}
|
|
1383
|
-
throw new Error(`Failed to create dataset ${response.status} ${response.statusText}`);
|
|
1384
|
-
}
|
|
1392
|
+
await (0, error_js_1.raiseForStatus)(response, "create dataset");
|
|
1385
1393
|
const result = await response.json();
|
|
1386
1394
|
return result;
|
|
1387
1395
|
}
|
|
@@ -1510,9 +1518,7 @@ class Client {
|
|
|
1510
1518
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1511
1519
|
...this.fetchOptions,
|
|
1512
1520
|
});
|
|
1513
|
-
|
|
1514
|
-
throw new Error(`Failed to update dataset ${_datasetId}: ${response.status} ${response.statusText}`);
|
|
1515
|
-
}
|
|
1521
|
+
await (0, error_js_1.raiseForStatus)(response, "update dataset");
|
|
1516
1522
|
return (await response.json());
|
|
1517
1523
|
}
|
|
1518
1524
|
async deleteDataset({ datasetId, datasetName, }) {
|
|
@@ -1538,9 +1544,7 @@ class Client {
|
|
|
1538
1544
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1539
1545
|
...this.fetchOptions,
|
|
1540
1546
|
});
|
|
1541
|
-
|
|
1542
|
-
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
1543
|
-
}
|
|
1547
|
+
await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
|
|
1544
1548
|
await response.json();
|
|
1545
1549
|
}
|
|
1546
1550
|
async indexDataset({ datasetId, datasetName, tag, }) {
|
|
@@ -1566,9 +1570,7 @@ class Client {
|
|
|
1566
1570
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1567
1571
|
...this.fetchOptions,
|
|
1568
1572
|
});
|
|
1569
|
-
|
|
1570
|
-
throw new Error(`Failed to index dataset ${datasetId_}: ${response.status} ${response.statusText}`);
|
|
1571
|
-
}
|
|
1573
|
+
await (0, error_js_1.raiseForStatus)(response, "index dataset");
|
|
1572
1574
|
await response.json();
|
|
1573
1575
|
}
|
|
1574
1576
|
/**
|
|
@@ -1607,9 +1609,7 @@ class Client {
|
|
|
1607
1609
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1608
1610
|
...this.fetchOptions,
|
|
1609
1611
|
});
|
|
1610
|
-
|
|
1611
|
-
throw new Error(`Failed to fetch similar examples: ${response.status} ${response.statusText}`);
|
|
1612
|
-
}
|
|
1612
|
+
await (0, error_js_1.raiseForStatus)(response, "fetch similar examples");
|
|
1613
1613
|
const result = await response.json();
|
|
1614
1614
|
return result["examples"];
|
|
1615
1615
|
}
|
|
@@ -1642,9 +1642,7 @@ class Client {
|
|
|
1642
1642
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1643
1643
|
...this.fetchOptions,
|
|
1644
1644
|
});
|
|
1645
|
-
|
|
1646
|
-
throw new Error(`Failed to create example: ${response.status} ${response.statusText}`);
|
|
1647
|
-
}
|
|
1645
|
+
await (0, error_js_1.raiseForStatus)(response, "create example");
|
|
1648
1646
|
const result = await response.json();
|
|
1649
1647
|
return result;
|
|
1650
1648
|
}
|
|
@@ -1679,9 +1677,7 @@ class Client {
|
|
|
1679
1677
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1680
1678
|
...this.fetchOptions,
|
|
1681
1679
|
});
|
|
1682
|
-
|
|
1683
|
-
throw new Error(`Failed to create examples: ${response.status} ${response.statusText}`);
|
|
1684
|
-
}
|
|
1680
|
+
await (0, error_js_1.raiseForStatus)(response, "create examples");
|
|
1685
1681
|
const result = await response.json();
|
|
1686
1682
|
return result;
|
|
1687
1683
|
}
|
|
@@ -1774,9 +1770,7 @@ class Client {
|
|
|
1774
1770
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1775
1771
|
...this.fetchOptions,
|
|
1776
1772
|
});
|
|
1777
|
-
|
|
1778
|
-
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
1779
|
-
}
|
|
1773
|
+
await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
|
|
1780
1774
|
await response.json();
|
|
1781
1775
|
}
|
|
1782
1776
|
async updateExample(exampleId, update) {
|
|
@@ -1788,9 +1782,7 @@ class Client {
|
|
|
1788
1782
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1789
1783
|
...this.fetchOptions,
|
|
1790
1784
|
});
|
|
1791
|
-
|
|
1792
|
-
throw new Error(`Failed to update example ${exampleId}: ${response.status} ${response.statusText}`);
|
|
1793
|
-
}
|
|
1785
|
+
await (0, error_js_1.raiseForStatus)(response, "update example");
|
|
1794
1786
|
const result = await response.json();
|
|
1795
1787
|
return result;
|
|
1796
1788
|
}
|
|
@@ -1802,9 +1794,7 @@ class Client {
|
|
|
1802
1794
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1803
1795
|
...this.fetchOptions,
|
|
1804
1796
|
});
|
|
1805
|
-
|
|
1806
|
-
throw new Error(`Failed to update examples: ${response.status} ${response.statusText}`);
|
|
1807
|
-
}
|
|
1797
|
+
await (0, error_js_1.raiseForStatus)(response, "update examples");
|
|
1808
1798
|
const result = await response.json();
|
|
1809
1799
|
return result;
|
|
1810
1800
|
}
|
|
@@ -1867,7 +1857,7 @@ class Client {
|
|
|
1867
1857
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1868
1858
|
...this.fetchOptions,
|
|
1869
1859
|
});
|
|
1870
|
-
await raiseForStatus(response, "update dataset splits");
|
|
1860
|
+
await (0, error_js_1.raiseForStatus)(response, "update dataset splits", true);
|
|
1871
1861
|
}
|
|
1872
1862
|
/**
|
|
1873
1863
|
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
|
|
@@ -1933,7 +1923,7 @@ class Client {
|
|
|
1933
1923
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1934
1924
|
...this.fetchOptions,
|
|
1935
1925
|
});
|
|
1936
|
-
await raiseForStatus(response, "create feedback");
|
|
1926
|
+
await (0, error_js_1.raiseForStatus)(response, "create feedback", true);
|
|
1937
1927
|
return feedback;
|
|
1938
1928
|
}
|
|
1939
1929
|
async updateFeedback(feedbackId, { score, value, correction, comment, }) {
|
|
@@ -1958,7 +1948,7 @@ class Client {
|
|
|
1958
1948
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1959
1949
|
...this.fetchOptions,
|
|
1960
1950
|
});
|
|
1961
|
-
await raiseForStatus(response, "update feedback");
|
|
1951
|
+
await (0, error_js_1.raiseForStatus)(response, "update feedback", true);
|
|
1962
1952
|
}
|
|
1963
1953
|
async readFeedback(feedbackId) {
|
|
1964
1954
|
(0, _uuid_js_1.assertUuid)(feedbackId);
|
|
@@ -1975,9 +1965,7 @@ class Client {
|
|
|
1975
1965
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1976
1966
|
...this.fetchOptions,
|
|
1977
1967
|
});
|
|
1978
|
-
|
|
1979
|
-
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
1980
|
-
}
|
|
1968
|
+
await (0, error_js_1.raiseForStatus)(response, `delete ${path}`);
|
|
1981
1969
|
await response.json();
|
|
1982
1970
|
}
|
|
1983
1971
|
async *listFeedback({ runIds, feedbackKeys, feedbackSourceTypes, } = {}) {
|
|
@@ -2170,9 +2158,7 @@ class Client {
|
|
|
2170
2158
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2171
2159
|
...this.fetchOptions,
|
|
2172
2160
|
});
|
|
2173
|
-
|
|
2174
|
-
throw new Error(`Failed to ${like ? "like" : "unlike"} prompt: ${response.status} ${await response.text()}`);
|
|
2175
|
-
}
|
|
2161
|
+
await (0, error_js_1.raiseForStatus)(response, `${like ? "like" : "unlike"} prompt`);
|
|
2176
2162
|
return await response.json();
|
|
2177
2163
|
}
|
|
2178
2164
|
async _getPromptUrl(promptIdentifier) {
|
|
@@ -2236,9 +2222,7 @@ class Client {
|
|
|
2236
2222
|
if (response.status === 404) {
|
|
2237
2223
|
return null;
|
|
2238
2224
|
}
|
|
2239
|
-
|
|
2240
|
-
throw new Error(`Failed to get prompt: ${response.status} ${await response.text()}`);
|
|
2241
|
-
}
|
|
2225
|
+
await (0, error_js_1.raiseForStatus)(response, "get prompt");
|
|
2242
2226
|
const result = await response.json();
|
|
2243
2227
|
if (result.repo) {
|
|
2244
2228
|
return result.repo;
|
|
@@ -2273,9 +2257,7 @@ class Client {
|
|
|
2273
2257
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2274
2258
|
...this.fetchOptions,
|
|
2275
2259
|
});
|
|
2276
|
-
|
|
2277
|
-
throw new Error(`Failed to create prompt: ${response.status} ${await response.text()}`);
|
|
2278
|
-
}
|
|
2260
|
+
await (0, error_js_1.raiseForStatus)(response, "create prompt");
|
|
2279
2261
|
const { repo } = await response.json();
|
|
2280
2262
|
return repo;
|
|
2281
2263
|
}
|
|
@@ -2298,9 +2280,7 @@ class Client {
|
|
|
2298
2280
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2299
2281
|
...this.fetchOptions,
|
|
2300
2282
|
});
|
|
2301
|
-
|
|
2302
|
-
throw new Error(`Failed to create commit: ${response.status} ${await response.text()}`);
|
|
2303
|
-
}
|
|
2283
|
+
await (0, error_js_1.raiseForStatus)(response, "create commit");
|
|
2304
2284
|
const result = await response.json();
|
|
2305
2285
|
return this._getPromptUrl(`${owner}/${promptName}${result.commit_hash ? `:${result.commit_hash}` : ""}`);
|
|
2306
2286
|
}
|
|
@@ -2337,9 +2317,7 @@ class Client {
|
|
|
2337
2317
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2338
2318
|
...this.fetchOptions,
|
|
2339
2319
|
});
|
|
2340
|
-
|
|
2341
|
-
throw new Error(`HTTP Error: ${response.status} - ${await response.text()}`);
|
|
2342
|
-
}
|
|
2320
|
+
await (0, error_js_1.raiseForStatus)(response, "update prompt");
|
|
2343
2321
|
return response.json();
|
|
2344
2322
|
}
|
|
2345
2323
|
async deletePrompt(promptIdentifier) {
|
|
@@ -2378,9 +2356,7 @@ class Client {
|
|
|
2378
2356
|
signal: AbortSignal.timeout(this.timeout_ms),
|
|
2379
2357
|
...this.fetchOptions,
|
|
2380
2358
|
});
|
|
2381
|
-
|
|
2382
|
-
throw new Error(`Failed to pull prompt commit: ${response.status} ${response.statusText}`);
|
|
2383
|
-
}
|
|
2359
|
+
await (0, error_js_1.raiseForStatus)(response, "pull prompt commit");
|
|
2384
2360
|
const result = await response.json();
|
|
2385
2361
|
return {
|
|
2386
2362
|
owner,
|
|
@@ -2433,5 +2409,86 @@ class Client {
|
|
|
2433
2409
|
});
|
|
2434
2410
|
return url;
|
|
2435
2411
|
}
|
|
2412
|
+
/**
|
|
2413
|
+
* Clone a public dataset to your own langsmith tenant.
|
|
2414
|
+
* This operation is idempotent. If you already have a dataset with the given name,
|
|
2415
|
+
* this function will do nothing.
|
|
2416
|
+
|
|
2417
|
+
* @param {string} tokenOrUrl The token of the public dataset to clone.
|
|
2418
|
+
* @param {Object} [options] Additional options for cloning the dataset.
|
|
2419
|
+
* @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
|
|
2420
|
+
* @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
|
|
2421
|
+
* @returns {Promise<void>}
|
|
2422
|
+
*/
|
|
2423
|
+
async clonePublicDataset(tokenOrUrl, options = {}) {
|
|
2424
|
+
const { sourceApiUrl = this.apiUrl, datasetName } = options;
|
|
2425
|
+
const [parsedApiUrl, tokenUuid] = this.parseTokenOrUrl(tokenOrUrl, sourceApiUrl);
|
|
2426
|
+
const sourceClient = new Client({
|
|
2427
|
+
apiUrl: parsedApiUrl,
|
|
2428
|
+
// Placeholder API key not needed anymore in most cases, but
|
|
2429
|
+
// some private deployments may have API key-based rate limiting
|
|
2430
|
+
// that would cause this to fail if we provide no value.
|
|
2431
|
+
apiKey: "placeholder",
|
|
2432
|
+
});
|
|
2433
|
+
const ds = await sourceClient.readSharedDataset(tokenUuid);
|
|
2434
|
+
const finalDatasetName = datasetName || ds.name;
|
|
2435
|
+
try {
|
|
2436
|
+
if (await this.hasDataset({ datasetId: finalDatasetName })) {
|
|
2437
|
+
console.log(`Dataset ${finalDatasetName} already exists in your tenant. Skipping.`);
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
catch (_) {
|
|
2442
|
+
// `.hasDataset` will throw an error if the dataset does not exist.
|
|
2443
|
+
// no-op in that case
|
|
2444
|
+
}
|
|
2445
|
+
// Fetch examples first, then create the dataset
|
|
2446
|
+
const examples = await sourceClient.listSharedExamples(tokenUuid);
|
|
2447
|
+
const dataset = await this.createDataset(finalDatasetName, {
|
|
2448
|
+
description: ds.description,
|
|
2449
|
+
dataType: ds.data_type || "kv",
|
|
2450
|
+
inputsSchema: ds.inputs_schema_definition ?? undefined,
|
|
2451
|
+
outputsSchema: ds.outputs_schema_definition ?? undefined,
|
|
2452
|
+
});
|
|
2453
|
+
try {
|
|
2454
|
+
await this.createExamples({
|
|
2455
|
+
inputs: examples.map((e) => e.inputs),
|
|
2456
|
+
outputs: examples.flatMap((e) => (e.outputs ? [e.outputs] : [])),
|
|
2457
|
+
datasetId: dataset.id,
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
catch (e) {
|
|
2461
|
+
console.error(`An error occurred while creating dataset ${finalDatasetName}. ` +
|
|
2462
|
+
"You should delete it manually.");
|
|
2463
|
+
throw e;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
parseTokenOrUrl(urlOrToken, apiUrl, numParts = 2, kind = "dataset") {
|
|
2467
|
+
// Try parsing as UUID
|
|
2468
|
+
try {
|
|
2469
|
+
(0, _uuid_js_1.assertUuid)(urlOrToken); // Will throw if it's not a UUID.
|
|
2470
|
+
return [apiUrl, urlOrToken];
|
|
2471
|
+
}
|
|
2472
|
+
catch (_) {
|
|
2473
|
+
// no-op if it's not a uuid
|
|
2474
|
+
}
|
|
2475
|
+
// Parse as URL
|
|
2476
|
+
try {
|
|
2477
|
+
const parsedUrl = new URL(urlOrToken);
|
|
2478
|
+
const pathParts = parsedUrl.pathname
|
|
2479
|
+
.split("/")
|
|
2480
|
+
.filter((part) => part !== "");
|
|
2481
|
+
if (pathParts.length >= numParts) {
|
|
2482
|
+
const tokenUuid = pathParts[pathParts.length - numParts];
|
|
2483
|
+
return [apiUrl, tokenUuid];
|
|
2484
|
+
}
|
|
2485
|
+
else {
|
|
2486
|
+
throw new Error(`Invalid public ${kind} URL: ${urlOrToken}`);
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
catch (error) {
|
|
2490
|
+
throw new Error(`Invalid public ${kind} URL or token: ${urlOrToken}`);
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2436
2493
|
}
|
|
2437
2494
|
exports.Client = Client;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
2
2
|
import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleUpdate, ExampleUpdateWithId, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, LangSmithSettings, LikePromptResponse, Prompt, PromptCommit, PromptSortField, Run, RunCreate, RunUpdate, ScoreType, ExampleSearch, TimeDelta, TracerSession, TracerSessionResult, ValueType } from "./schemas.js";
|
|
3
3
|
import { EvaluationResult, EvaluationResults, RunEvaluator } from "./evaluation/evaluator.js";
|
|
4
|
-
interface ClientConfig {
|
|
4
|
+
export interface ClientConfig {
|
|
5
5
|
apiUrl?: string;
|
|
6
6
|
apiKey?: string;
|
|
7
7
|
callerOptions?: AsyncCallerParams;
|
|
@@ -332,6 +332,17 @@ export declare class Client {
|
|
|
332
332
|
shareDataset(datasetId?: string, datasetName?: string): Promise<DatasetShareSchema>;
|
|
333
333
|
unshareDataset(datasetId: string): Promise<void>;
|
|
334
334
|
readSharedDataset(shareToken: string): Promise<Dataset>;
|
|
335
|
+
/**
|
|
336
|
+
* Get shared examples.
|
|
337
|
+
*
|
|
338
|
+
* @param {string} shareToken The share token to get examples for. A share token is the UUID (or LangSmith URL, including UUID) generated when explicitly marking an example as public.
|
|
339
|
+
* @param {Object} [options] Additional options for listing the examples.
|
|
340
|
+
* @param {string[] | undefined} [options.exampleIds] A list of example IDs to filter by.
|
|
341
|
+
* @returns {Promise<Example[]>} The shared examples.
|
|
342
|
+
*/
|
|
343
|
+
listSharedExamples(shareToken: string, options?: {
|
|
344
|
+
exampleIds?: string[];
|
|
345
|
+
}): Promise<Example[]>;
|
|
335
346
|
createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: {
|
|
336
347
|
projectName: string;
|
|
337
348
|
description?: string | null;
|
|
@@ -625,5 +636,21 @@ export declare class Client {
|
|
|
625
636
|
readme?: string;
|
|
626
637
|
tags?: string[];
|
|
627
638
|
}): Promise<string>;
|
|
639
|
+
/**
|
|
640
|
+
* Clone a public dataset to your own langsmith tenant.
|
|
641
|
+
* This operation is idempotent. If you already have a dataset with the given name,
|
|
642
|
+
* this function will do nothing.
|
|
643
|
+
|
|
644
|
+
* @param {string} tokenOrUrl The token of the public dataset to clone.
|
|
645
|
+
* @param {Object} [options] Additional options for cloning the dataset.
|
|
646
|
+
* @param {string} [options.sourceApiUrl] The URL of the langsmith server where the data is hosted. Defaults to the API URL of your current client.
|
|
647
|
+
* @param {string} [options.datasetName] The name of the dataset to create in your tenant. Defaults to the name of the public dataset.
|
|
648
|
+
* @returns {Promise<void>}
|
|
649
|
+
*/
|
|
650
|
+
clonePublicDataset(tokenOrUrl: string, options?: {
|
|
651
|
+
sourceApiUrl?: string;
|
|
652
|
+
datasetName?: string;
|
|
653
|
+
}): Promise<void>;
|
|
654
|
+
private parseTokenOrUrl;
|
|
628
655
|
}
|
|
629
656
|
export {};
|