langchain 0.1.6 → 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.
Files changed (38) hide show
  1. package/dist/agents/react/prompt.cjs +1 -1
  2. package/dist/agents/react/prompt.js +1 -1
  3. package/dist/agents/toolkits/conversational_retrieval/openai_functions.cjs +3 -1
  4. package/dist/agents/toolkits/conversational_retrieval/openai_functions.d.ts +1 -0
  5. package/dist/agents/toolkits/conversational_retrieval/openai_functions.js +3 -1
  6. package/dist/chains/constitutional_ai/constitutional_principle.js +1 -1
  7. package/dist/document_loaders/web/github.cjs +1 -1
  8. package/dist/document_loaders/web/github.js +1 -1
  9. package/dist/evaluation/comparison/pairwise.cjs +1 -1
  10. package/dist/evaluation/comparison/pairwise.js +1 -1
  11. package/dist/evaluation/criteria/criteria.cjs +1 -1
  12. package/dist/evaluation/criteria/criteria.js +1 -1
  13. package/dist/indexes/index.cjs +5 -0
  14. package/dist/indexes/index.d.ts +1 -0
  15. package/dist/indexes/index.js +1 -0
  16. package/dist/indexes/indexing.cjs +265 -0
  17. package/dist/indexes/indexing.d.ts +75 -0
  18. package/dist/indexes/indexing.js +261 -0
  19. package/dist/load/import_map.cjs +2 -1
  20. package/dist/load/import_map.d.ts +1 -0
  21. package/dist/load/import_map.js +1 -0
  22. package/dist/smith/config.d.ts +76 -26
  23. package/dist/smith/index.cjs +15 -0
  24. package/dist/smith/index.d.ts +3 -3
  25. package/dist/smith/index.js +2 -1
  26. package/dist/smith/runner_utils.cjs +56 -6
  27. package/dist/smith/runner_utils.d.ts +4 -4
  28. package/dist/smith/runner_utils.js +57 -7
  29. package/indexes.cjs +1 -0
  30. package/indexes.d.ts +1 -0
  31. package/indexes.js +1 -0
  32. package/package.json +28 -11
  33. package/tools/chain.cjs +1 -0
  34. package/tools/chain.d.ts +1 -0
  35. package/tools/chain.js +1 -0
  36. package/index.cjs +0 -1
  37. package/index.d.ts +0 -1
  38. package/index.js +0 -1
@@ -1,11 +1,41 @@
1
1
  import { mapStoredMessagesToChatMessages } from "@langchain/core/messages";
2
- import { Runnable, RunnableLambda } from "@langchain/core/runnables";
2
+ import { Runnable, RunnableLambda, } from "@langchain/core/runnables";
3
3
  import { RunCollectorCallbackHandler } from "@langchain/core/tracers/run_collector";
4
4
  import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";
5
5
  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,12 +53,27 @@ 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({ run, example });
59
+ const extractor = new RunIdExtractor();
60
+ const result = await this.evaluator.invoke({
61
+ run,
62
+ example,
63
+ input: run.inputs,
64
+ prediction: run.outputs,
65
+ reference: example?.outputs,
66
+ }, {
67
+ callbacks: [extractor],
68
+ });
69
+ const runId = await extractor.extract();
70
+ return {
71
+ sourceRunId: runId,
72
+ ...result,
73
+ };
30
74
  }
31
75
  }
76
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
77
  function isLLMStringEvaluator(evaluator) {
33
78
  return evaluator && typeof evaluator.evaluateStrings === "function";
34
79
  }
@@ -88,7 +133,7 @@ class PreparedRunEvaluator {
88
133
  * Evaluates a run with an optional example and returns the evaluation result.
89
134
  * @param run The run to evaluate.
90
135
  * @param example The optional example to use for evaluation.
91
- * @returns A promise that resolves to the evaluation result.
136
+ * @returns A promise that extracts to the evaluation result.
92
137
  */
93
138
  async evaluateRun(run, example) {
94
139
  const { prediction, input, reference } = this.formatEvaluatorInputs({
@@ -97,15 +142,20 @@ class PreparedRunEvaluator {
97
142
  rawReferenceOutput: example?.outputs,
98
143
  run,
99
144
  });
145
+ const extractor = new RunIdExtractor();
100
146
  if (this.isStringEvaluator) {
101
147
  const evalResult = await this.evaluator.evaluateStrings({
102
148
  prediction: prediction,
103
149
  reference: reference,
104
150
  input: input,
151
+ }, {
152
+ callbacks: [extractor],
105
153
  });
154
+ const runId = await extractor.extract();
106
155
  return {
107
156
  key: this.evaluationName,
108
157
  comment: evalResult?.reasoning,
158
+ sourceRunId: runId,
109
159
  ...evalResult,
110
160
  };
111
161
  }
@@ -251,7 +301,7 @@ const getExamplesInputs = (examples, chainOrFactory, dataType) => {
251
301
  * for evaluation.
252
302
  *
253
303
  * @param options - (Optional) Additional parameters for the evaluation process:
254
- * - `evaluation` (RunEvalConfig): Configuration for the evaluation, including
304
+ * - `evaluationConfig` (RunEvalConfig): Configuration for the evaluation, including
255
305
  * standard and custom evaluators.
256
306
  * - `projectName` (string): Name of the project for logging and tracking.
257
307
  * - `projectMetadata` (Record<string, unknown>): Additional metadata for the project.
@@ -270,10 +320,10 @@ const getExamplesInputs = (examples, chainOrFactory, dataType) => {
270
320
  * const datasetName = 'example-dataset';
271
321
  * const client = new Client(/* ...config... *\//);
272
322
  *
273
- * const evaluationConfig = new RunEvalConfig({
323
+ * const evaluationConfig = {
274
324
  * evaluators: [/* ...evaluators... *\//],
275
325
  * customEvaluators: [/* ...custom evaluators... *\//],
276
- * });
326
+ * };
277
327
  *
278
328
  * const results = await runOnDataset(chain, datasetName, {
279
329
  * evaluationConfig,
package/indexes.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/indexes/index.cjs');
package/indexes.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/indexes/index.js'
package/indexes.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/indexes/index.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langchain",
3
- "version": "0.1.6",
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",
@@ -874,9 +877,9 @@
874
877
  "runnables/remote.cjs",
875
878
  "runnables/remote.js",
876
879
  "runnables/remote.d.ts",
877
- "index.cjs",
878
- "index.js",
879
- "index.d.ts"
880
+ "indexes.cjs",
881
+ "indexes.js",
882
+ "indexes.d.ts"
880
883
  ],
881
884
  "repository": {
882
885
  "type": "git",
@@ -886,23 +889,26 @@
886
889
  "build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
887
890
  "build:deps": "yarn run turbo:command build --filter=@langchain/core --filter=@langchain/anthropic --filter=@langchain/openai --filter=@langchain/community --concurrency=1",
888
891
  "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests",
889
- "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",
890
- "build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
891
- "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",
892
895
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
893
896
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
894
897
  "lint": "yarn lint:eslint && yarn lint:dpdm",
895
898
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
896
899
  "precommit": "lint-staged",
897
- "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",
898
901
  "prepack": "yarn build",
899
902
  "release": "release-it --only-version --config .release-it.json",
900
903
  "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
901
904
  "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
902
905
  "test:integration": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
903
906
  "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
904
- "format": "prettier --config .prettierrc --write \"src\" \"scripts\"",
905
- "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"
906
912
  },
907
913
  "author": "LangChain",
908
914
  "license": "MIT",
@@ -920,6 +926,7 @@
920
926
  "@google-ai/generativelanguage": "^0.2.1",
921
927
  "@google-cloud/storage": "^6.10.1",
922
928
  "@jest/globals": "^29.5.0",
929
+ "@langchain/scripts": "^0.0.2",
923
930
  "@notionhq/client": "^2.2.10",
924
931
  "@pinecone-database/pinecone": "^1.1.0",
925
932
  "@supabase/supabase-js": "^2.10.0",
@@ -1205,7 +1212,7 @@
1205
1212
  },
1206
1213
  "dependencies": {
1207
1214
  "@anthropic-ai/sdk": "^0.9.1",
1208
- "@langchain/community": "~0.0.17",
1215
+ "@langchain/community": "~0.0.20",
1209
1216
  "@langchain/core": "~0.1.16",
1210
1217
  "@langchain/openai": "~0.0.12",
1211
1218
  "binary-extensions": "^2.2.0",
@@ -1346,6 +1353,11 @@
1346
1353
  "import": "./tools/calculator.js",
1347
1354
  "require": "./tools/calculator.cjs"
1348
1355
  },
1356
+ "./tools/chain": {
1357
+ "types": "./tools/chain.d.ts",
1358
+ "import": "./tools/chain.js",
1359
+ "require": "./tools/chain.cjs"
1360
+ },
1349
1361
  "./tools/connery": {
1350
1362
  "types": "./tools/connery.d.ts",
1351
1363
  "import": "./tools/connery.js",
@@ -2681,6 +2693,11 @@
2681
2693
  "import": "./runnables/remote.js",
2682
2694
  "require": "./runnables/remote.cjs"
2683
2695
  },
2696
+ "./indexes": {
2697
+ "types": "./indexes.d.ts",
2698
+ "import": "./indexes.js",
2699
+ "require": "./indexes.cjs"
2700
+ },
2684
2701
  "./package.json": "./package.json"
2685
2702
  }
2686
2703
  }
@@ -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'