langsmith 0.1.8 → 0.1.11
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/README.md +4 -0
- package/dist/client.cjs +75 -6
- package/dist/client.d.ts +36 -3
- package/dist/client.js +75 -6
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schemas.d.ts +38 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# LangSmith Client SDK
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/langsmith)
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
This package contains the TypeScript client for interacting with the [LangSmith platform](https://smith.langchain.com/).
|
|
4
8
|
|
|
5
9
|
To install:
|
package/dist/client.cjs
CHANGED
|
@@ -328,15 +328,27 @@ class Client {
|
|
|
328
328
|
return headers;
|
|
329
329
|
}
|
|
330
330
|
processInputs(inputs) {
|
|
331
|
-
if (this.hideInputs) {
|
|
331
|
+
if (this.hideInputs === false) {
|
|
332
|
+
return inputs;
|
|
333
|
+
}
|
|
334
|
+
if (this.hideInputs === true) {
|
|
332
335
|
return {};
|
|
333
336
|
}
|
|
337
|
+
if (typeof this.hideInputs === "function") {
|
|
338
|
+
return this.hideInputs(inputs);
|
|
339
|
+
}
|
|
334
340
|
return inputs;
|
|
335
341
|
}
|
|
336
342
|
processOutputs(outputs) {
|
|
337
|
-
if (this.hideOutputs) {
|
|
343
|
+
if (this.hideOutputs === false) {
|
|
344
|
+
return outputs;
|
|
345
|
+
}
|
|
346
|
+
if (this.hideOutputs === true) {
|
|
338
347
|
return {};
|
|
339
348
|
}
|
|
349
|
+
if (typeof this.hideOutputs === "function") {
|
|
350
|
+
return this.hideOutputs(outputs);
|
|
351
|
+
}
|
|
340
352
|
return outputs;
|
|
341
353
|
}
|
|
342
354
|
prepareRunCreateOrUpdateInputs(run) {
|
|
@@ -825,7 +837,7 @@ class Client {
|
|
|
825
837
|
* });
|
|
826
838
|
*/
|
|
827
839
|
async *listRuns(props) {
|
|
828
|
-
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, runType, error, id, query, filter, traceFilter, limit, } = props;
|
|
840
|
+
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, runType, error, id, query, filter, traceFilter, treeFilter, limit, } = props;
|
|
829
841
|
let projectIds = [];
|
|
830
842
|
if (projectId) {
|
|
831
843
|
projectIds = Array.isArray(projectId) ? projectId : [projectId];
|
|
@@ -844,8 +856,9 @@ class Client {
|
|
|
844
856
|
query,
|
|
845
857
|
filter,
|
|
846
858
|
trace_filter: traceFilter,
|
|
859
|
+
tree_filter: treeFilter,
|
|
847
860
|
execution_order: executionOrder,
|
|
848
|
-
parent_run: parentRunId
|
|
861
|
+
parent_run: parentRunId,
|
|
849
862
|
start_time: startTime ? startTime.toISOString() : null,
|
|
850
863
|
error,
|
|
851
864
|
id,
|
|
@@ -1483,7 +1496,7 @@ class Client {
|
|
|
1483
1496
|
sourceRunId: feedbackResult?.sourceRunId,
|
|
1484
1497
|
});
|
|
1485
1498
|
}
|
|
1486
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId,
|
|
1499
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, }) {
|
|
1487
1500
|
const feedback_source = {
|
|
1488
1501
|
type: feedbackSourceType ?? "api",
|
|
1489
1502
|
metadata: sourceInfo ?? {},
|
|
@@ -1506,8 +1519,9 @@ class Client {
|
|
|
1506
1519
|
correction,
|
|
1507
1520
|
comment,
|
|
1508
1521
|
feedback_source: feedback_source,
|
|
1522
|
+
feedbackConfig,
|
|
1509
1523
|
};
|
|
1510
|
-
const url = `${this.apiUrl}/feedback
|
|
1524
|
+
const url = `${this.apiUrl}/feedback`;
|
|
1511
1525
|
const response = await this.caller.call(fetch, url, {
|
|
1512
1526
|
method: "POST",
|
|
1513
1527
|
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
@@ -1578,5 +1592,60 @@ class Client {
|
|
|
1578
1592
|
yield* feedbacks;
|
|
1579
1593
|
}
|
|
1580
1594
|
}
|
|
1595
|
+
/**
|
|
1596
|
+
* Creates a presigned feedback token and URL.
|
|
1597
|
+
*
|
|
1598
|
+
* The token can be used to authorize feedback metrics without
|
|
1599
|
+
* needing an API key. This is useful for giving browser-based
|
|
1600
|
+
* applications the ability to submit feedback without needing
|
|
1601
|
+
* to expose an API key.
|
|
1602
|
+
*
|
|
1603
|
+
* @param runId - The ID of the run.
|
|
1604
|
+
* @param feedbackKey - The feedback key.
|
|
1605
|
+
* @param options - Additional options for the token.
|
|
1606
|
+
* @param options.expiration - The expiration time for the token.
|
|
1607
|
+
*
|
|
1608
|
+
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
1609
|
+
*/
|
|
1610
|
+
async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig, } = {}) {
|
|
1611
|
+
const body = {
|
|
1612
|
+
run_id: runId,
|
|
1613
|
+
feedback_key: feedbackKey,
|
|
1614
|
+
feedback_config: feedbackConfig,
|
|
1615
|
+
};
|
|
1616
|
+
if (expiration) {
|
|
1617
|
+
if (typeof expiration === "string") {
|
|
1618
|
+
body["expires_at"] = expiration;
|
|
1619
|
+
}
|
|
1620
|
+
else if (expiration?.hours || expiration?.minutes || expiration?.days) {
|
|
1621
|
+
body["expires_in"] = expiration;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
else {
|
|
1625
|
+
body["expires_in"] = {
|
|
1626
|
+
hours: 3,
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
|
|
1630
|
+
method: "POST",
|
|
1631
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1632
|
+
body: JSON.stringify(body),
|
|
1633
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1634
|
+
});
|
|
1635
|
+
const result = await response.json();
|
|
1636
|
+
return result;
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
1640
|
+
* @param runId The ID of the run.
|
|
1641
|
+
* @returns An async iterable of FeedbackIngestToken objects.
|
|
1642
|
+
*/
|
|
1643
|
+
async *listPresignedFeedbackTokens(runId) {
|
|
1644
|
+
assertUuid(runId);
|
|
1645
|
+
const params = new URLSearchParams({ run_id: runId });
|
|
1646
|
+
for await (const tokens of this._getPaginated("/feedback/tokens", params)) {
|
|
1647
|
+
yield* tokens;
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1581
1650
|
}
|
|
1582
1651
|
exports.Client = Client;
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncCallerParams } from "./utils/async_caller.js";
|
|
2
|
-
import { DataType, Dataset, DatasetShareSchema, Example, ExampleUpdate, Feedback, KVMap, LangChainBaseMessage, Run, RunCreate, RunUpdate, ScoreType, TracerSession, TracerSessionResult, ValueType } from "./schemas.js";
|
|
2
|
+
import { DataType, Dataset, DatasetShareSchema, Example, ExampleUpdate, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, Run, RunCreate, RunUpdate, ScoreType, TimeDelta, TracerSession, TracerSessionResult, ValueType } from "./schemas.js";
|
|
3
3
|
import { RunEvaluator } from "./evaluation/evaluator.js";
|
|
4
4
|
interface ClientConfig {
|
|
5
5
|
apiUrl?: string;
|
|
@@ -85,9 +85,16 @@ interface ListRunsParams {
|
|
|
85
85
|
*/
|
|
86
86
|
filter?: string;
|
|
87
87
|
/**
|
|
88
|
-
*
|
|
88
|
+
* Filter to apply to the ROOT run in the trace tree. This is meant to be used in conjunction with the regular
|
|
89
|
+
* `filter` parameter to let you filter runs by attributes of the root run within a trace. Example is filtering by
|
|
90
|
+
* feedback assigned to the trace.
|
|
89
91
|
*/
|
|
90
92
|
traceFilter?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Filter to apply to OTHER runs in the trace tree, including sibling and child runs. This is meant to be used in
|
|
95
|
+
* conjunction with the regular `filter` parameter to let you filter runs by attributes of any run within a trace.
|
|
96
|
+
*/
|
|
97
|
+
treeFilter?: string;
|
|
91
98
|
}
|
|
92
99
|
interface UploadCSVParams {
|
|
93
100
|
csvFile: Blob;
|
|
@@ -376,13 +383,14 @@ export declare class Client {
|
|
|
376
383
|
loadChildRuns: boolean;
|
|
377
384
|
referenceExample?: Example;
|
|
378
385
|
}): Promise<Feedback>;
|
|
379
|
-
createFeedback(runId: string, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId,
|
|
386
|
+
createFeedback(runId: string, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, }: {
|
|
380
387
|
score?: ScoreType;
|
|
381
388
|
value?: ValueType;
|
|
382
389
|
correction?: object;
|
|
383
390
|
comment?: string;
|
|
384
391
|
sourceInfo?: object;
|
|
385
392
|
feedbackSourceType?: FeedbackSourceType;
|
|
393
|
+
feedbackConfig?: FeedbackConfig;
|
|
386
394
|
sourceRunId?: string;
|
|
387
395
|
feedbackId?: string;
|
|
388
396
|
eager?: boolean;
|
|
@@ -400,5 +408,30 @@ export declare class Client {
|
|
|
400
408
|
feedbackKeys?: string[];
|
|
401
409
|
feedbackSourceTypes?: FeedbackSourceType[];
|
|
402
410
|
}): AsyncIterable<Feedback>;
|
|
411
|
+
/**
|
|
412
|
+
* Creates a presigned feedback token and URL.
|
|
413
|
+
*
|
|
414
|
+
* The token can be used to authorize feedback metrics without
|
|
415
|
+
* needing an API key. This is useful for giving browser-based
|
|
416
|
+
* applications the ability to submit feedback without needing
|
|
417
|
+
* to expose an API key.
|
|
418
|
+
*
|
|
419
|
+
* @param runId - The ID of the run.
|
|
420
|
+
* @param feedbackKey - The feedback key.
|
|
421
|
+
* @param options - Additional options for the token.
|
|
422
|
+
* @param options.expiration - The expiration time for the token.
|
|
423
|
+
*
|
|
424
|
+
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
425
|
+
*/
|
|
426
|
+
createPresignedFeedbackToken(runId: string, feedbackKey: string, { expiration, feedbackConfig, }?: {
|
|
427
|
+
expiration?: string | TimeDelta;
|
|
428
|
+
feedbackConfig?: FeedbackConfig;
|
|
429
|
+
}): Promise<FeedbackIngestToken>;
|
|
430
|
+
/**
|
|
431
|
+
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
432
|
+
* @param runId The ID of the run.
|
|
433
|
+
* @returns An async iterable of FeedbackIngestToken objects.
|
|
434
|
+
*/
|
|
435
|
+
listPresignedFeedbackTokens(runId: string): AsyncIterable<FeedbackIngestToken>;
|
|
403
436
|
}
|
|
404
437
|
export {};
|
package/dist/client.js
CHANGED
|
@@ -301,15 +301,27 @@ export class Client {
|
|
|
301
301
|
return headers;
|
|
302
302
|
}
|
|
303
303
|
processInputs(inputs) {
|
|
304
|
-
if (this.hideInputs) {
|
|
304
|
+
if (this.hideInputs === false) {
|
|
305
|
+
return inputs;
|
|
306
|
+
}
|
|
307
|
+
if (this.hideInputs === true) {
|
|
305
308
|
return {};
|
|
306
309
|
}
|
|
310
|
+
if (typeof this.hideInputs === "function") {
|
|
311
|
+
return this.hideInputs(inputs);
|
|
312
|
+
}
|
|
307
313
|
return inputs;
|
|
308
314
|
}
|
|
309
315
|
processOutputs(outputs) {
|
|
310
|
-
if (this.hideOutputs) {
|
|
316
|
+
if (this.hideOutputs === false) {
|
|
317
|
+
return outputs;
|
|
318
|
+
}
|
|
319
|
+
if (this.hideOutputs === true) {
|
|
311
320
|
return {};
|
|
312
321
|
}
|
|
322
|
+
if (typeof this.hideOutputs === "function") {
|
|
323
|
+
return this.hideOutputs(outputs);
|
|
324
|
+
}
|
|
313
325
|
return outputs;
|
|
314
326
|
}
|
|
315
327
|
prepareRunCreateOrUpdateInputs(run) {
|
|
@@ -798,7 +810,7 @@ export class Client {
|
|
|
798
810
|
* });
|
|
799
811
|
*/
|
|
800
812
|
async *listRuns(props) {
|
|
801
|
-
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, runType, error, id, query, filter, traceFilter, limit, } = props;
|
|
813
|
+
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, runType, error, id, query, filter, traceFilter, treeFilter, limit, } = props;
|
|
802
814
|
let projectIds = [];
|
|
803
815
|
if (projectId) {
|
|
804
816
|
projectIds = Array.isArray(projectId) ? projectId : [projectId];
|
|
@@ -817,8 +829,9 @@ export class Client {
|
|
|
817
829
|
query,
|
|
818
830
|
filter,
|
|
819
831
|
trace_filter: traceFilter,
|
|
832
|
+
tree_filter: treeFilter,
|
|
820
833
|
execution_order: executionOrder,
|
|
821
|
-
parent_run: parentRunId
|
|
834
|
+
parent_run: parentRunId,
|
|
822
835
|
start_time: startTime ? startTime.toISOString() : null,
|
|
823
836
|
error,
|
|
824
837
|
id,
|
|
@@ -1456,7 +1469,7 @@ export class Client {
|
|
|
1456
1469
|
sourceRunId: feedbackResult?.sourceRunId,
|
|
1457
1470
|
});
|
|
1458
1471
|
}
|
|
1459
|
-
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId,
|
|
1472
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, }) {
|
|
1460
1473
|
const feedback_source = {
|
|
1461
1474
|
type: feedbackSourceType ?? "api",
|
|
1462
1475
|
metadata: sourceInfo ?? {},
|
|
@@ -1479,8 +1492,9 @@ export class Client {
|
|
|
1479
1492
|
correction,
|
|
1480
1493
|
comment,
|
|
1481
1494
|
feedback_source: feedback_source,
|
|
1495
|
+
feedbackConfig,
|
|
1482
1496
|
};
|
|
1483
|
-
const url = `${this.apiUrl}/feedback
|
|
1497
|
+
const url = `${this.apiUrl}/feedback`;
|
|
1484
1498
|
const response = await this.caller.call(fetch, url, {
|
|
1485
1499
|
method: "POST",
|
|
1486
1500
|
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
@@ -1551,4 +1565,59 @@ export class Client {
|
|
|
1551
1565
|
yield* feedbacks;
|
|
1552
1566
|
}
|
|
1553
1567
|
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Creates a presigned feedback token and URL.
|
|
1570
|
+
*
|
|
1571
|
+
* The token can be used to authorize feedback metrics without
|
|
1572
|
+
* needing an API key. This is useful for giving browser-based
|
|
1573
|
+
* applications the ability to submit feedback without needing
|
|
1574
|
+
* to expose an API key.
|
|
1575
|
+
*
|
|
1576
|
+
* @param runId - The ID of the run.
|
|
1577
|
+
* @param feedbackKey - The feedback key.
|
|
1578
|
+
* @param options - Additional options for the token.
|
|
1579
|
+
* @param options.expiration - The expiration time for the token.
|
|
1580
|
+
*
|
|
1581
|
+
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
1582
|
+
*/
|
|
1583
|
+
async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig, } = {}) {
|
|
1584
|
+
const body = {
|
|
1585
|
+
run_id: runId,
|
|
1586
|
+
feedback_key: feedbackKey,
|
|
1587
|
+
feedback_config: feedbackConfig,
|
|
1588
|
+
};
|
|
1589
|
+
if (expiration) {
|
|
1590
|
+
if (typeof expiration === "string") {
|
|
1591
|
+
body["expires_at"] = expiration;
|
|
1592
|
+
}
|
|
1593
|
+
else if (expiration?.hours || expiration?.minutes || expiration?.days) {
|
|
1594
|
+
body["expires_in"] = expiration;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
else {
|
|
1598
|
+
body["expires_in"] = {
|
|
1599
|
+
hours: 3,
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
|
|
1603
|
+
method: "POST",
|
|
1604
|
+
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
1605
|
+
body: JSON.stringify(body),
|
|
1606
|
+
signal: AbortSignal.timeout(this.timeout_ms),
|
|
1607
|
+
});
|
|
1608
|
+
const result = await response.json();
|
|
1609
|
+
return result;
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
1613
|
+
* @param runId The ID of the run.
|
|
1614
|
+
* @returns An async iterable of FeedbackIngestToken objects.
|
|
1615
|
+
*/
|
|
1616
|
+
async *listPresignedFeedbackTokens(runId) {
|
|
1617
|
+
assertUuid(runId);
|
|
1618
|
+
const params = new URLSearchParams({ run_id: runId });
|
|
1619
|
+
for await (const tokens of this._getPaginated("/feedback/tokens", params)) {
|
|
1620
|
+
yield* tokens;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1554
1623
|
}
|
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.11";
|
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.11";
|
package/dist/index.js
CHANGED
package/dist/schemas.d.ts
CHANGED
|
@@ -209,3 +209,41 @@ export interface LangChainBaseMessage {
|
|
|
209
209
|
content: string;
|
|
210
210
|
additional_kwargs?: KVMap;
|
|
211
211
|
}
|
|
212
|
+
export interface FeedbackIngestToken {
|
|
213
|
+
id: string;
|
|
214
|
+
url: string;
|
|
215
|
+
expires_at: string;
|
|
216
|
+
}
|
|
217
|
+
export interface TimeDelta {
|
|
218
|
+
days?: number;
|
|
219
|
+
hours?: number;
|
|
220
|
+
minutes?: number;
|
|
221
|
+
}
|
|
222
|
+
export interface FeedbackCategory {
|
|
223
|
+
value: number;
|
|
224
|
+
label?: string | null;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Represents the configuration for feedback.
|
|
228
|
+
* This determines how the LangSmith service interprets feedback
|
|
229
|
+
* values of the associated key.
|
|
230
|
+
*/
|
|
231
|
+
export interface FeedbackConfig {
|
|
232
|
+
/**
|
|
233
|
+
* The type of feedback.
|
|
234
|
+
*/
|
|
235
|
+
type: "continuous" | "categorical" | "freeform";
|
|
236
|
+
/**
|
|
237
|
+
* The minimum value for continuous feedback.
|
|
238
|
+
*/
|
|
239
|
+
min?: number | null;
|
|
240
|
+
/**
|
|
241
|
+
* The maximum value for continuous feedback.
|
|
242
|
+
*/
|
|
243
|
+
max?: number | null;
|
|
244
|
+
/**
|
|
245
|
+
* If feedback is categorical, this defines the valid categories the server will accept.
|
|
246
|
+
* Not applicable to continuous or freeform feedback types.
|
|
247
|
+
*/
|
|
248
|
+
categories?: FeedbackCategory[] | null;
|
|
249
|
+
}
|