langchain 0.1.2 → 0.1.4
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/agents/openai_functions/index.cjs +3 -3
- package/dist/agents/openai_functions/index.js +3 -3
- package/dist/agents/openai_functions/output_parser.cjs +1 -1
- package/dist/agents/openai_functions/output_parser.d.ts +1 -1
- package/dist/agents/openai_functions/output_parser.js +1 -1
- package/dist/agents/openai_tools/index.cjs +2 -2
- package/dist/agents/openai_tools/index.js +2 -2
- package/dist/agents/openai_tools/output_parser.cjs +1 -1
- package/dist/agents/openai_tools/output_parser.d.ts +1 -1
- package/dist/agents/openai_tools/output_parser.js +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.cjs +2 -2
- package/dist/agents/toolkits/conversational_retrieval/tool.d.ts +1 -1
- package/dist/agents/toolkits/conversational_retrieval/tool.js +1 -1
- package/dist/agents/toolkits/openapi/openapi.cjs +2 -2
- package/dist/agents/toolkits/openapi/openapi.js +1 -1
- package/dist/cache/cloudflare_kv.cjs +2 -1
- package/dist/cache/cloudflare_kv.js +2 -1
- package/dist/chains/history_aware_retriever.cjs +1 -1
- package/dist/chains/history_aware_retriever.d.ts +1 -1
- package/dist/chains/history_aware_retriever.js +1 -1
- package/dist/chains/openai_functions/base.d.ts +1 -1
- package/dist/chains/openai_functions/openapi.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -0
- package/dist/chains/openai_functions/structured_output.d.ts +3 -1
- package/dist/chains/openai_functions/structured_output.js +2 -0
- package/dist/chains/sql_db/sql_db_prompt.cjs +20 -1
- package/dist/chains/sql_db/sql_db_prompt.d.ts +6 -0
- package/dist/chains/sql_db/sql_db_prompt.js +19 -0
- package/dist/chat_models/cloudflare_workersai.cjs +2 -0
- package/dist/chat_models/cloudflare_workersai.js +2 -0
- package/dist/document_transformers/openai_functions.d.ts +1 -1
- package/dist/document_transformers/openai_functions.js +1 -1
- package/dist/embeddings/cloudflare_workersai.cjs +2 -0
- package/dist/embeddings/cloudflare_workersai.js +2 -0
- package/dist/experimental/chat_models/anthropic_functions.cjs +2 -2
- package/dist/experimental/chat_models/anthropic_functions.js +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +2 -1
- package/dist/experimental/plan_and_execute/agent_executor.d.ts +1 -2
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -2
- package/dist/llms/cloudflare_workersai.cjs +2 -0
- package/dist/llms/cloudflare_workersai.js +2 -0
- package/dist/output_parsers/index.cjs +2 -1
- package/dist/output_parsers/index.d.ts +1 -1
- package/dist/output_parsers/index.js +1 -1
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_tools.cjs +86 -8
- package/dist/output_parsers/openai_tools.d.ts +31 -2
- package/dist/output_parsers/openai_tools.js +84 -7
- package/dist/output_parsers/structured.js +1 -1
- package/dist/runnables/remote.cjs +177 -73
- package/dist/runnables/remote.d.ts +2 -0
- package/dist/runnables/remote.js +178 -74
- package/dist/stores/message/cloudflare_d1.cjs +2 -0
- package/dist/stores/message/cloudflare_d1.js +2 -0
- package/dist/tools/chain.cjs +3 -2
- package/dist/tools/chain.d.ts +3 -1
- package/dist/tools/chain.js +2 -1
- package/dist/tools/convert_to_openai.cjs +3 -26
- package/dist/tools/convert_to_openai.d.ts +2 -8
- package/dist/tools/convert_to_openai.js +2 -24
- package/dist/tools/retriever.cjs +2 -2
- package/dist/tools/retriever.d.ts +1 -1
- package/dist/tools/retriever.js +1 -1
- package/dist/util/sql_utils.cjs +23 -0
- package/dist/util/sql_utils.js +24 -1
- package/dist/vectorstores/cloudflare_vectorize.cjs +2 -0
- package/dist/vectorstores/cloudflare_vectorize.js +2 -0
- package/package.json +7 -7
package/dist/runnables/remote.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Runnable, } from "@langchain/core/runnables";
|
|
2
2
|
import { Document } from "@langchain/core/documents";
|
|
3
3
|
import { ChatPromptValue, StringPromptValue, } from "@langchain/core/prompt_values";
|
|
4
|
+
import { LogStreamCallbackHandler, } from "@langchain/core/tracers/log_stream";
|
|
4
5
|
import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, } from "@langchain/core/messages";
|
|
5
|
-
import {
|
|
6
|
+
import { GenerationChunk, ChatGenerationChunk, RUN_KEY, } from "@langchain/core/outputs";
|
|
7
|
+
import { getBytes, getLines, getMessages, convertEventStreamToIterableReadableDataStream, } from "@langchain/community/utils/event_source_parse";
|
|
6
8
|
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
7
9
|
function isSuperset(set, subset) {
|
|
8
10
|
for (const elem of subset) {
|
|
@@ -17,94 +19,153 @@ function revive(obj) {
|
|
|
17
19
|
if (Array.isArray(obj))
|
|
18
20
|
return obj.map(revive);
|
|
19
21
|
if (typeof obj === "object") {
|
|
22
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
23
|
+
if (!obj || obj instanceof Date) {
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
20
26
|
const keysArr = Object.keys(obj);
|
|
21
27
|
const keys = new Set(keysArr);
|
|
22
|
-
if (isSuperset(keys, new Set(["page_content", "metadata"])))
|
|
28
|
+
if (isSuperset(keys, new Set(["page_content", "metadata"]))) {
|
|
23
29
|
return new Document({
|
|
24
30
|
pageContent: obj.page_content,
|
|
25
31
|
metadata: obj.metadata,
|
|
26
32
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
content: obj.content,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
33
|
+
}
|
|
34
|
+
if (isSuperset(keys, new Set(["content", "type", "additional_kwargs"]))) {
|
|
35
|
+
if (obj.type === "HumanMessage" || obj.type === "human") {
|
|
36
|
+
return new HumanMessage({
|
|
37
|
+
content: obj.content,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (obj.type === "SystemMessage" || obj.type === "system") {
|
|
41
|
+
return new SystemMessage({
|
|
42
|
+
content: obj.content,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (obj.type === "ChatMessage" || obj.type === "chat") {
|
|
46
|
+
return new ChatMessage({
|
|
47
|
+
content: obj.content,
|
|
48
|
+
role: obj.role,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (obj.type === "FunctionMessage" || obj.type === "function") {
|
|
52
|
+
return new FunctionMessage({
|
|
53
|
+
content: obj.content,
|
|
54
|
+
name: obj.name,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (obj.type === "ToolMessage" || obj.type === "tool") {
|
|
58
|
+
return new ToolMessage({
|
|
59
|
+
content: obj.content,
|
|
60
|
+
tool_call_id: obj.tool_call_id,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (obj.type === "AIMessage" || obj.type === "ai") {
|
|
64
|
+
return new AIMessage({
|
|
65
|
+
content: obj.content,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (obj.type === "HumanMessageChunk") {
|
|
69
|
+
return new HumanMessageChunk({
|
|
70
|
+
content: obj.content,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (obj.type === "SystemMessageChunk") {
|
|
74
|
+
return new SystemMessageChunk({
|
|
75
|
+
content: obj.content,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (obj.type === "ChatMessageChunk") {
|
|
79
|
+
return new ChatMessageChunk({
|
|
80
|
+
content: obj.content,
|
|
81
|
+
role: obj.role,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (obj.type === "FunctionMessageChunk") {
|
|
85
|
+
return new FunctionMessageChunk({
|
|
86
|
+
content: obj.content,
|
|
87
|
+
name: obj.name,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (obj.type === "ToolMessageChunk") {
|
|
91
|
+
return new ToolMessageChunk({
|
|
92
|
+
content: obj.content,
|
|
93
|
+
tool_call_id: obj.tool_call_id,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (obj.type === "AIMessageChunk") {
|
|
97
|
+
return new AIMessageChunk({
|
|
98
|
+
content: obj.content,
|
|
99
|
+
});
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
if (isSuperset(keys, new Set(["text"]))) {
|
|
100
|
-
|
|
102
|
+
if (isSuperset(keys, new Set(["text", "generation_info", "type"]))) {
|
|
103
|
+
if (obj.type === "ChatGenerationChunk") {
|
|
104
|
+
return new ChatGenerationChunk({
|
|
105
|
+
message: revive(obj.message),
|
|
106
|
+
text: obj.text,
|
|
107
|
+
generationInfo: obj.generation_info,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else if (obj.type === "ChatGeneration") {
|
|
111
|
+
return {
|
|
112
|
+
message: revive(obj.message),
|
|
113
|
+
text: obj.text,
|
|
114
|
+
generationInfo: obj.generation_info,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else if (obj.type === "GenerationChunk") {
|
|
118
|
+
return new GenerationChunk({
|
|
119
|
+
text: obj.text,
|
|
120
|
+
generationInfo: obj.generation_info,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else if (obj.type === "Generation") {
|
|
124
|
+
return {
|
|
125
|
+
text: obj.text,
|
|
126
|
+
generationInfo: obj.generation_info,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (isSuperset(keys, new Set(["tool", "tool_input", "log", "type"]))) {
|
|
131
|
+
if (obj.type === "AgentAction") {
|
|
132
|
+
return {
|
|
133
|
+
tool: obj.tool,
|
|
134
|
+
toolInput: obj.tool_input,
|
|
135
|
+
log: obj.log,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (isSuperset(keys, new Set(["return_values", "log", "type"]))) {
|
|
140
|
+
if (obj.type === "AgentFinish") {
|
|
141
|
+
return {
|
|
142
|
+
returnValues: obj.return_values,
|
|
143
|
+
log: obj.log,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (isSuperset(keys, new Set(["generations", "run", "type"]))) {
|
|
148
|
+
if (obj.type === "LLMResult") {
|
|
149
|
+
return {
|
|
150
|
+
generations: revive(obj.generations),
|
|
151
|
+
llmOutput: obj.llm_output,
|
|
152
|
+
[RUN_KEY]: obj.run,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
101
155
|
}
|
|
102
156
|
if (isSuperset(keys, new Set(["messages"]))) {
|
|
157
|
+
// TODO: Start checking for type: ChatPromptValue and ChatPromptValueConcrete
|
|
158
|
+
// when LangServe bug is fixed
|
|
103
159
|
return new ChatPromptValue({
|
|
104
160
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
161
|
messages: obj.messages.map((msg) => revive(msg)),
|
|
106
162
|
});
|
|
107
163
|
}
|
|
164
|
+
if (isSuperset(keys, new Set(["text"]))) {
|
|
165
|
+
// TODO: Start checking for type: StringPromptValue
|
|
166
|
+
// when LangServe bug is fixed
|
|
167
|
+
return new StringPromptValue(obj.text);
|
|
168
|
+
}
|
|
108
169
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
170
|
const innerRevive = (key) => [
|
|
110
171
|
key,
|
|
@@ -229,4 +290,47 @@ export class RemoteRunnable extends Runnable {
|
|
|
229
290
|
});
|
|
230
291
|
return IterableReadableStream.fromReadableStream(stream);
|
|
231
292
|
}
|
|
293
|
+
async *streamLog(input, options, streamOptions) {
|
|
294
|
+
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
295
|
+
const stream = new LogStreamCallbackHandler({
|
|
296
|
+
...streamOptions,
|
|
297
|
+
autoClose: false,
|
|
298
|
+
});
|
|
299
|
+
const { callbacks } = config;
|
|
300
|
+
if (callbacks === undefined) {
|
|
301
|
+
config.callbacks = [stream];
|
|
302
|
+
}
|
|
303
|
+
else if (Array.isArray(callbacks)) {
|
|
304
|
+
config.callbacks = callbacks.concat([stream]);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
const copiedCallbacks = callbacks.copy();
|
|
308
|
+
copiedCallbacks.inheritableHandlers.push(stream);
|
|
309
|
+
config.callbacks = copiedCallbacks;
|
|
310
|
+
}
|
|
311
|
+
// The type is in camelCase but the API only accepts snake_case.
|
|
312
|
+
const camelCaseStreamOptions = {
|
|
313
|
+
include_names: streamOptions?.includeNames,
|
|
314
|
+
include_types: streamOptions?.includeTypes,
|
|
315
|
+
include_tags: streamOptions?.includeTags,
|
|
316
|
+
exclude_names: streamOptions?.excludeNames,
|
|
317
|
+
exclude_types: streamOptions?.excludeTypes,
|
|
318
|
+
exclude_tags: streamOptions?.excludeTags,
|
|
319
|
+
};
|
|
320
|
+
const response = await this.post("/stream_log", {
|
|
321
|
+
input,
|
|
322
|
+
config,
|
|
323
|
+
kwargs,
|
|
324
|
+
...camelCaseStreamOptions,
|
|
325
|
+
diff: false,
|
|
326
|
+
});
|
|
327
|
+
const { body } = response;
|
|
328
|
+
if (!body) {
|
|
329
|
+
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
330
|
+
}
|
|
331
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
332
|
+
for await (const log of runnableStream) {
|
|
333
|
+
yield revive(JSON.parse(log));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
232
336
|
}
|
|
@@ -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: "stores/message/cloudflare_d1",
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/cloudflare",
|
|
20
22
|
});
|
|
21
23
|
__exportStar(require("@langchain/community/stores/message/cloudflare_d1"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "stores/message/cloudflare_d1",
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/cloudflare",
|
|
4
6
|
});
|
|
5
7
|
export * from "@langchain/community/stores/message/cloudflare_d1";
|
package/dist/tools/chain.cjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ChainTool = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tools_1 = require("@langchain/core/tools");
|
|
5
5
|
/**
|
|
6
|
+
* @deprecated Wrap in a DynamicTool instead.
|
|
6
7
|
* Class that extends DynamicTool for creating tools that can run chains.
|
|
7
8
|
* Takes an instance of a class that extends BaseChain as a parameter in
|
|
8
9
|
* its constructor and uses it to run the chain when its 'func' method is
|
|
9
10
|
* called.
|
|
10
11
|
*/
|
|
11
|
-
class ChainTool extends
|
|
12
|
+
class ChainTool extends tools_1.DynamicTool {
|
|
12
13
|
static lc_name() {
|
|
13
14
|
return "ChainTool";
|
|
14
15
|
}
|
package/dist/tools/chain.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DynamicTool, DynamicToolInput } from "@langchain/
|
|
1
|
+
import { DynamicTool, DynamicToolInput } from "@langchain/core/tools";
|
|
2
2
|
import { BaseChain } from "../chains/base.js";
|
|
3
3
|
/**
|
|
4
|
+
* @deprecated Wrap in a DynamicTool instead.
|
|
4
5
|
* Interface for the input parameters of the ChainTool constructor.
|
|
5
6
|
* Extends the DynamicToolInput interface, replacing the 'func' property
|
|
6
7
|
* with a 'chain' property.
|
|
@@ -9,6 +10,7 @@ export interface ChainToolInput extends Omit<DynamicToolInput, "func"> {
|
|
|
9
10
|
chain: BaseChain;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
13
|
+
* @deprecated Wrap in a DynamicTool instead.
|
|
12
14
|
* Class that extends DynamicTool for creating tools that can run chains.
|
|
13
15
|
* Takes an instance of a class that extends BaseChain as a parameter in
|
|
14
16
|
* its constructor and uses it to run the chain when its 'func' method is
|
package/dist/tools/chain.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DynamicTool
|
|
1
|
+
import { DynamicTool } from "@langchain/core/tools";
|
|
2
2
|
/**
|
|
3
|
+
* @deprecated Wrap in a DynamicTool instead.
|
|
3
4
|
* Class that extends DynamicTool for creating tools that can run chains.
|
|
4
5
|
* Takes an instance of a class that extends BaseChain as a parameter in
|
|
5
6
|
* its constructor and uses it to run the chain when its 'func' method is
|
|
@@ -2,32 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatToOpenAIAssistantTool = exports.formatToOpenAITool = exports.formatToOpenAIFunction = void 0;
|
|
4
4
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* function to convert the schema of the `StructuredTool` into a JSON
|
|
9
|
-
* schema, which is then used as the parameters for the OpenAI function.
|
|
10
|
-
*/
|
|
11
|
-
function formatToOpenAIFunction(tool) {
|
|
12
|
-
return {
|
|
13
|
-
name: tool.name,
|
|
14
|
-
description: tool.description,
|
|
15
|
-
parameters: (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
exports.formatToOpenAIFunction = formatToOpenAIFunction;
|
|
19
|
-
function formatToOpenAITool(tool) {
|
|
20
|
-
const schema = (0, zod_to_json_schema_1.zodToJsonSchema)(tool.schema);
|
|
21
|
-
return {
|
|
22
|
-
type: "function",
|
|
23
|
-
function: {
|
|
24
|
-
name: tool.name,
|
|
25
|
-
description: tool.description,
|
|
26
|
-
parameters: schema,
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
exports.formatToOpenAITool = formatToOpenAITool;
|
|
5
|
+
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
|
+
Object.defineProperty(exports, "formatToOpenAIFunction", { enumerable: true, get: function () { return function_calling_1.convertToOpenAIFunction; } });
|
|
7
|
+
Object.defineProperty(exports, "formatToOpenAITool", { enumerable: true, get: function () { return function_calling_1.convertToOpenAITool; } });
|
|
31
8
|
function formatToOpenAIAssistantTool(tool) {
|
|
32
9
|
return {
|
|
33
10
|
type: "function",
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import type { OpenAIClient } from "@langchain/openai";
|
|
2
2
|
import type { StructuredToolInterface } from "@langchain/core/tools";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
|
|
6
|
-
* function to convert the schema of the `StructuredTool` into a JSON
|
|
7
|
-
* schema, which is then used as the parameters for the OpenAI function.
|
|
8
|
-
*/
|
|
9
|
-
export declare function formatToOpenAIFunction(tool: StructuredToolInterface): OpenAIClient.Chat.ChatCompletionCreateParams.Function;
|
|
10
|
-
export declare function formatToOpenAITool(tool: StructuredToolInterface): OpenAIClient.Chat.ChatCompletionTool;
|
|
3
|
+
import { convertToOpenAIFunction, convertToOpenAITool } from "@langchain/core/utils/function_calling";
|
|
4
|
+
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
11
5
|
export declare function formatToOpenAIAssistantTool(tool: StructuredToolInterface): OpenAIClient.Beta.AssistantCreateParams.AssistantToolsFunction;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`
|
|
5
|
-
* function to convert the schema of the `StructuredTool` into a JSON
|
|
6
|
-
* schema, which is then used as the parameters for the OpenAI function.
|
|
7
|
-
*/
|
|
8
|
-
export function formatToOpenAIFunction(tool) {
|
|
9
|
-
return {
|
|
10
|
-
name: tool.name,
|
|
11
|
-
description: tool.description,
|
|
12
|
-
parameters: zodToJsonSchema(tool.schema),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function formatToOpenAITool(tool) {
|
|
16
|
-
const schema = zodToJsonSchema(tool.schema);
|
|
17
|
-
return {
|
|
18
|
-
type: "function",
|
|
19
|
-
function: {
|
|
20
|
-
name: tool.name,
|
|
21
|
-
description: tool.description,
|
|
22
|
-
parameters: schema,
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
2
|
+
import { convertToOpenAIFunction, convertToOpenAITool, } from "@langchain/core/utils/function_calling";
|
|
3
|
+
export { convertToOpenAIFunction as formatToOpenAIFunction, convertToOpenAITool as formatToOpenAITool, };
|
|
26
4
|
export function formatToOpenAIAssistantTool(tool) {
|
|
27
5
|
return {
|
|
28
6
|
type: "function",
|
package/dist/tools/retriever.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createRetrieverTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const tools_1 = require("@langchain/core/tools");
|
|
6
6
|
const document_js_1 = require("../util/document.cjs");
|
|
7
7
|
function createRetrieverTool(retriever, input) {
|
|
8
8
|
const func = async ({ query }, runManager) => {
|
|
@@ -12,6 +12,6 @@ function createRetrieverTool(retriever, input) {
|
|
|
12
12
|
const schema = zod_1.z.object({
|
|
13
13
|
query: zod_1.z.string().describe("query to look up in retriever"),
|
|
14
14
|
});
|
|
15
|
-
return new
|
|
15
|
+
return new tools_1.DynamicStructuredTool({ ...input, func, schema });
|
|
16
16
|
}
|
|
17
17
|
exports.createRetrieverTool = createRetrieverTool;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BaseRetrieverInterface } from "@langchain/core/retrievers";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { DynamicStructuredTool, type DynamicStructuredToolInput } from "@langchain/
|
|
3
|
+
import { DynamicStructuredTool, type DynamicStructuredToolInput } from "@langchain/core/tools";
|
|
4
4
|
export declare function createRetrieverTool(retriever: BaseRetrieverInterface, input: Omit<DynamicStructuredToolInput, "func" | "schema">): DynamicStructuredTool<z.ZodObject<{
|
|
5
5
|
query: z.ZodString;
|
|
6
6
|
}, "strip", z.ZodTypeAny, {
|
package/dist/tools/retriever.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { DynamicStructuredTool, } from "@langchain/
|
|
2
|
+
import { DynamicStructuredTool, } from "@langchain/core/tools";
|
|
3
3
|
import { formatDocumentsAsString } from "../util/document.js";
|
|
4
4
|
export function createRetrieverTool(retriever, input) {
|
|
5
5
|
const func = async ({ query }, runManager) => {
|
package/dist/util/sql_utils.cjs
CHANGED
|
@@ -126,6 +126,20 @@ const getTableAndColumnsName = async (appDataSource) => {
|
|
|
126
126
|
}));
|
|
127
127
|
return formatToSqlTable(repLowerCase);
|
|
128
128
|
}
|
|
129
|
+
if (appDataSource.options.type === "oracle") {
|
|
130
|
+
const schemaName = appDataSource.options.schema;
|
|
131
|
+
const sql = `
|
|
132
|
+
SELECT
|
|
133
|
+
TABLE_NAME AS "table_name",
|
|
134
|
+
COLUMN_NAME AS "column_name",
|
|
135
|
+
DATA_TYPE AS "data_type",
|
|
136
|
+
NULLABLE AS "is_nullable"
|
|
137
|
+
FROM ALL_TAB_COLS
|
|
138
|
+
WHERE
|
|
139
|
+
OWNER = UPPER('${schemaName}')`;
|
|
140
|
+
const rep = await appDataSource.query(sql);
|
|
141
|
+
return formatToSqlTable(rep);
|
|
142
|
+
}
|
|
129
143
|
throw new Error("Database type not implemented yet");
|
|
130
144
|
};
|
|
131
145
|
exports.getTableAndColumnsName = getTableAndColumnsName;
|
|
@@ -161,6 +175,9 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
161
175
|
appDataSource.options?.username ??
|
|
162
176
|
"public";
|
|
163
177
|
}
|
|
178
|
+
else if (appDataSource.options.type === "oracle") {
|
|
179
|
+
schema = appDataSource.options.schema;
|
|
180
|
+
}
|
|
164
181
|
let sqlCreateTableQuery = schema
|
|
165
182
|
? `CREATE TABLE "${schema}"."${currentTable.tableName}" (\n`
|
|
166
183
|
: `CREATE TABLE ${currentTable.tableName} (\n`;
|
|
@@ -189,6 +206,9 @@ const generateTableInfoFromTables = async (tables, appDataSource, nbSampleRow, c
|
|
|
189
206
|
"public";
|
|
190
207
|
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
191
208
|
}
|
|
209
|
+
else if (appDataSource.options.type === "oracle") {
|
|
210
|
+
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" WHERE ROWNUM <= '${nbSampleRow}'`;
|
|
211
|
+
}
|
|
192
212
|
else {
|
|
193
213
|
sqlSelectInfoQuery = `SELECT * FROM "${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
194
214
|
}
|
|
@@ -229,6 +249,9 @@ const getPromptTemplateFromDataSource = (appDataSource) => {
|
|
|
229
249
|
if (appDataSource.options.type === "sap") {
|
|
230
250
|
return sql_db_prompt_js_1.SQL_SAP_HANA_PROMPT;
|
|
231
251
|
}
|
|
252
|
+
if (appDataSource.options.type === "oracle") {
|
|
253
|
+
return sql_db_prompt_js_1.SQL_ORACLE_PROMPT;
|
|
254
|
+
}
|
|
232
255
|
return sql_db_prompt_js_1.DEFAULT_SQL_DATABASE_PROMPT;
|
|
233
256
|
};
|
|
234
257
|
exports.getPromptTemplateFromDataSource = getPromptTemplateFromDataSource;
|
package/dist/util/sql_utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEFAULT_SQL_DATABASE_PROMPT, SQL_SAP_HANA_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, } from "../chains/sql_db/sql_db_prompt.js";
|
|
1
|
+
import { DEFAULT_SQL_DATABASE_PROMPT, SQL_SAP_HANA_PROMPT, SQL_MSSQL_PROMPT, SQL_MYSQL_PROMPT, SQL_POSTGRES_PROMPT, SQL_SQLITE_PROMPT, SQL_ORACLE_PROMPT, } from "../chains/sql_db/sql_db_prompt.js";
|
|
2
2
|
export const verifyListTablesExistInDatabase = (tablesFromDatabase, listTables, errorPrefixMsg) => {
|
|
3
3
|
const onlyTableNames = tablesFromDatabase.map((table) => table.tableName);
|
|
4
4
|
if (listTables.length > 0) {
|
|
@@ -120,6 +120,20 @@ export const getTableAndColumnsName = async (appDataSource) => {
|
|
|
120
120
|
}));
|
|
121
121
|
return formatToSqlTable(repLowerCase);
|
|
122
122
|
}
|
|
123
|
+
if (appDataSource.options.type === "oracle") {
|
|
124
|
+
const schemaName = appDataSource.options.schema;
|
|
125
|
+
const sql = `
|
|
126
|
+
SELECT
|
|
127
|
+
TABLE_NAME AS "table_name",
|
|
128
|
+
COLUMN_NAME AS "column_name",
|
|
129
|
+
DATA_TYPE AS "data_type",
|
|
130
|
+
NULLABLE AS "is_nullable"
|
|
131
|
+
FROM ALL_TAB_COLS
|
|
132
|
+
WHERE
|
|
133
|
+
OWNER = UPPER('${schemaName}')`;
|
|
134
|
+
const rep = await appDataSource.query(sql);
|
|
135
|
+
return formatToSqlTable(rep);
|
|
136
|
+
}
|
|
123
137
|
throw new Error("Database type not implemented yet");
|
|
124
138
|
};
|
|
125
139
|
const formatSqlResponseToSimpleTableString = (rawResult) => {
|
|
@@ -154,6 +168,9 @@ export const generateTableInfoFromTables = async (tables, appDataSource, nbSampl
|
|
|
154
168
|
appDataSource.options?.username ??
|
|
155
169
|
"public";
|
|
156
170
|
}
|
|
171
|
+
else if (appDataSource.options.type === "oracle") {
|
|
172
|
+
schema = appDataSource.options.schema;
|
|
173
|
+
}
|
|
157
174
|
let sqlCreateTableQuery = schema
|
|
158
175
|
? `CREATE TABLE "${schema}"."${currentTable.tableName}" (\n`
|
|
159
176
|
: `CREATE TABLE ${currentTable.tableName} (\n`;
|
|
@@ -182,6 +199,9 @@ export const generateTableInfoFromTables = async (tables, appDataSource, nbSampl
|
|
|
182
199
|
"public";
|
|
183
200
|
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
184
201
|
}
|
|
202
|
+
else if (appDataSource.options.type === "oracle") {
|
|
203
|
+
sqlSelectInfoQuery = `SELECT * FROM "${schema}"."${currentTable.tableName}" WHERE ROWNUM <= '${nbSampleRow}'`;
|
|
204
|
+
}
|
|
185
205
|
else {
|
|
186
206
|
sqlSelectInfoQuery = `SELECT * FROM "${currentTable.tableName}" LIMIT ${nbSampleRow};\n`;
|
|
187
207
|
}
|
|
@@ -221,5 +241,8 @@ export const getPromptTemplateFromDataSource = (appDataSource) => {
|
|
|
221
241
|
if (appDataSource.options.type === "sap") {
|
|
222
242
|
return SQL_SAP_HANA_PROMPT;
|
|
223
243
|
}
|
|
244
|
+
if (appDataSource.options.type === "oracle") {
|
|
245
|
+
return SQL_ORACLE_PROMPT;
|
|
246
|
+
}
|
|
224
247
|
return DEFAULT_SQL_DATABASE_PROMPT;
|
|
225
248
|
};
|
|
@@ -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/cloudflare_vectorize",
|
|
20
|
+
newEntrypointName: "",
|
|
21
|
+
newPackageName: "@langchain/cloudflare",
|
|
20
22
|
});
|
|
21
23
|
__exportStar(require("@langchain/community/vectorstores/cloudflare_vectorize"), exports);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { logVersion010MigrationWarning } from "../util/entrypoint_deprecation.js";
|
|
2
2
|
/* #__PURE__ */ logVersion010MigrationWarning({
|
|
3
3
|
oldEntrypointName: "vectorstores/cloudflare_vectorize",
|
|
4
|
+
newEntrypointName: "",
|
|
5
|
+
newPackageName: "@langchain/cloudflare",
|
|
4
6
|
});
|
|
5
7
|
export * from "@langchain/community/vectorstores/cloudflare_vectorize";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -886,7 +886,7 @@
|
|
|
886
886
|
"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",
|
|
887
887
|
"build:watch": "node scripts/create-entrypoints.js && tsc --outDir dist/ --watch",
|
|
888
888
|
"build:scripts": "node scripts/create-entrypoints.js && node scripts/check-tree-shaking.js",
|
|
889
|
-
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint src",
|
|
889
|
+
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
890
890
|
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
891
891
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
892
892
|
"lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
|
|
@@ -1202,9 +1202,9 @@
|
|
|
1202
1202
|
},
|
|
1203
1203
|
"dependencies": {
|
|
1204
1204
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1205
|
-
"@langchain/community": "~0.0.
|
|
1206
|
-
"@langchain/core": "~0.1.
|
|
1207
|
-
"@langchain/openai": "~0.0.
|
|
1205
|
+
"@langchain/community": "~0.0.17",
|
|
1206
|
+
"@langchain/core": "~0.1.16",
|
|
1207
|
+
"@langchain/openai": "~0.0.12",
|
|
1208
1208
|
"binary-extensions": "^2.2.0",
|
|
1209
1209
|
"expr-eval": "^2.0.2",
|
|
1210
1210
|
"js-tiktoken": "^1.0.7",
|
|
@@ -1217,8 +1217,8 @@
|
|
|
1217
1217
|
"p-retry": "4",
|
|
1218
1218
|
"uuid": "^9.0.0",
|
|
1219
1219
|
"yaml": "^2.2.1",
|
|
1220
|
-
"zod": "^3.22.
|
|
1221
|
-
"zod-to-json-schema": "3.
|
|
1220
|
+
"zod": "^3.22.4",
|
|
1221
|
+
"zod-to-json-schema": "^3.22.3"
|
|
1222
1222
|
},
|
|
1223
1223
|
"publishConfig": {
|
|
1224
1224
|
"access": "public"
|