langchain 0.1.4 → 0.1.5
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/chat_models/anthropic.cjs +2 -0
- package/dist/chat_models/anthropic.js +2 -0
- package/dist/experimental/chat_models/anthropic_functions.cjs +11 -2
- package/dist/experimental/chat_models/anthropic_functions.d.ts +3 -0
- package/dist/experimental/chat_models/anthropic_functions.js +11 -2
- package/dist/retrievers/self_query/pinecone.d.ts +2 -2
- package/dist/runnables/remote.cjs +2 -1
- package/dist/runnables/remote.d.ts +1 -0
- package/dist/runnables/remote.js +2 -1
- package/dist/text_splitter.cjs +6 -5
- package/dist/text_splitter.js +6 -5
- package/dist/util/sql_utils.cjs +16 -9
- package/dist/util/sql_utils.js +16 -9
- package/dist/vectorstores/pinecone.cjs +2 -0
- package/dist/vectorstores/pinecone.js +2 -0
- package/package.json +3 -3
|
@@ -36,6 +36,8 @@ function getAnthropicPromptFromMessage(message) {
|
|
|
36
36
|
return sdk_1.HUMAN_PROMPT;
|
|
37
37
|
case "system":
|
|
38
38
|
return "";
|
|
39
|
+
case "function":
|
|
40
|
+
return sdk_1.HUMAN_PROMPT;
|
|
39
41
|
case "generic": {
|
|
40
42
|
if (!messages_1.ChatMessage.isInstance(message))
|
|
41
43
|
throw new Error("Invalid generic chat message");
|
|
@@ -32,6 +32,8 @@ function getAnthropicPromptFromMessage(message) {
|
|
|
32
32
|
return HUMAN_PROMPT;
|
|
33
33
|
case "system":
|
|
34
34
|
return "";
|
|
35
|
+
case "function":
|
|
36
|
+
return HUMAN_PROMPT;
|
|
35
37
|
case "generic": {
|
|
36
38
|
if (!ChatMessage.isInstance(message))
|
|
37
39
|
throw new Error("Invalid generic chat message");
|
|
@@ -10,7 +10,8 @@ const anthropic_js_1 = require("../../chat_models/anthropic.cjs");
|
|
|
10
10
|
const TOOL_SYSTEM_PROMPT =
|
|
11
11
|
/* #__PURE__ */
|
|
12
12
|
prompts_1.PromptTemplate.fromTemplate(`In addition to responding, you can use tools.
|
|
13
|
-
You
|
|
13
|
+
You should use tools as often as you can, as they return the most accurate information possible.
|
|
14
|
+
You have access to the following tools:
|
|
14
15
|
|
|
15
16
|
{tools}
|
|
16
17
|
|
|
@@ -45,6 +46,12 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
45
46
|
writable: true,
|
|
46
47
|
value: void 0
|
|
47
48
|
});
|
|
49
|
+
Object.defineProperty(this, "systemPromptTemplate", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: void 0
|
|
54
|
+
});
|
|
48
55
|
Object.defineProperty(this, "lc_namespace", {
|
|
49
56
|
enumerable: true,
|
|
50
57
|
configurable: true,
|
|
@@ -52,6 +59,8 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
52
59
|
value: ["langchain", "experimental", "chat_models"]
|
|
53
60
|
});
|
|
54
61
|
this.llm = fields?.llm ?? new anthropic_js_1.ChatAnthropic(fields);
|
|
62
|
+
this.systemPromptTemplate =
|
|
63
|
+
fields?.systemPromptTemplate ?? TOOL_SYSTEM_PROMPT;
|
|
55
64
|
this.stopSequences =
|
|
56
65
|
fields?.stopSequences ?? this.llm.stopSequences;
|
|
57
66
|
}
|
|
@@ -74,7 +83,7 @@ class AnthropicFunctions extends chat_models_1.BaseChatModel {
|
|
|
74
83
|
options.functions = (options.functions ?? []).concat(options.tools.map(function_calling_1.convertToOpenAIFunction));
|
|
75
84
|
}
|
|
76
85
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
77
|
-
const content = await
|
|
86
|
+
const content = await this.systemPromptTemplate.format({
|
|
78
87
|
tools: JSON.stringify(options.functions, null, 2),
|
|
79
88
|
});
|
|
80
89
|
const systemMessage = new messages_1.SystemMessage({ content });
|
|
@@ -4,16 +4,19 @@ import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
|
|
4
4
|
import { BaseChatModel, BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
5
5
|
import { BaseFunctionCallOptions } from "@langchain/core/language_models/base";
|
|
6
6
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
7
|
+
import { BasePromptTemplate } from "@langchain/core/prompts";
|
|
7
8
|
import { type AnthropicInput } from "../../chat_models/anthropic.js";
|
|
8
9
|
export interface ChatAnthropicFunctionsCallOptions extends BaseFunctionCallOptions {
|
|
9
10
|
tools?: StructuredToolInterface[];
|
|
10
11
|
}
|
|
11
12
|
export type AnthropicFunctionsInput = Partial<AnthropicInput> & BaseChatModelParams & {
|
|
12
13
|
llm?: BaseChatModel;
|
|
14
|
+
systemPromptTemplate?: BasePromptTemplate;
|
|
13
15
|
};
|
|
14
16
|
export declare class AnthropicFunctions extends BaseChatModel<ChatAnthropicFunctionsCallOptions> {
|
|
15
17
|
llm: BaseChatModel;
|
|
16
18
|
stopSequences?: string[];
|
|
19
|
+
systemPromptTemplate: BasePromptTemplate;
|
|
17
20
|
lc_namespace: string[];
|
|
18
21
|
static lc_name(): string;
|
|
19
22
|
constructor(fields?: AnthropicFunctionsInput);
|
|
@@ -7,7 +7,8 @@ import { ChatAnthropic, DEFAULT_STOP_SEQUENCES, } from "../../chat_models/anthro
|
|
|
7
7
|
const TOOL_SYSTEM_PROMPT =
|
|
8
8
|
/* #__PURE__ */
|
|
9
9
|
PromptTemplate.fromTemplate(`In addition to responding, you can use tools.
|
|
10
|
-
You
|
|
10
|
+
You should use tools as often as you can, as they return the most accurate information possible.
|
|
11
|
+
You have access to the following tools:
|
|
11
12
|
|
|
12
13
|
{tools}
|
|
13
14
|
|
|
@@ -42,6 +43,12 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
42
43
|
writable: true,
|
|
43
44
|
value: void 0
|
|
44
45
|
});
|
|
46
|
+
Object.defineProperty(this, "systemPromptTemplate", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: void 0
|
|
51
|
+
});
|
|
45
52
|
Object.defineProperty(this, "lc_namespace", {
|
|
46
53
|
enumerable: true,
|
|
47
54
|
configurable: true,
|
|
@@ -49,6 +56,8 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
49
56
|
value: ["langchain", "experimental", "chat_models"]
|
|
50
57
|
});
|
|
51
58
|
this.llm = fields?.llm ?? new ChatAnthropic(fields);
|
|
59
|
+
this.systemPromptTemplate =
|
|
60
|
+
fields?.systemPromptTemplate ?? TOOL_SYSTEM_PROMPT;
|
|
52
61
|
this.stopSequences =
|
|
53
62
|
fields?.stopSequences ?? this.llm.stopSequences;
|
|
54
63
|
}
|
|
@@ -71,7 +80,7 @@ export class AnthropicFunctions extends BaseChatModel {
|
|
|
71
80
|
options.functions = (options.functions ?? []).concat(options.tools.map(convertToOpenAIFunction));
|
|
72
81
|
}
|
|
73
82
|
if (options.functions !== undefined && options.functions.length > 0) {
|
|
74
|
-
const content = await
|
|
83
|
+
const content = await this.systemPromptTemplate.format({
|
|
75
84
|
tools: JSON.stringify(options.functions, null, 2),
|
|
76
85
|
});
|
|
77
86
|
const systemMessage = new SystemMessage({ content });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { VectorStoreInterface } from "@langchain/core/vectorstores";
|
|
2
2
|
import { BasicTranslator } from "./base.js";
|
|
3
3
|
/**
|
|
4
4
|
* Specialized translator class that extends the BasicTranslator. It is
|
|
@@ -21,6 +21,6 @@ import { BasicTranslator } from "./base.js";
|
|
|
21
21
|
* );
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare class PineconeTranslator<T extends
|
|
24
|
+
export declare class PineconeTranslator<T extends VectorStoreInterface> extends BasicTranslator<T> {
|
|
25
25
|
constructor();
|
|
26
26
|
}
|
|
@@ -219,8 +219,9 @@ class RemoteRunnable extends runnables_1.Runnable {
|
|
|
219
219
|
body: JSON.stringify(body),
|
|
220
220
|
headers: {
|
|
221
221
|
"Content-Type": "application/json",
|
|
222
|
+
...this.options?.headers,
|
|
222
223
|
},
|
|
223
|
-
signal: AbortSignal.timeout(this.options?.timeout ??
|
|
224
|
+
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
async invoke(input, options) {
|
|
@@ -4,6 +4,7 @@ import { type LogStreamCallbackHandlerInput, type RunLogPatch } from "@langchain
|
|
|
4
4
|
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
5
5
|
type RemoteRunnableOptions = {
|
|
6
6
|
timeout?: number;
|
|
7
|
+
headers?: Record<string, unknown>;
|
|
7
8
|
};
|
|
8
9
|
export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
9
10
|
private url;
|
package/dist/runnables/remote.js
CHANGED
|
@@ -216,8 +216,9 @@ export class RemoteRunnable extends Runnable {
|
|
|
216
216
|
body: JSON.stringify(body),
|
|
217
217
|
headers: {
|
|
218
218
|
"Content-Type": "application/json",
|
|
219
|
+
...this.options?.headers,
|
|
219
220
|
},
|
|
220
|
-
signal: AbortSignal.timeout(this.options?.timeout ??
|
|
221
|
+
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
221
222
|
});
|
|
222
223
|
}
|
|
223
224
|
async invoke(input, options) {
|
package/dist/text_splitter.cjs
CHANGED
|
@@ -691,13 +691,14 @@ class TokenTextSplitter extends TextSplitter {
|
|
|
691
691
|
const splits = [];
|
|
692
692
|
const input_ids = this.tokenizer.encode(text, this.allowedSpecial, this.disallowedSpecial);
|
|
693
693
|
let start_idx = 0;
|
|
694
|
-
let cur_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
695
|
-
let chunk_ids = input_ids.slice(start_idx, cur_idx);
|
|
696
694
|
while (start_idx < input_ids.length) {
|
|
695
|
+
if (start_idx > 0) {
|
|
696
|
+
start_idx -= this.chunkOverlap;
|
|
697
|
+
}
|
|
698
|
+
const end_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
699
|
+
const chunk_ids = input_ids.slice(start_idx, end_idx);
|
|
697
700
|
splits.push(this.tokenizer.decode(chunk_ids));
|
|
698
|
-
start_idx
|
|
699
|
-
cur_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
700
|
-
chunk_ids = input_ids.slice(start_idx, cur_idx);
|
|
701
|
+
start_idx = end_idx;
|
|
701
702
|
}
|
|
702
703
|
return splits;
|
|
703
704
|
}
|
package/dist/text_splitter.js
CHANGED
|
@@ -685,13 +685,14 @@ export class TokenTextSplitter extends TextSplitter {
|
|
|
685
685
|
const splits = [];
|
|
686
686
|
const input_ids = this.tokenizer.encode(text, this.allowedSpecial, this.disallowedSpecial);
|
|
687
687
|
let start_idx = 0;
|
|
688
|
-
let cur_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
689
|
-
let chunk_ids = input_ids.slice(start_idx, cur_idx);
|
|
690
688
|
while (start_idx < input_ids.length) {
|
|
689
|
+
if (start_idx > 0) {
|
|
690
|
+
start_idx -= this.chunkOverlap;
|
|
691
|
+
}
|
|
692
|
+
const end_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
693
|
+
const chunk_ids = input_ids.slice(start_idx, end_idx);
|
|
691
694
|
splits.push(this.tokenizer.decode(chunk_ids));
|
|
692
|
-
start_idx
|
|
693
|
-
cur_idx = Math.min(start_idx + this.chunkSize, input_ids.length);
|
|
694
|
-
chunk_ids = input_ids.slice(start_idx, cur_idx);
|
|
695
|
+
start_idx = end_idx;
|
|
695
696
|
}
|
|
696
697
|
return splits;
|
|
697
698
|
}
|
package/dist/util/sql_utils.cjs
CHANGED
|
@@ -96,14 +96,15 @@ const getTableAndColumnsName = async (appDataSource) => {
|
|
|
96
96
|
return formatToSqlTable(rep);
|
|
97
97
|
}
|
|
98
98
|
if (appDataSource.options.type === "mssql") {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
const schema = appDataSource.options?.schema;
|
|
100
|
+
const sql = `SELECT
|
|
101
|
+
TABLE_NAME AS table_name,
|
|
102
|
+
COLUMN_NAME AS column_name,
|
|
103
|
+
DATA_TYPE AS data_type,
|
|
104
|
+
IS_NULLABLE AS is_nullable
|
|
105
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
106
|
+
${schema && `WHERE TABLE_SCHEMA = '${schema}'`}
|
|
107
|
+
ORDER BY TABLE_NAME, ORDINAL_POSITION;`;
|
|
107
108
|
const rep = await appDataSource.query(sql);
|
|
108
109
|
return formatToSqlTable(rep);
|
|
109
110
|
}
|
|
@@ -169,6 +170,9 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
169
170
|
if (appDataSource.options.type === "postgres") {
|
|
170
171
|
schema = appDataSource.options?.schema ?? "public";
|
|
171
172
|
}
|
|
173
|
+
else if (appDataSource.options.type === "mssql") {
|
|
174
|
+
schema = appDataSource.options?.schema;
|
|
175
|
+
}
|
|
172
176
|
else if (appDataSource.options.type === "sap") {
|
|
173
177
|
schema =
|
|
174
178
|
appDataSource.options?.schema ??
|
|
@@ -198,7 +202,10 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
198
202
|
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
199
203
|
}
|
|
200
204
|
else if (appDataSource.options.type === "mssql") {
|
|
201
|
-
|
|
205
|
+
const schema = appDataSource.options?.schema;
|
|
206
|
+
sqlSelectInfoQuery = schema
|
|
207
|
+
? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\n`
|
|
208
|
+
: `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\n`;
|
|
202
209
|
}
|
|
203
210
|
else if (appDataSource.options.type === "sap") {
|
|
204
211
|
const schema = appDataSource.options?.schema ??
|
package/dist/util/sql_utils.js
CHANGED
|
@@ -90,14 +90,15 @@ export const getTableAndColumnsName = async (appDataSource) => {
|
|
|
90
90
|
return formatToSqlTable(rep);
|
|
91
91
|
}
|
|
92
92
|
if (appDataSource.options.type === "mssql") {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
93
|
+
const schema = appDataSource.options?.schema;
|
|
94
|
+
const sql = `SELECT
|
|
95
|
+
TABLE_NAME AS table_name,
|
|
96
|
+
COLUMN_NAME AS column_name,
|
|
97
|
+
DATA_TYPE AS data_type,
|
|
98
|
+
IS_NULLABLE AS is_nullable
|
|
99
|
+
FROM INFORMATION_SCHEMA.COLUMNS
|
|
100
|
+
${schema && `WHERE TABLE_SCHEMA = '${schema}'`}
|
|
101
|
+
ORDER BY TABLE_NAME, ORDINAL_POSITION;`;
|
|
101
102
|
const rep = await appDataSource.query(sql);
|
|
102
103
|
return formatToSqlTable(rep);
|
|
103
104
|
}
|
|
@@ -162,6 +163,9 @@ export const generateTableInfoFromTables = async (tables, appDataSource, nbSampl
|
|
|
162
163
|
if (appDataSource.options.type === "postgres") {
|
|
163
164
|
schema = appDataSource.options?.schema ?? "public";
|
|
164
165
|
}
|
|
166
|
+
else if (appDataSource.options.type === "mssql") {
|
|
167
|
+
schema = appDataSource.options?.schema;
|
|
168
|
+
}
|
|
165
169
|
else if (appDataSource.options.type === "sap") {
|
|
166
170
|
schema =
|
|
167
171
|
appDataSource.options?.schema ??
|
|
@@ -191,7 +195,10 @@ export const generateTableInfoFromTables = async (tables, appDataSource, nbSampl
|
|
|
191
195
|
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
192
196
|
}
|
|
193
197
|
else if (appDataSource.options.type === "mssql") {
|
|
194
|
-
|
|
198
|
+
const schema = appDataSource.options?.schema;
|
|
199
|
+
sqlSelectInfoQuery = schema
|
|
200
|
+
? `SELECT TOP ${nbSampleRow} * FROM ${schema}.[${currentTable.tableName}];\n`
|
|
201
|
+
: `SELECT TOP ${nbSampleRow} * FROM [${currentTable.tableName}];\n`;
|
|
195
202
|
}
|
|
196
203
|
else if (appDataSource.options.type === "sap") {
|
|
197
204
|
const schema = appDataSource.options?.schema ??
|
|
@@ -17,5 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
const entrypoint_deprecation_js_1 = require("../util/entrypoint_deprecation.cjs");
|
|
18
18
|
/* #__PURE__ */ (0, entrypoint_deprecation_js_1.logVersion010MigrationWarning)({
|
|
19
19
|
oldEntrypointName: "vectorstores/pinecone",
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/pinecone",
|
|
20
22
|
});
|
|
21
23
|
__exportStar(require("@langchain/community/vectorstores/pinecone"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "vectorstores/pinecone",
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/pinecone",
|
|
4
6
|
});
|
|
5
7
|
export * from "@langchain/community/vectorstores/pinecone";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -898,8 +898,8 @@
|
|
|
898
898
|
"test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
|
|
899
899
|
"test:integration": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
|
|
900
900
|
"test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
|
|
901
|
-
"format": "prettier --write \"src\"",
|
|
902
|
-
"format:check": "prettier --check \"src\""
|
|
901
|
+
"format": "prettier --config .prettierrc --write \"src\" \"scripts\"",
|
|
902
|
+
"format:check": "prettier --config .prettierrc --check \"src\" \"scripts\""
|
|
903
903
|
},
|
|
904
904
|
"author": "LangChain",
|
|
905
905
|
"license": "MIT",
|