langchain 0.1.7 → 0.1.8

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FORMAT_INSTRUCTIONS = void 0;
4
- exports.FORMAT_INSTRUCTIONS /* #__PURE__ */ = `Use the following format:
4
+ exports.FORMAT_INSTRUCTIONS = `Use the following format:
5
5
 
6
6
  Question: the input question you must answer
7
7
  Thought: you should always think about what to do
@@ -1,4 +1,4 @@
1
- export const FORMAT_INSTRUCTIONS /* #__PURE__ */ = `Use the following format:
1
+ export const FORMAT_INSTRUCTIONS = `Use the following format:
2
2
 
3
3
  Question: the input question you must answer
4
4
  Thought: you should always think about what to do
@@ -56,7 +56,7 @@ export class ConstitutionalPrinciple {
56
56
  };
57
57
  }
58
58
  }
59
- export const PRINCIPLES = /* #__PURE__ */ {
59
+ export const PRINCIPLES = {
60
60
  harmful1: /* #__PURE__ */ new ConstitutionalPrinciple({
61
61
  name: "harmful1",
62
62
  critiqueRequest: "Identify specific ways in which the assistant’s last response is harmful, unethical, racist, sexist, toxic, dangerous, or illegal.",
@@ -12,7 +12,7 @@ const async_caller_1 = require("@langchain/core/utils/async_caller");
12
12
  const base_js_1 = require("../base.cjs");
13
13
  const directory_js_1 = require("../fs/directory.cjs");
14
14
  const extname_js_1 = require("../../util/extname.cjs");
15
- const extensions = new Set(binary_extensions_1.default);
15
+ const extensions = /* #__PURE__ */ new Set(binary_extensions_1.default);
16
16
  /**
17
17
  * A function that checks if a file path is a binary file based on its
18
18
  * extension.
@@ -6,7 +6,7 @@ import { AsyncCaller, } from "@langchain/core/utils/async_caller";
6
6
  import { BaseDocumentLoader } from "../base.js";
7
7
  import { UnknownHandling } from "../fs/directory.js";
8
8
  import { extname } from "../../util/extname.js";
9
- const extensions = new Set(binaryExtensions);
9
+ const extensions = /* #__PURE__ */ new Set(binaryExtensions);
10
10
  /**
11
11
  * A function that checks if a file path is a binary file based on its
12
12
  * extension.
@@ -6,7 +6,7 @@ const outputs_1 = require("@langchain/core/outputs");
6
6
  const base_js_1 = require("../base.cjs");
7
7
  const prompt_js_1 = require("./prompt.cjs");
8
8
  const index_js_1 = require("../../chains/index.cjs");
9
- const SUPPORTED_CRITERIA = /* #__PURE__ */ {
9
+ const SUPPORTED_CRITERIA = {
10
10
  conciseness: "Is the submission concise and to the point?",
11
11
  relevance: "Is the submission referring to a real quote from the text?",
12
12
  correctness: "Is the submission correct, accurate, and factual?",
@@ -3,7 +3,7 @@ import { RUN_KEY } from "@langchain/core/outputs";
3
3
  import { eqSet, LLMPairwiseStringEvaluator, } from "../base.js";
4
4
  import { PROMPT, PROMPT_WITH_REFERENCES } from "./prompt.js";
5
5
  import { ConstitutionalPrinciple } from "../../chains/index.js";
6
- const SUPPORTED_CRITERIA = /* #__PURE__ */ {
6
+ const SUPPORTED_CRITERIA = {
7
7
  conciseness: "Is the submission concise and to the point?",
8
8
  relevance: "Is the submission referring to a real quote from the text?",
9
9
  correctness: "Is the submission correct, accurate, and factual?",
@@ -6,7 +6,7 @@ const outputs_1 = require("@langchain/core/outputs");
6
6
  const base_js_1 = require("../base.cjs");
7
7
  const prompt_js_1 = require("./prompt.cjs");
8
8
  const constitutional_principle_js_1 = require("../../chains/constitutional_ai/constitutional_principle.cjs");
9
- const SUPPORTED_CRITERIA = /* #__PURE__ */ {
9
+ const SUPPORTED_CRITERIA = {
10
10
  conciseness: "Is the submission concise and to the point?",
11
11
  relevance: "Is the submission referring to a real quote from the text?",
12
12
  correctness: "Is the submission correct, accurate, and factual?",
@@ -3,7 +3,7 @@ import { RUN_KEY } from "@langchain/core/outputs";
3
3
  import { eqSet, LLMStringEvaluator, } from "../base.js";
4
4
  import { CRITERIA_PROMPT, PROMPT_WITH_REFERENCES } from "./prompt.js";
5
5
  import { ConstitutionalPrinciple } from "../../chains/constitutional_ai/constitutional_principle.js";
6
- const SUPPORTED_CRITERIA = /* #__PURE__ */ {
6
+ const SUPPORTED_CRITERIA = {
7
7
  conciseness: "Is the submission concise and to the point?",
8
8
  relevance: "Is the submission referring to a real quote from the text?",
9
9
  correctness: "Is the submission correct, accurate, and factual?",
@@ -1,4 +1,5 @@
1
1
  import { BaseLanguageModel } from "@langchain/core/language_models/base";
2
+ import { RunnableConfig } from "@langchain/core/runnables";
2
3
  import { Example, Run } from "langsmith";
3
4
  import { EvaluationResult, RunEvaluator } from "langsmith/evaluation";
4
5
  import { Criteria } from "../evaluation/index.js";
@@ -27,7 +28,11 @@ export type DynamicRunEvaluatorParams = {
27
28
  * While we have the class-based RunEvaluator, it's often more convenient to directly
28
29
  * pass a function to the runner. This type allows us to do that.
29
30
  */
30
- export type RunEvaluatorLike = ((props: DynamicRunEvaluatorParams) => Promise<EvaluationResult>) | ((props: DynamicRunEvaluatorParams) => EvaluationResult);
31
+ export type RunEvaluatorLike = ((props: DynamicRunEvaluatorParams, options?: {
32
+ config?: RunnableConfig;
33
+ }) => Promise<EvaluationResult>) | ((props: DynamicRunEvaluatorParams, options?: {
34
+ config?: RunnableConfig;
35
+ }) => EvaluationResult);
31
36
  /**
32
37
  * Configuration class for running evaluations on datasets.
33
38
  *
@@ -9,6 +9,36 @@ const langsmith_1 = require("langsmith");
9
9
  const loader_js_1 = require("../evaluation/loader.cjs");
10
10
  const name_generation_js_1 = require("./name_generation.cjs");
11
11
  const progress_js_1 = require("./progress.cjs");
12
+ class RunIdExtractor {
13
+ constructor() {
14
+ Object.defineProperty(this, "runIdPromiseResolver", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: void 0
19
+ });
20
+ Object.defineProperty(this, "runIdPromise", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: void 0
25
+ });
26
+ Object.defineProperty(this, "handleChainStart", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: (_chain, _inputs, runId) => {
31
+ this.runIdPromiseResolver(runId);
32
+ }
33
+ });
34
+ this.runIdPromise = new Promise((extract) => {
35
+ this.runIdPromiseResolver = extract;
36
+ });
37
+ }
38
+ async extract() {
39
+ return this.runIdPromise;
40
+ }
41
+ }
12
42
  /**
13
43
  * Wraps an evaluator function + implements the RunEvaluator interface.
14
44
  */
@@ -26,16 +56,24 @@ class DynamicRunEvaluator {
26
56
  * Evaluates a run with an optional example and returns the evaluation result.
27
57
  * @param run The run to evaluate.
28
58
  * @param example The optional example to use for evaluation.
29
- * @returns A promise that resolves to the evaluation result.
59
+ * @returns A promise that extracts to the evaluation result.
30
60
  */
31
61
  async evaluateRun(run, example) {
32
- return await this.evaluator.invoke({
62
+ const extractor = new RunIdExtractor();
63
+ const result = await this.evaluator.invoke({
33
64
  run,
34
65
  example,
35
66
  input: run.inputs,
36
67
  prediction: run.outputs,
37
68
  reference: example?.outputs,
69
+ }, {
70
+ callbacks: [extractor],
38
71
  });
72
+ const runId = await extractor.extract();
73
+ return {
74
+ sourceRunId: runId,
75
+ ...result,
76
+ };
39
77
  }
40
78
  }
41
79
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -98,7 +136,7 @@ class PreparedRunEvaluator {
98
136
  * Evaluates a run with an optional example and returns the evaluation result.
99
137
  * @param run The run to evaluate.
100
138
  * @param example The optional example to use for evaluation.
101
- * @returns A promise that resolves to the evaluation result.
139
+ * @returns A promise that extracts to the evaluation result.
102
140
  */
103
141
  async evaluateRun(run, example) {
104
142
  const { prediction, input, reference } = this.formatEvaluatorInputs({
@@ -107,15 +145,20 @@ class PreparedRunEvaluator {
107
145
  rawReferenceOutput: example?.outputs,
108
146
  run,
109
147
  });
148
+ const extractor = new RunIdExtractor();
110
149
  if (this.isStringEvaluator) {
111
150
  const evalResult = await this.evaluator.evaluateStrings({
112
151
  prediction: prediction,
113
152
  reference: reference,
114
153
  input: input,
154
+ }, {
155
+ callbacks: [extractor],
115
156
  });
157
+ const runId = await extractor.extract();
116
158
  return {
117
159
  key: this.evaluationName,
118
160
  comment: evalResult?.reasoning,
161
+ sourceRunId: runId,
119
162
  ...evalResult,
120
163
  };
121
164
  }
@@ -6,6 +6,36 @@ import { Client } from "langsmith";
6
6
  import { loadEvaluator } from "../evaluation/loader.js";
7
7
  import { randomName } from "./name_generation.js";
8
8
  import { ProgressBar } from "./progress.js";
9
+ class RunIdExtractor {
10
+ constructor() {
11
+ Object.defineProperty(this, "runIdPromiseResolver", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: void 0
16
+ });
17
+ Object.defineProperty(this, "runIdPromise", {
18
+ enumerable: true,
19
+ configurable: true,
20
+ writable: true,
21
+ value: void 0
22
+ });
23
+ Object.defineProperty(this, "handleChainStart", {
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true,
27
+ value: (_chain, _inputs, runId) => {
28
+ this.runIdPromiseResolver(runId);
29
+ }
30
+ });
31
+ this.runIdPromise = new Promise((extract) => {
32
+ this.runIdPromiseResolver = extract;
33
+ });
34
+ }
35
+ async extract() {
36
+ return this.runIdPromise;
37
+ }
38
+ }
9
39
  /**
10
40
  * Wraps an evaluator function + implements the RunEvaluator interface.
11
41
  */
@@ -23,16 +53,24 @@ class DynamicRunEvaluator {
23
53
  * Evaluates a run with an optional example and returns the evaluation result.
24
54
  * @param run The run to evaluate.
25
55
  * @param example The optional example to use for evaluation.
26
- * @returns A promise that resolves to the evaluation result.
56
+ * @returns A promise that extracts to the evaluation result.
27
57
  */
28
58
  async evaluateRun(run, example) {
29
- return await this.evaluator.invoke({
59
+ const extractor = new RunIdExtractor();
60
+ const result = await this.evaluator.invoke({
30
61
  run,
31
62
  example,
32
63
  input: run.inputs,
33
64
  prediction: run.outputs,
34
65
  reference: example?.outputs,
66
+ }, {
67
+ callbacks: [extractor],
35
68
  });
69
+ const runId = await extractor.extract();
70
+ return {
71
+ sourceRunId: runId,
72
+ ...result,
73
+ };
36
74
  }
37
75
  }
38
76
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -95,7 +133,7 @@ class PreparedRunEvaluator {
95
133
  * Evaluates a run with an optional example and returns the evaluation result.
96
134
  * @param run The run to evaluate.
97
135
  * @param example The optional example to use for evaluation.
98
- * @returns A promise that resolves to the evaluation result.
136
+ * @returns A promise that extracts to the evaluation result.
99
137
  */
100
138
  async evaluateRun(run, example) {
101
139
  const { prediction, input, reference } = this.formatEvaluatorInputs({
@@ -104,15 +142,20 @@ class PreparedRunEvaluator {
104
142
  rawReferenceOutput: example?.outputs,
105
143
  run,
106
144
  });
145
+ const extractor = new RunIdExtractor();
107
146
  if (this.isStringEvaluator) {
108
147
  const evalResult = await this.evaluator.evaluateStrings({
109
148
  prediction: prediction,
110
149
  reference: reference,
111
150
  input: input,
151
+ }, {
152
+ callbacks: [extractor],
112
153
  });
154
+ const runId = await extractor.extract();
113
155
  return {
114
156
  key: this.evaluationName,
115
157
  comment: evalResult?.reasoning,
158
+ sourceRunId: runId,
116
159
  ...evalResult,
117
160
  };
118
161
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Typescript bindings for langchain",
5
5
  "type": "module",
6
6
  "engines": {
@@ -73,6 +73,9 @@
73
73
  "tools/calculator.cjs",
74
74
  "tools/calculator.js",
75
75
  "tools/calculator.d.ts",
76
+ "tools/chain.cjs",
77
+ "tools/chain.js",
78
+ "tools/chain.d.ts",
76
79
  "tools/connery.cjs",
77
80
  "tools/connery.js",
78
81
  "tools/connery.d.ts",
@@ -876,10 +879,7 @@
876
879
  "runnables/remote.d.ts",
877
880
  "indexes.cjs",
878
881
  "indexes.js",
879
- "indexes.d.ts",
880
- "index.cjs",
881
- "index.js",
882
- "index.d.ts"
882
+ "indexes.d.ts"
883
883
  ],
884
884
  "repository": {
885
885
  "type": "git",
@@ -889,23 +889,26 @@
889
889
  "build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
890
890
  "build:deps": "yarn run turbo:command build --filter=@langchain/core --filter=@langchain/anthropic --filter=@langchain/openai --filter=@langchain/community --concurrency=1",
891
891
  "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
892
- "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && node scripts/move-cjs-to-dist.js && rimraf dist-cjs",
893
- "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
894
- "build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js",
892
+ "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs",
893
+ "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
894
+ "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
895
895
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
896
896
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
897
897
  "lint": "yarn lint:eslint && yarn lint:dpdm",
898
898
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
899
899
  "precommit": "lint-staged",
900
- "clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 node scripts/create-entrypoints.js pre",
900
+ "clean": "rimraf .turbo/ dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn create-entrypoints -- --pre --gen-maps",
901
901
  "prepack": "yarn build",
902
902
  "release": "release-it --only-version --config .release-it.json",
903
903
  "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
904
904
  "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
905
905
  "test:integration": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
906
906
  "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
907
- "format": "prettier --config .prettierrc --write \"src\" \"scripts\"",
908
- "format:check": "prettier --config .prettierrc --check \"src\" \"scripts\""
907
+ "format": "prettier --config .prettierrc --write \"src\"",
908
+ "format:check": "prettier --config .prettierrc --check \"src\"",
909
+ "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
910
+ "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
911
+ "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
909
912
  },
910
913
  "author": "LangChain",
911
914
  "license": "MIT",
@@ -923,6 +926,7 @@
923
926
  "@google-ai/generativelanguage": "^0.2.1",
924
927
  "@google-cloud/storage": "^6.10.1",
925
928
  "@jest/globals": "^29.5.0",
929
+ "@langchain/scripts": "^0.0.2",
926
930
  "@notionhq/client": "^2.2.10",
927
931
  "@pinecone-database/pinecone": "^1.1.0",
928
932
  "@supabase/supabase-js": "^2.10.0",
@@ -1349,6 +1353,11 @@
1349
1353
  "import": "./tools/calculator.js",
1350
1354
  "require": "./tools/calculator.cjs"
1351
1355
  },
1356
+ "./tools/chain": {
1357
+ "types": "./tools/chain.d.ts",
1358
+ "import": "./tools/chain.js",
1359
+ "require": "./tools/chain.cjs"
1360
+ },
1352
1361
  "./tools/connery": {
1353
1362
  "types": "./tools/connery.d.ts",
1354
1363
  "import": "./tools/connery.js",
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/tools/chain.cjs');
@@ -0,0 +1 @@
1
+ export * from '../dist/tools/chain.js'
package/tools/chain.js ADDED
@@ -0,0 +1 @@
1
+ export * from '../dist/tools/chain.js'
package/index.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/index.cjs');
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/index.js'
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './dist/index.js'