langchain 0.1.12 → 0.1.14
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/cache/redis.cjs +1 -1
- package/dist/cache/redis.d.ts +1 -1
- package/dist/cache/redis.js +1 -1
- package/dist/document_loaders/web/confluence.cjs +7 -1
- package/dist/document_loaders/web/confluence.d.ts +9 -0
- package/dist/document_loaders/web/confluence.js +7 -1
- package/dist/embeddings/fake.cjs +21 -92
- package/dist/embeddings/fake.d.ts +1 -53
- package/dist/embeddings/fake.js +7 -89
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +35 -14
- package/dist/load/import_map.d.ts +22 -1
- package/dist/load/import_map.js +37 -16
- package/dist/runnables/remote.cjs +15 -339
- package/dist/runnables/remote.d.ts +1 -30
- package/dist/runnables/remote.js +1 -337
- package/dist/stores/message/redis.cjs +2 -0
- package/dist/stores/message/redis.js +2 -0
- package/dist/util/migrations/0_0-0_1-migrate-imports.cjs +208 -0
- package/dist/util/migrations/0_0-0_1-migrate-imports.d.ts +44 -0
- package/dist/util/migrations/0_0-0_1-migrate-imports.js +201 -0
- package/dist/vectorstores/redis.cjs +2 -0
- package/dist/vectorstores/redis.js +2 -0
- package/dist/vectorstores/weaviate.cjs +2 -0
- package/dist/vectorstores/weaviate.js +2 -0
- package/package.json +26 -7
- package/util/migrations/0_1.cjs +1 -0
- package/util/migrations/0_1.d.cts +1 -0
- package/util/migrations/0_1.d.ts +1 -0
- package/util/migrations/0_1.js +1 -0
package/dist/load/import_map.js
CHANGED
|
@@ -67,28 +67,28 @@ export * as smith from "../smith/index.js";
|
|
|
67
67
|
export * as runnables__remote from "../runnables/remote.js";
|
|
68
68
|
export * as indexes from "../indexes/index.js";
|
|
69
69
|
import { ChatOpenAI, OpenAI, OpenAIEmbeddings } from "@langchain/openai";
|
|
70
|
-
import { PromptTemplate, AIMessagePromptTemplate, ChatMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate,
|
|
71
|
-
import { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk
|
|
70
|
+
import { PromptTemplate, AIMessagePromptTemplate, ChatMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, ImagePromptTemplate, PipelinePromptTemplate } from "@langchain/core/prompts";
|
|
71
|
+
import { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk } from "@langchain/core/messages";
|
|
72
72
|
import { StringPromptValue } from "@langchain/core/prompt_values";
|
|
73
|
-
import { RouterRunnable, RunnableAssign, RunnableBinding, RunnableBranch, RunnableEach, RunnableMap, RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence, RunnableWithFallbacks, RunnableWithMessageHistory
|
|
73
|
+
import { RouterRunnable, RunnableAssign, RunnableBinding, RunnableBranch, RunnableEach, RunnableMap, RunnableParallel, RunnablePassthrough, RunnablePick, RunnableRetry, RunnableSequence, RunnableWithFallbacks, RunnableWithMessageHistory } from "@langchain/core/runnables";
|
|
74
74
|
import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
75
75
|
import { ChatGenerationChunk, GenerationChunk } from "@langchain/core/outputs";
|
|
76
76
|
import { ChatFireworks } from "@langchain/community/chat_models/fireworks";
|
|
77
77
|
import { Fireworks } from "@langchain/community/llms/fireworks";
|
|
78
78
|
const chat_models__openai = {
|
|
79
|
-
ChatOpenAI
|
|
79
|
+
ChatOpenAI
|
|
80
80
|
};
|
|
81
81
|
export { chat_models__openai };
|
|
82
82
|
const llms__openai = {
|
|
83
|
-
OpenAI
|
|
83
|
+
OpenAI
|
|
84
84
|
};
|
|
85
85
|
export { llms__openai };
|
|
86
86
|
const embeddings__openai = {
|
|
87
|
-
OpenAIEmbeddings
|
|
87
|
+
OpenAIEmbeddings
|
|
88
88
|
};
|
|
89
89
|
export { embeddings__openai };
|
|
90
90
|
const prompts__prompt = {
|
|
91
|
-
PromptTemplate
|
|
91
|
+
PromptTemplate
|
|
92
92
|
};
|
|
93
93
|
export { prompts__prompt };
|
|
94
94
|
const schema__messages = {
|
|
@@ -105,24 +105,45 @@ const schema__messages = {
|
|
|
105
105
|
SystemMessage,
|
|
106
106
|
SystemMessageChunk,
|
|
107
107
|
ToolMessage,
|
|
108
|
-
ToolMessageChunk
|
|
108
|
+
ToolMessageChunk
|
|
109
109
|
};
|
|
110
110
|
export { schema__messages };
|
|
111
|
+
const schema = {
|
|
112
|
+
AIMessage,
|
|
113
|
+
AIMessageChunk,
|
|
114
|
+
BaseMessage,
|
|
115
|
+
BaseMessageChunk,
|
|
116
|
+
ChatMessage,
|
|
117
|
+
ChatMessageChunk,
|
|
118
|
+
FunctionMessage,
|
|
119
|
+
FunctionMessageChunk,
|
|
120
|
+
HumanMessage,
|
|
121
|
+
HumanMessageChunk,
|
|
122
|
+
SystemMessage,
|
|
123
|
+
SystemMessageChunk,
|
|
124
|
+
ToolMessage,
|
|
125
|
+
ToolMessageChunk
|
|
126
|
+
};
|
|
127
|
+
export { schema };
|
|
111
128
|
const prompts__chat = {
|
|
112
129
|
AIMessagePromptTemplate,
|
|
113
130
|
ChatMessagePromptTemplate,
|
|
114
131
|
ChatPromptTemplate,
|
|
115
132
|
HumanMessagePromptTemplate,
|
|
116
133
|
MessagesPlaceholder,
|
|
117
|
-
SystemMessagePromptTemplate
|
|
134
|
+
SystemMessagePromptTemplate
|
|
118
135
|
};
|
|
119
136
|
export { prompts__chat };
|
|
137
|
+
const prompts__image = {
|
|
138
|
+
ImagePromptTemplate
|
|
139
|
+
};
|
|
140
|
+
export { prompts__image };
|
|
120
141
|
const prompts__pipeline = {
|
|
121
|
-
PipelinePromptTemplate
|
|
142
|
+
PipelinePromptTemplate
|
|
122
143
|
};
|
|
123
144
|
export { prompts__pipeline };
|
|
124
145
|
const prompts__base = {
|
|
125
|
-
StringPromptValue
|
|
146
|
+
StringPromptValue
|
|
126
147
|
};
|
|
127
148
|
export { prompts__base };
|
|
128
149
|
const schema__runnable = {
|
|
@@ -138,23 +159,23 @@ const schema__runnable = {
|
|
|
138
159
|
RunnableRetry,
|
|
139
160
|
RunnableSequence,
|
|
140
161
|
RunnableWithFallbacks,
|
|
141
|
-
RunnableWithMessageHistory
|
|
162
|
+
RunnableWithMessageHistory
|
|
142
163
|
};
|
|
143
164
|
export { schema__runnable };
|
|
144
165
|
const schema__output_parser = {
|
|
145
|
-
StringOutputParser
|
|
166
|
+
StringOutputParser
|
|
146
167
|
};
|
|
147
168
|
export { schema__output_parser };
|
|
148
169
|
const schema__output = {
|
|
149
170
|
ChatGenerationChunk,
|
|
150
|
-
GenerationChunk
|
|
171
|
+
GenerationChunk
|
|
151
172
|
};
|
|
152
173
|
export { schema__output };
|
|
153
174
|
const chat_models__fireworks = {
|
|
154
|
-
ChatFireworks
|
|
175
|
+
ChatFireworks
|
|
155
176
|
};
|
|
156
177
|
export { chat_models__fireworks };
|
|
157
178
|
const llms__fireworks = {
|
|
158
|
-
Fireworks
|
|
179
|
+
Fireworks
|
|
159
180
|
};
|
|
160
181
|
export { llms__fireworks };
|
|
@@ -1,341 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
const runnables_1 = require("@langchain/core/runnables");
|
|
5
|
-
const documents_1 = require("@langchain/core/documents");
|
|
6
|
-
const prompt_values_1 = require("@langchain/core/prompt_values");
|
|
7
|
-
const log_stream_1 = require("@langchain/core/tracers/log_stream");
|
|
8
|
-
const messages_1 = require("@langchain/core/messages");
|
|
9
|
-
const outputs_1 = require("@langchain/core/outputs");
|
|
10
|
-
const event_source_parse_1 = require("@langchain/community/utils/event_source_parse");
|
|
11
|
-
const stream_1 = require("@langchain/core/utils/stream");
|
|
12
|
-
function isSuperset(set, subset) {
|
|
13
|
-
for (const elem of subset) {
|
|
14
|
-
if (!set.has(elem)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
|
-
function revive(obj) {
|
|
22
|
-
if (Array.isArray(obj))
|
|
23
|
-
return obj.map(revive);
|
|
24
|
-
if (typeof obj === "object") {
|
|
25
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
26
|
-
if (!obj || obj instanceof Date) {
|
|
27
|
-
return obj;
|
|
28
|
-
}
|
|
29
|
-
const keysArr = Object.keys(obj);
|
|
30
|
-
const keys = new Set(keysArr);
|
|
31
|
-
if (isSuperset(keys, new Set(["page_content", "metadata"]))) {
|
|
32
|
-
return new documents_1.Document({
|
|
33
|
-
pageContent: obj.page_content,
|
|
34
|
-
metadata: obj.metadata,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
if (isSuperset(keys, new Set(["content", "type", "additional_kwargs"]))) {
|
|
38
|
-
if (obj.type === "HumanMessage" || obj.type === "human") {
|
|
39
|
-
return new messages_1.HumanMessage({
|
|
40
|
-
content: obj.content,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (obj.type === "SystemMessage" || obj.type === "system") {
|
|
44
|
-
return new messages_1.SystemMessage({
|
|
45
|
-
content: obj.content,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if (obj.type === "ChatMessage" || obj.type === "chat") {
|
|
49
|
-
return new messages_1.ChatMessage({
|
|
50
|
-
content: obj.content,
|
|
51
|
-
role: obj.role,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (obj.type === "FunctionMessage" || obj.type === "function") {
|
|
55
|
-
return new messages_1.FunctionMessage({
|
|
56
|
-
content: obj.content,
|
|
57
|
-
name: obj.name,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (obj.type === "ToolMessage" || obj.type === "tool") {
|
|
61
|
-
return new messages_1.ToolMessage({
|
|
62
|
-
content: obj.content,
|
|
63
|
-
tool_call_id: obj.tool_call_id,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
if (obj.type === "AIMessage" || obj.type === "ai") {
|
|
67
|
-
return new messages_1.AIMessage({
|
|
68
|
-
content: obj.content,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
if (obj.type === "HumanMessageChunk") {
|
|
72
|
-
return new messages_1.HumanMessageChunk({
|
|
73
|
-
content: obj.content,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (obj.type === "SystemMessageChunk") {
|
|
77
|
-
return new messages_1.SystemMessageChunk({
|
|
78
|
-
content: obj.content,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (obj.type === "ChatMessageChunk") {
|
|
82
|
-
return new messages_1.ChatMessageChunk({
|
|
83
|
-
content: obj.content,
|
|
84
|
-
role: obj.role,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (obj.type === "FunctionMessageChunk") {
|
|
88
|
-
return new messages_1.FunctionMessageChunk({
|
|
89
|
-
content: obj.content,
|
|
90
|
-
name: obj.name,
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
if (obj.type === "ToolMessageChunk") {
|
|
94
|
-
return new messages_1.ToolMessageChunk({
|
|
95
|
-
content: obj.content,
|
|
96
|
-
tool_call_id: obj.tool_call_id,
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (obj.type === "AIMessageChunk") {
|
|
100
|
-
return new messages_1.AIMessageChunk({
|
|
101
|
-
content: obj.content,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (isSuperset(keys, new Set(["text", "generation_info", "type"]))) {
|
|
106
|
-
if (obj.type === "ChatGenerationChunk") {
|
|
107
|
-
return new outputs_1.ChatGenerationChunk({
|
|
108
|
-
message: revive(obj.message),
|
|
109
|
-
text: obj.text,
|
|
110
|
-
generationInfo: obj.generation_info,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
else if (obj.type === "ChatGeneration") {
|
|
114
|
-
return {
|
|
115
|
-
message: revive(obj.message),
|
|
116
|
-
text: obj.text,
|
|
117
|
-
generationInfo: obj.generation_info,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
else if (obj.type === "GenerationChunk") {
|
|
121
|
-
return new outputs_1.GenerationChunk({
|
|
122
|
-
text: obj.text,
|
|
123
|
-
generationInfo: obj.generation_info,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
else if (obj.type === "Generation") {
|
|
127
|
-
return {
|
|
128
|
-
text: obj.text,
|
|
129
|
-
generationInfo: obj.generation_info,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (isSuperset(keys, new Set(["tool", "tool_input", "log", "type"]))) {
|
|
134
|
-
if (obj.type === "AgentAction") {
|
|
135
|
-
return {
|
|
136
|
-
tool: obj.tool,
|
|
137
|
-
toolInput: obj.tool_input,
|
|
138
|
-
log: obj.log,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (isSuperset(keys, new Set(["return_values", "log", "type"]))) {
|
|
143
|
-
if (obj.type === "AgentFinish") {
|
|
144
|
-
return {
|
|
145
|
-
returnValues: obj.return_values,
|
|
146
|
-
log: obj.log,
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (isSuperset(keys, new Set(["generations", "run", "type"]))) {
|
|
151
|
-
if (obj.type === "LLMResult") {
|
|
152
|
-
return {
|
|
153
|
-
generations: revive(obj.generations),
|
|
154
|
-
llmOutput: obj.llm_output,
|
|
155
|
-
[outputs_1.RUN_KEY]: obj.run,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (isSuperset(keys, new Set(["messages"]))) {
|
|
160
|
-
// TODO: Start checking for type: ChatPromptValue and ChatPromptValueConcrete
|
|
161
|
-
// when LangServe bug is fixed
|
|
162
|
-
return new prompt_values_1.ChatPromptValue({
|
|
163
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
164
|
-
messages: obj.messages.map((msg) => revive(msg)),
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
if (isSuperset(keys, new Set(["text"]))) {
|
|
168
|
-
// TODO: Start checking for type: StringPromptValue
|
|
169
|
-
// when LangServe bug is fixed
|
|
170
|
-
return new prompt_values_1.StringPromptValue(obj.text);
|
|
171
|
-
}
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
|
-
const innerRevive = (key) => [
|
|
174
|
-
key,
|
|
175
|
-
revive(obj[key]),
|
|
176
|
-
];
|
|
177
|
-
const rtn = Object.fromEntries(keysArr.map(innerRevive));
|
|
178
|
-
return rtn;
|
|
179
|
-
}
|
|
180
|
-
return obj;
|
|
181
|
-
}
|
|
182
|
-
function deserialize(str) {
|
|
183
|
-
const obj = JSON.parse(str);
|
|
184
|
-
return revive(obj);
|
|
185
|
-
}
|
|
186
|
-
function removeCallbacks(options) {
|
|
187
|
-
const rest = { ...options };
|
|
188
|
-
delete rest.callbacks;
|
|
189
|
-
return rest;
|
|
190
|
-
}
|
|
191
|
-
class RemoteRunnable extends runnables_1.Runnable {
|
|
192
|
-
constructor(fields) {
|
|
193
|
-
super(fields);
|
|
194
|
-
Object.defineProperty(this, "url", {
|
|
195
|
-
enumerable: true,
|
|
196
|
-
configurable: true,
|
|
197
|
-
writable: true,
|
|
198
|
-
value: void 0
|
|
199
|
-
});
|
|
200
|
-
Object.defineProperty(this, "options", {
|
|
201
|
-
enumerable: true,
|
|
202
|
-
configurable: true,
|
|
203
|
-
writable: true,
|
|
204
|
-
value: void 0
|
|
205
|
-
});
|
|
206
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
207
|
-
enumerable: true,
|
|
208
|
-
configurable: true,
|
|
209
|
-
writable: true,
|
|
210
|
-
value: ["langchain", "schema", "runnable", "remote"]
|
|
211
|
-
});
|
|
212
|
-
const { url, options } = fields;
|
|
213
|
-
this.url = url.replace(/\/$/, ""); // remove trailing slash
|
|
214
|
-
this.options = options;
|
|
215
|
-
}
|
|
216
|
-
async post(path, body) {
|
|
217
|
-
return await fetch(`${this.url}${path}`, {
|
|
218
|
-
method: "POST",
|
|
219
|
-
body: JSON.stringify(body),
|
|
220
|
-
headers: {
|
|
221
|
-
"Content-Type": "application/json",
|
|
222
|
-
...this.options?.headers,
|
|
223
|
-
},
|
|
224
|
-
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
async invoke(input, options) {
|
|
228
|
-
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
229
|
-
const response = await this.post("/invoke", {
|
|
230
|
-
input,
|
|
231
|
-
config: removeCallbacks(config),
|
|
232
|
-
kwargs: kwargs ?? {},
|
|
233
|
-
});
|
|
234
|
-
return revive((await response.json()).output);
|
|
235
|
-
}
|
|
236
|
-
async _batch(inputs, options, _, batchOptions) {
|
|
237
|
-
if (batchOptions?.returnExceptions) {
|
|
238
|
-
throw new Error("returnExceptions is not supported for remote clients");
|
|
239
|
-
}
|
|
240
|
-
const configsAndKwargsArray = options?.map((opts) => this._separateRunnableConfigFromCallOptions(opts));
|
|
241
|
-
const [configs, kwargs] = configsAndKwargsArray?.reduce(([pc, pk], [c, k]) => [
|
|
242
|
-
[...pc, c],
|
|
243
|
-
[...pk, k],
|
|
244
|
-
], [[], []]) ?? [undefined, undefined];
|
|
245
|
-
const response = await this.post("/batch", {
|
|
246
|
-
inputs,
|
|
247
|
-
config: (configs ?? [])
|
|
248
|
-
.map(removeCallbacks)
|
|
249
|
-
.map((config) => ({ ...config, ...batchOptions })),
|
|
250
|
-
kwargs,
|
|
251
|
-
});
|
|
252
|
-
const body = await response.json();
|
|
253
|
-
if (!body.output)
|
|
254
|
-
throw new Error("Invalid response from remote runnable");
|
|
255
|
-
return revive(body.output);
|
|
256
|
-
}
|
|
257
|
-
async batch(inputs, options, batchOptions) {
|
|
258
|
-
if (batchOptions?.returnExceptions) {
|
|
259
|
-
throw Error("returnExceptions is not supported for remote clients");
|
|
260
|
-
}
|
|
261
|
-
return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
|
|
262
|
-
}
|
|
263
|
-
async stream(input, options) {
|
|
264
|
-
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
265
|
-
const response = await this.post("/stream", {
|
|
266
|
-
input,
|
|
267
|
-
config,
|
|
268
|
-
kwargs,
|
|
269
|
-
});
|
|
270
|
-
if (!response.ok) {
|
|
271
|
-
const json = await response.json();
|
|
272
|
-
const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
|
|
273
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
274
|
-
error.response = response;
|
|
275
|
-
throw error;
|
|
276
|
-
}
|
|
277
|
-
const { body } = response;
|
|
278
|
-
if (!body) {
|
|
279
|
-
throw new Error("Could not begin remote stream. Please check the given URL and try again.");
|
|
280
|
-
}
|
|
281
|
-
const stream = new ReadableStream({
|
|
282
|
-
async start(controller) {
|
|
283
|
-
const enqueueLine = (0, event_source_parse_1.getMessages)((msg) => {
|
|
284
|
-
if (msg.data)
|
|
285
|
-
controller.enqueue(deserialize(msg.data));
|
|
286
|
-
});
|
|
287
|
-
const onLine = (line, fieldLength, flush) => {
|
|
288
|
-
enqueueLine(line, fieldLength, flush);
|
|
289
|
-
if (flush)
|
|
290
|
-
controller.close();
|
|
291
|
-
};
|
|
292
|
-
await (0, event_source_parse_1.getBytes)(body, (0, event_source_parse_1.getLines)(onLine));
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
return stream_1.IterableReadableStream.fromReadableStream(stream);
|
|
296
|
-
}
|
|
297
|
-
async *streamLog(input, options, streamOptions) {
|
|
298
|
-
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
299
|
-
const stream = new log_stream_1.LogStreamCallbackHandler({
|
|
300
|
-
...streamOptions,
|
|
301
|
-
autoClose: false,
|
|
302
|
-
});
|
|
303
|
-
const { callbacks } = config;
|
|
304
|
-
if (callbacks === undefined) {
|
|
305
|
-
config.callbacks = [stream];
|
|
306
|
-
}
|
|
307
|
-
else if (Array.isArray(callbacks)) {
|
|
308
|
-
config.callbacks = callbacks.concat([stream]);
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
const copiedCallbacks = callbacks.copy();
|
|
312
|
-
copiedCallbacks.inheritableHandlers.push(stream);
|
|
313
|
-
config.callbacks = copiedCallbacks;
|
|
314
|
-
}
|
|
315
|
-
// The type is in camelCase but the API only accepts snake_case.
|
|
316
|
-
const camelCaseStreamOptions = {
|
|
317
|
-
include_names: streamOptions?.includeNames,
|
|
318
|
-
include_types: streamOptions?.includeTypes,
|
|
319
|
-
include_tags: streamOptions?.includeTags,
|
|
320
|
-
exclude_names: streamOptions?.excludeNames,
|
|
321
|
-
exclude_types: streamOptions?.excludeTypes,
|
|
322
|
-
exclude_tags: streamOptions?.excludeTags,
|
|
323
|
-
};
|
|
324
|
-
const response = await this.post("/stream_log", {
|
|
325
|
-
input,
|
|
326
|
-
config,
|
|
327
|
-
kwargs,
|
|
328
|
-
...camelCaseStreamOptions,
|
|
329
|
-
diff: false,
|
|
330
|
-
});
|
|
331
|
-
const { body } = response;
|
|
332
|
-
if (!body) {
|
|
333
|
-
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
334
|
-
}
|
|
335
|
-
const runnableStream = (0, event_source_parse_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
336
|
-
for await (const log of runnableStream) {
|
|
337
|
-
yield revive(JSON.parse(log));
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
exports.RemoteRunnable = RemoteRunnable;
|
|
17
|
+
__exportStar(require("@langchain/core/runnables/remote"), exports);
|
|
@@ -1,30 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { CallbackManagerForChainRun } from "@langchain/core/callbacks/manager";
|
|
3
|
-
import { type LogStreamCallbackHandlerInput, type RunLogPatch } from "@langchain/core/tracers/log_stream";
|
|
4
|
-
import { IterableReadableStream } from "@langchain/core/utils/stream";
|
|
5
|
-
type RemoteRunnableOptions = {
|
|
6
|
-
timeout?: number;
|
|
7
|
-
headers?: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
10
|
-
private url;
|
|
11
|
-
private options?;
|
|
12
|
-
lc_namespace: string[];
|
|
13
|
-
constructor(fields: {
|
|
14
|
-
url: string;
|
|
15
|
-
options?: RemoteRunnableOptions;
|
|
16
|
-
});
|
|
17
|
-
private post;
|
|
18
|
-
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
19
|
-
_batch(inputs: RunInput[], options?: Partial<CallOptions>[], _?: (CallbackManagerForChainRun | undefined)[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
20
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
21
|
-
returnExceptions?: false;
|
|
22
|
-
}): Promise<RunOutput[]>;
|
|
23
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
24
|
-
returnExceptions: true;
|
|
25
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
26
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
27
|
-
stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStream<RunOutput>>;
|
|
28
|
-
streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
|
|
29
|
-
}
|
|
30
|
-
export {};
|
|
1
|
+
export * from "@langchain/core/runnables/remote";
|