langsmith 0.0.35 → 0.0.36

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 CHANGED
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Client = void 0;
27
27
  const uuid = __importStar(require("uuid"));
28
28
  const async_caller_js_1 = require("./utils/async_caller.cjs");
29
+ const messages_js_1 = require("./utils/messages.cjs");
29
30
  const env_js_1 = require("./utils/env.cjs");
30
31
  // utility functions
31
32
  const isLocalhost = (url) => {
@@ -580,7 +581,7 @@ class Client {
580
581
  }
581
582
  await response.json();
582
583
  }
583
- async createExample(inputs, outputs, { datasetId, datasetName, createdAt, }) {
584
+ async createExample(inputs, outputs, { datasetId, datasetName, createdAt }) {
584
585
  let datasetId_ = datasetId;
585
586
  if (datasetId_ === undefined && datasetName === undefined) {
586
587
  throw new Error("Must provide either datasetName or datasetId");
@@ -611,6 +612,21 @@ class Client {
611
612
  const result = await response.json();
612
613
  return result;
613
614
  }
615
+ async createLLMExample(input, generation, options) {
616
+ return this.createExample({ input }, { output: generation }, options);
617
+ }
618
+ async createChatExample(input, generations, options) {
619
+ const finalInput = input.map((message) => {
620
+ if ((0, messages_js_1.isLangChainMessage)(message)) {
621
+ return (0, messages_js_1.convertLangChainMessageToExample)(message);
622
+ }
623
+ return message;
624
+ });
625
+ const finalOutput = (0, messages_js_1.isLangChainMessage)(generations)
626
+ ? (0, messages_js_1.convertLangChainMessageToExample)(generations)
627
+ : generations;
628
+ return this.createExample({ input: finalInput }, { output: finalOutput }, options);
629
+ }
614
630
  async readExample(exampleId) {
615
631
  const path = `/examples/${exampleId}`;
616
632
  return await this._get(path);
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AsyncCallerParams } from "./utils/async_caller.js";
2
- import { Dataset, Example, ExampleUpdate, Feedback, KVMap, Run, RunCreate, RunUpdate, ScoreType, TracerSession, TracerSessionResult, ValueType, DataType } from "./schemas.js";
2
+ import { Dataset, Example, ExampleUpdate, Feedback, KVMap, Run, RunCreate, RunUpdate, ScoreType, TracerSession, TracerSessionResult, ValueType, DataType, LangChainBaseMessage } from "./schemas.js";
3
3
  import { RunEvaluator } from "./evaluation/evaluator.js";
4
4
  interface ClientConfig {
5
5
  apiUrl?: string;
@@ -49,6 +49,11 @@ interface CreateRunParams {
49
49
  project_name?: string;
50
50
  }
51
51
  export type FeedbackSourceType = "model" | "api" | "app";
52
+ export type CreateExampleOptions = {
53
+ datasetId?: string;
54
+ datasetName?: string;
55
+ createdAt?: Date;
56
+ };
52
57
  export declare class Client {
53
58
  private apiKey?;
54
59
  private apiUrl;
@@ -120,11 +125,9 @@ export declare class Client {
120
125
  datasetId?: string;
121
126
  datasetName?: string;
122
127
  }): Promise<void>;
123
- createExample(inputs: KVMap, outputs: KVMap, { datasetId, datasetName, createdAt, }: {
124
- datasetId?: string;
125
- datasetName?: string;
126
- createdAt?: Date;
127
- }): Promise<Example>;
128
+ createExample(inputs: KVMap, outputs: KVMap, { datasetId, datasetName, createdAt }: CreateExampleOptions): Promise<Example>;
129
+ createLLMExample(input: string, generation: string | undefined, options: CreateExampleOptions): Promise<Example>;
130
+ createChatExample(input: KVMap[] | LangChainBaseMessage[], generations: KVMap | LangChainBaseMessage | undefined, options: CreateExampleOptions): Promise<Example>;
128
131
  readExample(exampleId: string): Promise<Example>;
129
132
  listExamples({ datasetId, datasetName, exampleIds, }?: {
130
133
  datasetId?: string;
package/dist/client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as uuid from "uuid";
2
2
  import { AsyncCaller } from "./utils/async_caller.js";
3
+ import { convertLangChainMessageToExample, isLangChainMessage, } from "./utils/messages.js";
3
4
  import { getEnvironmentVariable, getRuntimeEnvironment } from "./utils/env.js";
4
5
  // utility functions
5
6
  const isLocalhost = (url) => {
@@ -554,7 +555,7 @@ export class Client {
554
555
  }
555
556
  await response.json();
556
557
  }
557
- async createExample(inputs, outputs, { datasetId, datasetName, createdAt, }) {
558
+ async createExample(inputs, outputs, { datasetId, datasetName, createdAt }) {
558
559
  let datasetId_ = datasetId;
559
560
  if (datasetId_ === undefined && datasetName === undefined) {
560
561
  throw new Error("Must provide either datasetName or datasetId");
@@ -585,6 +586,21 @@ export class Client {
585
586
  const result = await response.json();
586
587
  return result;
587
588
  }
589
+ async createLLMExample(input, generation, options) {
590
+ return this.createExample({ input }, { output: generation }, options);
591
+ }
592
+ async createChatExample(input, generations, options) {
593
+ const finalInput = input.map((message) => {
594
+ if (isLangChainMessage(message)) {
595
+ return convertLangChainMessageToExample(message);
596
+ }
597
+ return message;
598
+ });
599
+ const finalOutput = isLangChainMessage(generations)
600
+ ? convertLangChainMessageToExample(generations)
601
+ : generations;
602
+ return this.createExample({ input: finalInput }, { output: finalOutput }, options);
603
+ }
588
604
  async readExample(exampleId) {
589
605
  const path = `/examples/${exampleId}`;
590
606
  return await this._get(path);
package/dist/schemas.d.ts CHANGED
@@ -164,3 +164,8 @@ export interface FeedbackCreate extends FeedbackBase {
164
164
  export interface Feedback extends FeedbackBase {
165
165
  id: string;
166
166
  }
167
+ export interface LangChainBaseMessage {
168
+ _getType: () => string;
169
+ content: string;
170
+ additional_kwargs?: KVMap;
171
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertLangChainMessageToExample = exports.isLangChainMessage = void 0;
4
+ function isLangChainMessage(message) {
5
+ return typeof message?._getType === "function";
6
+ }
7
+ exports.isLangChainMessage = isLangChainMessage;
8
+ function convertLangChainMessageToExample(message) {
9
+ const converted = {
10
+ type: message._getType(),
11
+ data: { content: message.content },
12
+ };
13
+ // Check for presence of keys in additional_kwargs
14
+ if (message?.additional_kwargs &&
15
+ Object.keys(message.additional_kwargs).length > 0) {
16
+ converted.data.additional_kwargs = { ...message.additional_kwargs };
17
+ }
18
+ return converted;
19
+ }
20
+ exports.convertLangChainMessageToExample = convertLangChainMessageToExample;
@@ -0,0 +1,11 @@
1
+ import { LangChainBaseMessage } from "../schemas.js";
2
+ export declare function isLangChainMessage(message?: any): message is LangChainBaseMessage;
3
+ interface ConvertedData {
4
+ content: string;
5
+ [key: string]: any;
6
+ }
7
+ export declare function convertLangChainMessageToExample(message: LangChainBaseMessage): {
8
+ type: string;
9
+ data: ConvertedData;
10
+ };
11
+ export {};
@@ -0,0 +1,15 @@
1
+ export function isLangChainMessage(message) {
2
+ return typeof message?._getType === "function";
3
+ }
4
+ export function convertLangChainMessageToExample(message) {
5
+ const converted = {
6
+ type: message._getType(),
7
+ data: { content: message.content },
8
+ };
9
+ // Check for presence of keys in additional_kwargs
10
+ if (message?.additional_kwargs &&
11
+ Object.keys(message.additional_kwargs).length > 0) {
12
+ converted.data.additional_kwargs = { ...message.additional_kwargs };
13
+ }
14
+ return converted;
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "files": [
6
6
  "dist/",
@@ -72,6 +72,7 @@
72
72
  "eslint-plugin-no-instanceof": "^1.0.1",
73
73
  "eslint-plugin-prettier": "^4.2.1",
74
74
  "jest": "^29.5.0",
75
+ "langchain": "^0.0.147",
75
76
  "prettier": "^2.8.8",
76
77
  "ts-jest": "^29.1.0",
77
78
  "ts-node": "^10.9.1",