langchain 0.3.32 → 0.3.34
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 +2 -4
- package/dist/chat_models/universal.cjs +9 -4
- package/dist/chat_models/universal.js +9 -4
- package/dist/document_loaders/fs/buffer.cjs +2 -2
- package/dist/document_loaders/fs/buffer.d.ts +1 -1
- package/dist/document_loaders/fs/buffer.js +1 -1
- package/dist/document_loaders/fs/json.cjs +13 -1
- package/dist/document_loaders/fs/json.js +13 -1
- package/dist/document_loaders/fs/text.cjs +2 -2
- package/dist/document_loaders/fs/text.d.ts +1 -1
- package/dist/document_loaders/fs/text.js +1 -1
- package/dist/hub/node.cjs +26 -2
- package/dist/hub/node.js +26 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
⚡ Building applications with LLMs through composability ⚡
|
|
4
4
|
|
|
5
|
-
[](https://opensource.org/licenses/MIT)  [](https://twitter.com/langchainai) [](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/langchain-ai/langchainjs)
|
|
6
6
|
[<img src="https://github.com/codespaces/badge.svg" title="Open in Github Codespace" width="150" height="20">](https://codespaces.new/langchain-ai/langchainjs)
|
|
7
7
|
|
|
8
8
|
Looking for the Python version? Check out [LangChain](https://github.com/langchain-ai/langchain).
|
|
@@ -43,15 +43,13 @@ This framework consists of several parts.
|
|
|
43
43
|
|
|
44
44
|
The LangChain libraries themselves are made up of several different packages.
|
|
45
45
|
|
|
46
|
-
- **[`@langchain/core`](https://github.com/langchain-ai/langchainjs/blob/main/langchain-core)**: Base abstractions
|
|
46
|
+
- **[`@langchain/core`](https://github.com/langchain-ai/langchainjs/blob/main/langchain-core)**: Base abstractions.
|
|
47
47
|
- **[`@langchain/community`](https://github.com/langchain-ai/langchainjs/blob/main/libs/langchain-community)**: Third party integrations.
|
|
48
48
|
- **[`langchain`](https://github.com/langchain-ai/langchainjs/blob/main/langchain)**: Chains, agents, and retrieval strategies that make up an application's cognitive architecture.
|
|
49
49
|
- **[LangGraph.js](https://langchain-ai.github.io/langgraphjs/)**: LangGraph powers production-grade agents, trusted by Linkedin, Uber, Klarna, GitLab, and many more. Build robust and stateful multi-actor applications with LLMs by modeling steps as edges and nodes in a graph. Integrates smoothly with LangChain, but can be used without it.
|
|
50
50
|
|
|
51
51
|
Integrations may also be split into their own compatible packages.
|
|
52
52
|
|
|
53
|
-

|
|
54
|
-
|
|
55
53
|
This library aims to assist in the development of those types of applications. Common examples of these applications include:
|
|
56
54
|
|
|
57
55
|
**❓Question Answering over specific documents**
|
|
@@ -200,6 +200,9 @@ function _inferModelProvider(modelName) {
|
|
|
200
200
|
else if (modelName.startsWith("amazon.")) {
|
|
201
201
|
return "bedrock";
|
|
202
202
|
}
|
|
203
|
+
else if (modelName.startsWith("mistral")) {
|
|
204
|
+
return "mistralai";
|
|
205
|
+
}
|
|
203
206
|
else {
|
|
204
207
|
return undefined;
|
|
205
208
|
}
|
|
@@ -263,12 +266,13 @@ class ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
263
266
|
configurable: true,
|
|
264
267
|
writable: true,
|
|
265
268
|
value: (schema, ...args) => {
|
|
266
|
-
|
|
269
|
+
const newQueuedOperations = { ...this._queuedMethodOperations };
|
|
270
|
+
newQueuedOperations.withStructuredOutput = [schema, ...args];
|
|
267
271
|
return new ConfigurableModel({
|
|
268
272
|
defaultConfig: this._defaultConfig,
|
|
269
273
|
configurableFields: this._configurableFields,
|
|
270
274
|
configPrefix: this._configPrefix,
|
|
271
|
-
queuedMethodOperations:
|
|
275
|
+
queuedMethodOperations: newQueuedOperations,
|
|
272
276
|
});
|
|
273
277
|
}
|
|
274
278
|
});
|
|
@@ -317,12 +321,13 @@ class ConfigurableModel extends chat_models_1.BaseChatModel {
|
|
|
317
321
|
bindTools(tools,
|
|
318
322
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
319
323
|
params) {
|
|
320
|
-
this._queuedMethodOperations
|
|
324
|
+
const newQueuedOperations = { ...this._queuedMethodOperations };
|
|
325
|
+
newQueuedOperations.bindTools = [tools, params];
|
|
321
326
|
return new ConfigurableModel({
|
|
322
327
|
defaultConfig: this._defaultConfig,
|
|
323
328
|
configurableFields: this._configurableFields,
|
|
324
329
|
configPrefix: this._configPrefix,
|
|
325
|
-
queuedMethodOperations:
|
|
330
|
+
queuedMethodOperations: newQueuedOperations,
|
|
326
331
|
});
|
|
327
332
|
}
|
|
328
333
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -162,6 +162,9 @@ export function _inferModelProvider(modelName) {
|
|
|
162
162
|
else if (modelName.startsWith("amazon.")) {
|
|
163
163
|
return "bedrock";
|
|
164
164
|
}
|
|
165
|
+
else if (modelName.startsWith("mistral")) {
|
|
166
|
+
return "mistralai";
|
|
167
|
+
}
|
|
165
168
|
else {
|
|
166
169
|
return undefined;
|
|
167
170
|
}
|
|
@@ -225,12 +228,13 @@ export class ConfigurableModel extends BaseChatModel {
|
|
|
225
228
|
configurable: true,
|
|
226
229
|
writable: true,
|
|
227
230
|
value: (schema, ...args) => {
|
|
228
|
-
|
|
231
|
+
const newQueuedOperations = { ...this._queuedMethodOperations };
|
|
232
|
+
newQueuedOperations.withStructuredOutput = [schema, ...args];
|
|
229
233
|
return new ConfigurableModel({
|
|
230
234
|
defaultConfig: this._defaultConfig,
|
|
231
235
|
configurableFields: this._configurableFields,
|
|
232
236
|
configPrefix: this._configPrefix,
|
|
233
|
-
queuedMethodOperations:
|
|
237
|
+
queuedMethodOperations: newQueuedOperations,
|
|
234
238
|
});
|
|
235
239
|
}
|
|
236
240
|
});
|
|
@@ -279,12 +283,13 @@ export class ConfigurableModel extends BaseChatModel {
|
|
|
279
283
|
bindTools(tools,
|
|
280
284
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
281
285
|
params) {
|
|
282
|
-
this._queuedMethodOperations
|
|
286
|
+
const newQueuedOperations = { ...this._queuedMethodOperations };
|
|
287
|
+
newQueuedOperations.bindTools = [tools, params];
|
|
283
288
|
return new ConfigurableModel({
|
|
284
289
|
defaultConfig: this._defaultConfig,
|
|
285
290
|
configurableFields: this._configurableFields,
|
|
286
291
|
configPrefix: this._configPrefix,
|
|
287
|
-
queuedMethodOperations:
|
|
292
|
+
queuedMethodOperations: newQueuedOperations,
|
|
288
293
|
});
|
|
289
294
|
}
|
|
290
295
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.BufferLoader = void 0;
|
|
37
37
|
const env_1 = require("@langchain/core/utils/env");
|
|
38
|
-
const
|
|
38
|
+
const base_1 = require("@langchain/core/document_loaders/base");
|
|
39
39
|
/**
|
|
40
40
|
* Abstract class that extends the `BaseDocumentLoader` class. It
|
|
41
41
|
* represents a document loader that loads documents from a buffer. The
|
|
@@ -43,7 +43,7 @@ const base_js_1 = require("../base.cjs");
|
|
|
43
43
|
* based on the type of `filePathOrBlob`, and then calls the `parse()`
|
|
44
44
|
* method to parse the buffer and return the documents.
|
|
45
45
|
*/
|
|
46
|
-
class BufferLoader extends
|
|
46
|
+
class BufferLoader extends base_1.BaseDocumentLoader {
|
|
47
47
|
constructor(filePathOrBlob) {
|
|
48
48
|
super();
|
|
49
49
|
Object.defineProperty(this, "filePathOrBlob", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { readFile as ReadFileT } from "node:fs/promises";
|
|
2
2
|
import { Document } from "@langchain/core/documents";
|
|
3
|
-
import { BaseDocumentLoader } from "
|
|
3
|
+
import { BaseDocumentLoader } from "@langchain/core/document_loaders/base";
|
|
4
4
|
/**
|
|
5
5
|
* Abstract class that extends the `BaseDocumentLoader` class. It
|
|
6
6
|
* represents a document loader that loads documents from a buffer. The
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEnv } from "@langchain/core/utils/env";
|
|
2
|
-
import { BaseDocumentLoader } from "
|
|
2
|
+
import { BaseDocumentLoader } from "@langchain/core/document_loaders/base";
|
|
3
3
|
/**
|
|
4
4
|
* Abstract class that extends the `BaseDocumentLoader` class. It
|
|
5
5
|
* represents a document loader that loads documents from a buffer. The
|
|
@@ -141,7 +141,19 @@ class JSONLinesLoader extends text_js_1.TextLoader {
|
|
|
141
141
|
.filter(Boolean)
|
|
142
142
|
.map((line) => JSON.parse(line));
|
|
143
143
|
const pointer = jsonpointer_1.default.compile(this.pointer);
|
|
144
|
-
return jsons.map((json) =>
|
|
144
|
+
return jsons.map((json) => {
|
|
145
|
+
const data = pointer.get(json);
|
|
146
|
+
if (typeof data === "string") {
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
if (!data) {
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
if (typeof data === "object") {
|
|
153
|
+
return JSON.stringify(data);
|
|
154
|
+
}
|
|
155
|
+
return "";
|
|
156
|
+
});
|
|
145
157
|
}
|
|
146
158
|
}
|
|
147
159
|
exports.JSONLinesLoader = JSONLinesLoader;
|
|
@@ -134,6 +134,18 @@ export class JSONLinesLoader extends TextLoader {
|
|
|
134
134
|
.filter(Boolean)
|
|
135
135
|
.map((line) => JSON.parse(line));
|
|
136
136
|
const pointer = jsonpointer.compile(this.pointer);
|
|
137
|
-
return jsons.map((json) =>
|
|
137
|
+
return jsons.map((json) => {
|
|
138
|
+
const data = pointer.get(json);
|
|
139
|
+
if (typeof data === "string") {
|
|
140
|
+
return data;
|
|
141
|
+
}
|
|
142
|
+
if (!data) {
|
|
143
|
+
return "";
|
|
144
|
+
}
|
|
145
|
+
if (typeof data === "object") {
|
|
146
|
+
return JSON.stringify(data);
|
|
147
|
+
}
|
|
148
|
+
return "";
|
|
149
|
+
});
|
|
138
150
|
}
|
|
139
151
|
}
|
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.TextLoader = void 0;
|
|
37
37
|
const documents_1 = require("@langchain/core/documents");
|
|
38
38
|
const env_1 = require("@langchain/core/utils/env");
|
|
39
|
-
const
|
|
39
|
+
const base_1 = require("@langchain/core/document_loaders/base");
|
|
40
40
|
/**
|
|
41
41
|
* A class that extends the `BaseDocumentLoader` class. It represents a
|
|
42
42
|
* document loader that loads documents from a text file. The `load()`
|
|
@@ -50,7 +50,7 @@ const base_js_1 = require("../base.cjs");
|
|
|
50
50
|
* const docs = await loader.load();
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
|
-
class TextLoader extends
|
|
53
|
+
class TextLoader extends base_1.BaseDocumentLoader {
|
|
54
54
|
constructor(filePathOrBlob) {
|
|
55
55
|
super();
|
|
56
56
|
Object.defineProperty(this, "filePathOrBlob", {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { readFile as ReadFileT } from "node:fs/promises";
|
|
2
2
|
import { Document } from "@langchain/core/documents";
|
|
3
|
-
import { BaseDocumentLoader } from "
|
|
3
|
+
import { BaseDocumentLoader } from "@langchain/core/document_loaders/base";
|
|
4
4
|
/**
|
|
5
5
|
* A class that extends the `BaseDocumentLoader` class. It represents a
|
|
6
6
|
* document loader that loads documents from a text file. The `load()`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Document } from "@langchain/core/documents";
|
|
2
2
|
import { getEnv } from "@langchain/core/utils/env";
|
|
3
|
-
import { BaseDocumentLoader } from "
|
|
3
|
+
import { BaseDocumentLoader } from "@langchain/core/document_loaders/base";
|
|
4
4
|
/**
|
|
5
5
|
* A class that extends the `BaseDocumentLoader` class. It represents a
|
|
6
6
|
* document loader that loads documents from a text file. The `load()`
|
package/dist/hub/node.cjs
CHANGED
|
@@ -38,6 +38,27 @@ exports.pull = pull;
|
|
|
38
38
|
const base_js_1 = require("./base.cjs");
|
|
39
39
|
Object.defineProperty(exports, "push", { enumerable: true, get: function () { return base_js_1.basePush; } });
|
|
40
40
|
const index_js_1 = require("../load/index.cjs");
|
|
41
|
+
function _idEquals(a, b) {
|
|
42
|
+
if (!Array.isArray(a) || !Array.isArray(b)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (a.length !== b.length) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < a.length; i++) {
|
|
49
|
+
if (a[i] !== b[i]) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
function isRunnableBinding(a) {
|
|
56
|
+
const wellKnownIds = [
|
|
57
|
+
["langchain_core", "runnables", "RunnableBinding"],
|
|
58
|
+
["langchain", "schema", "runnable", "RunnableBinding"],
|
|
59
|
+
];
|
|
60
|
+
return wellKnownIds.some((id) => _idEquals(a, id));
|
|
61
|
+
}
|
|
41
62
|
/**
|
|
42
63
|
* Pull a prompt from the hub.
|
|
43
64
|
* @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
|
|
@@ -52,8 +73,11 @@ async function pull(ownerRepoCommit, options) {
|
|
|
52
73
|
const promptObject = await (0, base_js_1.basePull)(ownerRepoCommit, options);
|
|
53
74
|
let modelClass;
|
|
54
75
|
if (options?.includeModel) {
|
|
55
|
-
|
|
56
|
-
|
|
76
|
+
const chatModelObject = isRunnableBinding(promptObject.manifest.kwargs?.last?.id)
|
|
77
|
+
? promptObject.manifest.kwargs?.last?.kwargs?.bound
|
|
78
|
+
: promptObject.manifest.kwargs?.last;
|
|
79
|
+
if (Array.isArray(chatModelObject?.id)) {
|
|
80
|
+
const modelName = chatModelObject?.id.at(-1);
|
|
57
81
|
if (modelName === "ChatOpenAI") {
|
|
58
82
|
modelClass = (await Promise.resolve().then(() => __importStar(require("@langchain/openai")))).ChatOpenAI;
|
|
59
83
|
}
|
package/dist/hub/node.js
CHANGED
|
@@ -2,6 +2,27 @@ import { basePush, basePull, generateModelImportMap, generateOptionalImportMap,
|
|
|
2
2
|
import { load } from "../load/index.js";
|
|
3
3
|
// TODO: Make this the default, add web entrypoint in next breaking release
|
|
4
4
|
export { basePush as push };
|
|
5
|
+
function _idEquals(a, b) {
|
|
6
|
+
if (!Array.isArray(a) || !Array.isArray(b)) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
if (a.length !== b.length) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
for (let i = 0; i < a.length; i++) {
|
|
13
|
+
if (a[i] !== b[i]) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
function isRunnableBinding(a) {
|
|
20
|
+
const wellKnownIds = [
|
|
21
|
+
["langchain_core", "runnables", "RunnableBinding"],
|
|
22
|
+
["langchain", "schema", "runnable", "RunnableBinding"],
|
|
23
|
+
];
|
|
24
|
+
return wellKnownIds.some((id) => _idEquals(a, id));
|
|
25
|
+
}
|
|
5
26
|
/**
|
|
6
27
|
* Pull a prompt from the hub.
|
|
7
28
|
* @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
|
|
@@ -16,8 +37,11 @@ export async function pull(ownerRepoCommit, options) {
|
|
|
16
37
|
const promptObject = await basePull(ownerRepoCommit, options);
|
|
17
38
|
let modelClass;
|
|
18
39
|
if (options?.includeModel) {
|
|
19
|
-
|
|
20
|
-
|
|
40
|
+
const chatModelObject = isRunnableBinding(promptObject.manifest.kwargs?.last?.id)
|
|
41
|
+
? promptObject.manifest.kwargs?.last?.kwargs?.bound
|
|
42
|
+
: promptObject.manifest.kwargs?.last;
|
|
43
|
+
if (Array.isArray(chatModelObject?.id)) {
|
|
44
|
+
const modelName = chatModelObject?.id.at(-1);
|
|
21
45
|
if (modelName === "ChatOpenAI") {
|
|
22
46
|
modelClass = (await import("@langchain/openai")).ChatOpenAI;
|
|
23
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.34",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -440,7 +440,7 @@
|
|
|
440
440
|
"@types/ws": "^8",
|
|
441
441
|
"@typescript-eslint/eslint-plugin": "^5.58.0",
|
|
442
442
|
"@typescript-eslint/parser": "^5.58.0",
|
|
443
|
-
"axios": "^1.
|
|
443
|
+
"axios": "^1.12.0",
|
|
444
444
|
"cheerio": "1.0.0-rc.12",
|
|
445
445
|
"dotenv": "^16.0.3",
|
|
446
446
|
"dpdm": "^3.14.0",
|
|
@@ -545,7 +545,7 @@
|
|
|
545
545
|
"js-tiktoken": "^1.0.12",
|
|
546
546
|
"js-yaml": "^4.1.0",
|
|
547
547
|
"jsonpointer": "^5.0.1",
|
|
548
|
-
"langsmith": "^0.3.
|
|
548
|
+
"langsmith": "^0.3.67",
|
|
549
549
|
"openapi-types": "^12.1.3",
|
|
550
550
|
"p-retry": "4",
|
|
551
551
|
"uuid": "^10.0.0",
|