langsmith 0.0.34 → 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/cli/main.cjs CHANGED
@@ -287,11 +287,9 @@ class SmithCommand {
287
287
  }
288
288
  async env() {
289
289
  const env = await (0, env_js_1.getRuntimeEnvironment)();
290
- const dockerEnv = await (0, env_js_1.getDockerEnvironment)();
291
290
  const envVars = await (0, env_js_1.getLangChainEnvVars)();
292
291
  const envDict = {
293
292
  ...env,
294
- ...dockerEnv,
295
293
  ...envVars,
296
294
  };
297
295
  // Pretty print
package/dist/cli/main.js CHANGED
@@ -3,7 +3,7 @@ import * as path from "path";
3
3
  import * as util from "util";
4
4
  import { Command } from "commander";
5
5
  import * as child_process from "child_process";
6
- import { getDockerEnvironment, getLangChainEnvVars, getRuntimeEnvironment, setEnvironmentVariable, } from "../utils/env.js";
6
+ import { getLangChainEnvVars, getRuntimeEnvironment, setEnvironmentVariable, } from "../utils/env.js";
7
7
  import { spawn } from "child_process";
8
8
  const currentFileName = __filename;
9
9
  const currentDirName = __dirname;
@@ -261,11 +261,9 @@ class SmithCommand {
261
261
  }
262
262
  async env() {
263
263
  const env = await getRuntimeEnvironment();
264
- const dockerEnv = await getDockerEnvironment();
265
264
  const envVars = await getLangChainEnvVars();
266
265
  const envDict = {
267
266
  ...env,
268
- ...dockerEnv,
269
267
  ...envVars,
270
268
  };
271
269
  // Pretty print
package/dist/cli/main.ts CHANGED
@@ -4,7 +4,6 @@ import * as util from "util";
4
4
  import { Command } from "commander";
5
5
  import * as child_process from "child_process";
6
6
  import {
7
- getDockerEnvironment,
8
7
  getLangChainEnvVars,
9
8
  getRuntimeEnvironment,
10
9
  setEnvironmentVariable,
@@ -295,11 +294,9 @@ class SmithCommand {
295
294
 
296
295
  async env() {
297
296
  const env = await getRuntimeEnvironment();
298
- const dockerEnv = await getDockerEnvironment();
299
297
  const envVars = await getLangChainEnvVars();
300
298
  const envDict = {
301
299
  ...env,
302
- ...dockerEnv,
303
300
  ...envVars,
304
301
  };
305
302
  // Pretty print
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
+ }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getShas = exports.setEnvironmentVariable = exports.getEnvironmentVariable = exports.getEnvironmentVariables = exports.getLangChainEnvVars = exports.getDockerEnvironment = exports.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
4
- const child_process_1 = require("child_process");
3
+ exports.getShas = exports.setEnvironmentVariable = exports.getEnvironmentVariable = exports.getEnvironmentVariables = exports.getLangChainEnvVars = exports.getRuntimeEnvironment = exports.getEnv = exports.isNode = exports.isDeno = exports.isJsDom = exports.isWebWorker = exports.isBrowser = void 0;
5
4
  const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
6
5
  exports.isBrowser = isBrowser;
7
6
  const isWebWorker = () => typeof globalThis === "object" &&
@@ -60,49 +59,6 @@ async function getRuntimeEnvironment() {
60
59
  return runtimeEnvironment;
61
60
  }
62
61
  exports.getRuntimeEnvironment = getRuntimeEnvironment;
63
- async function getDockerEnvironment() {
64
- const getDockerVersion = () => new Promise((resolve) => {
65
- (0, child_process_1.exec)("docker --version", (error, stdout) => {
66
- if (error) {
67
- resolve(undefined);
68
- }
69
- else {
70
- resolve(stdout.trim());
71
- }
72
- });
73
- });
74
- const getDockerComposeCommand = () => new Promise((resolve) => {
75
- (0, child_process_1.exec)("which docker-compose", (error, stdout) => {
76
- if (error) {
77
- resolve(undefined);
78
- }
79
- else {
80
- resolve(stdout.trim());
81
- }
82
- });
83
- });
84
- const getDockerComposeVersion = () => new Promise((resolve) => {
85
- (0, child_process_1.exec)("docker-compose --version", (error, stdout) => {
86
- if (error) {
87
- resolve(undefined);
88
- }
89
- else {
90
- resolve(stdout.trim());
91
- }
92
- });
93
- });
94
- const [dockerVersion, dockerComposeCommand, dockerComposeVersion] = await Promise.all([
95
- getDockerVersion(),
96
- getDockerComposeCommand(),
97
- getDockerComposeVersion(),
98
- ]);
99
- return {
100
- dockerVersion,
101
- dockerComposeCommand,
102
- dockerComposeVersion,
103
- };
104
- }
105
- exports.getDockerEnvironment = getDockerEnvironment;
106
62
  /**
107
63
  * Retrieves the LangChain-specific environment variables from the current runtime environment.
108
64
  * Sensitive keys (containing the word "key") have their values redacted for security.
@@ -18,11 +18,6 @@ export type RuntimeEnvironment = {
18
18
  runtimeVersion?: string;
19
19
  };
20
20
  export declare function getRuntimeEnvironment(): Promise<RuntimeEnvironment>;
21
- export declare function getDockerEnvironment(): Promise<{
22
- dockerVersion: string | undefined;
23
- dockerComposeCommand: string | undefined;
24
- dockerComposeVersion: string | undefined;
25
- }>;
26
21
  /**
27
22
  * Retrieves the LangChain-specific environment variables from the current runtime environment.
28
23
  * Sensitive keys (containing the word "key") have their values redacted for security.
package/dist/utils/env.js CHANGED
@@ -1,4 +1,3 @@
1
- import { exec } from "child_process";
2
1
  export const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
3
2
  export const isWebWorker = () => typeof globalThis === "object" &&
4
3
  globalThis.constructor &&
@@ -50,48 +49,6 @@ export async function getRuntimeEnvironment() {
50
49
  }
51
50
  return runtimeEnvironment;
52
51
  }
53
- export async function getDockerEnvironment() {
54
- const getDockerVersion = () => new Promise((resolve) => {
55
- exec("docker --version", (error, stdout) => {
56
- if (error) {
57
- resolve(undefined);
58
- }
59
- else {
60
- resolve(stdout.trim());
61
- }
62
- });
63
- });
64
- const getDockerComposeCommand = () => new Promise((resolve) => {
65
- exec("which docker-compose", (error, stdout) => {
66
- if (error) {
67
- resolve(undefined);
68
- }
69
- else {
70
- resolve(stdout.trim());
71
- }
72
- });
73
- });
74
- const getDockerComposeVersion = () => new Promise((resolve) => {
75
- exec("docker-compose --version", (error, stdout) => {
76
- if (error) {
77
- resolve(undefined);
78
- }
79
- else {
80
- resolve(stdout.trim());
81
- }
82
- });
83
- });
84
- const [dockerVersion, dockerComposeCommand, dockerComposeVersion] = await Promise.all([
85
- getDockerVersion(),
86
- getDockerComposeCommand(),
87
- getDockerComposeVersion(),
88
- ]);
89
- return {
90
- dockerVersion,
91
- dockerComposeCommand,
92
- dockerComposeVersion,
93
- };
94
- }
95
52
  /**
96
53
  * Retrieves the LangChain-specific environment variables from the current runtime environment.
97
54
  * Sensitive keys (containing the word "key") have their values redacted for security.
@@ -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.34",
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",