langsmith 0.1.8 → 0.1.10

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # LangSmith Client SDK
2
2
 
3
+ ![NPM Version](https://img.shields.io/npm/v/langsmith?logo=npm)
4
+ [![JS Downloads](https://img.shields.io/npm/dm/langsmith)](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) {
@@ -1483,7 +1495,7 @@ class Client {
1483
1495
  sourceRunId: feedbackResult?.sourceRunId,
1484
1496
  });
1485
1497
  }
1486
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, eager = false, }) {
1498
+ async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, }) {
1487
1499
  const feedback_source = {
1488
1500
  type: feedbackSourceType ?? "api",
1489
1501
  metadata: sourceInfo ?? {},
@@ -1506,8 +1518,9 @@ class Client {
1506
1518
  correction,
1507
1519
  comment,
1508
1520
  feedback_source: feedback_source,
1521
+ feedbackConfig,
1509
1522
  };
1510
- const url = `${this.apiUrl}/feedback` + (eager ? "/eager" : "");
1523
+ const url = `${this.apiUrl}/feedback`;
1511
1524
  const response = await this.caller.call(fetch, url, {
1512
1525
  method: "POST",
1513
1526
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -1578,5 +1591,60 @@ class Client {
1578
1591
  yield* feedbacks;
1579
1592
  }
1580
1593
  }
1594
+ /**
1595
+ * Creates a presigned feedback token and URL.
1596
+ *
1597
+ * The token can be used to authorize feedback metrics without
1598
+ * needing an API key. This is useful for giving browser-based
1599
+ * applications the ability to submit feedback without needing
1600
+ * to expose an API key.
1601
+ *
1602
+ * @param runId - The ID of the run.
1603
+ * @param feedbackKey - The feedback key.
1604
+ * @param options - Additional options for the token.
1605
+ * @param options.expiration - The expiration time for the token.
1606
+ *
1607
+ * @returns A promise that resolves to a FeedbackIngestToken.
1608
+ */
1609
+ async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig, } = {}) {
1610
+ const body = {
1611
+ run_id: runId,
1612
+ feedback_key: feedbackKey,
1613
+ feedback_config: feedbackConfig,
1614
+ };
1615
+ if (expiration) {
1616
+ if (typeof expiration === "string") {
1617
+ body["expires_at"] = expiration;
1618
+ }
1619
+ else if (expiration?.hours || expiration?.minutes || expiration?.days) {
1620
+ body["expires_in"] = expiration;
1621
+ }
1622
+ }
1623
+ else {
1624
+ body["expires_in"] = {
1625
+ hours: 3,
1626
+ };
1627
+ }
1628
+ const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
1629
+ method: "POST",
1630
+ headers: { ...this.headers, "Content-Type": "application/json" },
1631
+ body: JSON.stringify(body),
1632
+ signal: AbortSignal.timeout(this.timeout_ms),
1633
+ });
1634
+ const result = await response.json();
1635
+ return result;
1636
+ }
1637
+ /**
1638
+ * Retrieves a list of presigned feedback tokens for a given run ID.
1639
+ * @param runId The ID of the run.
1640
+ * @returns An async iterable of FeedbackIngestToken objects.
1641
+ */
1642
+ async *listPresignedFeedbackTokens(runId) {
1643
+ assertUuid(runId);
1644
+ const params = new URLSearchParams({ run_id: runId });
1645
+ for await (const tokens of this._getPaginated("/feedback/tokens", params)) {
1646
+ yield* tokens;
1647
+ }
1648
+ }
1581
1649
  }
1582
1650
  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;
@@ -376,13 +376,14 @@ export declare class Client {
376
376
  loadChildRuns: boolean;
377
377
  referenceExample?: Example;
378
378
  }): Promise<Feedback>;
379
- createFeedback(runId: string, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, eager, }: {
379
+ createFeedback(runId: string, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, }: {
380
380
  score?: ScoreType;
381
381
  value?: ValueType;
382
382
  correction?: object;
383
383
  comment?: string;
384
384
  sourceInfo?: object;
385
385
  feedbackSourceType?: FeedbackSourceType;
386
+ feedbackConfig?: FeedbackConfig;
386
387
  sourceRunId?: string;
387
388
  feedbackId?: string;
388
389
  eager?: boolean;
@@ -400,5 +401,30 @@ export declare class Client {
400
401
  feedbackKeys?: string[];
401
402
  feedbackSourceTypes?: FeedbackSourceType[];
402
403
  }): AsyncIterable<Feedback>;
404
+ /**
405
+ * Creates a presigned feedback token and URL.
406
+ *
407
+ * The token can be used to authorize feedback metrics without
408
+ * needing an API key. This is useful for giving browser-based
409
+ * applications the ability to submit feedback without needing
410
+ * to expose an API key.
411
+ *
412
+ * @param runId - The ID of the run.
413
+ * @param feedbackKey - The feedback key.
414
+ * @param options - Additional options for the token.
415
+ * @param options.expiration - The expiration time for the token.
416
+ *
417
+ * @returns A promise that resolves to a FeedbackIngestToken.
418
+ */
419
+ createPresignedFeedbackToken(runId: string, feedbackKey: string, { expiration, feedbackConfig, }?: {
420
+ expiration?: string | TimeDelta;
421
+ feedbackConfig?: FeedbackConfig;
422
+ }): Promise<FeedbackIngestToken>;
423
+ /**
424
+ * Retrieves a list of presigned feedback tokens for a given run ID.
425
+ * @param runId The ID of the run.
426
+ * @returns An async iterable of FeedbackIngestToken objects.
427
+ */
428
+ listPresignedFeedbackTokens(runId: string): AsyncIterable<FeedbackIngestToken>;
403
429
  }
404
430
  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) {
@@ -1456,7 +1468,7 @@ export class Client {
1456
1468
  sourceRunId: feedbackResult?.sourceRunId,
1457
1469
  });
1458
1470
  }
1459
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, eager = false, }) {
1471
+ async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, }) {
1460
1472
  const feedback_source = {
1461
1473
  type: feedbackSourceType ?? "api",
1462
1474
  metadata: sourceInfo ?? {},
@@ -1479,8 +1491,9 @@ export class Client {
1479
1491
  correction,
1480
1492
  comment,
1481
1493
  feedback_source: feedback_source,
1494
+ feedbackConfig,
1482
1495
  };
1483
- const url = `${this.apiUrl}/feedback` + (eager ? "/eager" : "");
1496
+ const url = `${this.apiUrl}/feedback`;
1484
1497
  const response = await this.caller.call(fetch, url, {
1485
1498
  method: "POST",
1486
1499
  headers: { ...this.headers, "Content-Type": "application/json" },
@@ -1551,4 +1564,59 @@ export class Client {
1551
1564
  yield* feedbacks;
1552
1565
  }
1553
1566
  }
1567
+ /**
1568
+ * Creates a presigned feedback token and URL.
1569
+ *
1570
+ * The token can be used to authorize feedback metrics without
1571
+ * needing an API key. This is useful for giving browser-based
1572
+ * applications the ability to submit feedback without needing
1573
+ * to expose an API key.
1574
+ *
1575
+ * @param runId - The ID of the run.
1576
+ * @param feedbackKey - The feedback key.
1577
+ * @param options - Additional options for the token.
1578
+ * @param options.expiration - The expiration time for the token.
1579
+ *
1580
+ * @returns A promise that resolves to a FeedbackIngestToken.
1581
+ */
1582
+ async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig, } = {}) {
1583
+ const body = {
1584
+ run_id: runId,
1585
+ feedback_key: feedbackKey,
1586
+ feedback_config: feedbackConfig,
1587
+ };
1588
+ if (expiration) {
1589
+ if (typeof expiration === "string") {
1590
+ body["expires_at"] = expiration;
1591
+ }
1592
+ else if (expiration?.hours || expiration?.minutes || expiration?.days) {
1593
+ body["expires_in"] = expiration;
1594
+ }
1595
+ }
1596
+ else {
1597
+ body["expires_in"] = {
1598
+ hours: 3,
1599
+ };
1600
+ }
1601
+ const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, {
1602
+ method: "POST",
1603
+ headers: { ...this.headers, "Content-Type": "application/json" },
1604
+ body: JSON.stringify(body),
1605
+ signal: AbortSignal.timeout(this.timeout_ms),
1606
+ });
1607
+ const result = await response.json();
1608
+ return result;
1609
+ }
1610
+ /**
1611
+ * Retrieves a list of presigned feedback tokens for a given run ID.
1612
+ * @param runId The ID of the run.
1613
+ * @returns An async iterable of FeedbackIngestToken objects.
1614
+ */
1615
+ async *listPresignedFeedbackTokens(runId) {
1616
+ assertUuid(runId);
1617
+ const params = new URLSearchParams({ run_id: runId });
1618
+ for await (const tokens of this._getPaginated("/feedback/tokens", params)) {
1619
+ yield* tokens;
1620
+ }
1621
+ }
1554
1622
  }
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.8";
9
+ exports.__version__ = "0.1.10";
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.8";
4
+ export declare const __version__ = "0.1.10";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Client } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  // Update using yarn bump-version
4
- export const __version__ = "0.1.8";
4
+ export const __version__ = "0.1.10";
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [