@langchain/core 0.2.21 → 0.2.22-rc.0
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/runnables/remote.cjs +34 -3
- package/dist/runnables/remote.d.ts +17 -0
- package/dist/runnables/remote.js +34 -3
- package/package.json +1 -1
|
@@ -229,6 +229,19 @@ function serialize(input) {
|
|
|
229
229
|
}
|
|
230
230
|
return input;
|
|
231
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Client for interacting with LangChain runnables
|
|
234
|
+
* that are hosted as LangServe endpoints.
|
|
235
|
+
*
|
|
236
|
+
* Allows you to interact with hosted runnables using the standard
|
|
237
|
+
* `.invoke()`, `.stream()`, `.streamEvents()`, etc. methods that
|
|
238
|
+
* other runnables support.
|
|
239
|
+
*
|
|
240
|
+
* @param url - The base URL of the LangServe endpoint.
|
|
241
|
+
* @param options - Optional configuration for the remote runnable, including timeout and headers.
|
|
242
|
+
* @param fetch - Optional custom fetch implementation.
|
|
243
|
+
* @param fetchRequestOptions - Optional additional options for fetch requests.
|
|
244
|
+
*/
|
|
232
245
|
class RemoteRunnable extends base_js_1.Runnable {
|
|
233
246
|
constructor(fields) {
|
|
234
247
|
super(fields);
|
|
@@ -244,25 +257,43 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
244
257
|
writable: true,
|
|
245
258
|
value: void 0
|
|
246
259
|
});
|
|
260
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
261
|
+
Object.defineProperty(this, "fetchImplementation", {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
configurable: true,
|
|
264
|
+
writable: true,
|
|
265
|
+
value: fetch
|
|
266
|
+
});
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
|
+
Object.defineProperty(this, "fetchRequestOptions", {
|
|
269
|
+
enumerable: true,
|
|
270
|
+
configurable: true,
|
|
271
|
+
writable: true,
|
|
272
|
+
value: void 0
|
|
273
|
+
});
|
|
247
274
|
Object.defineProperty(this, "lc_namespace", {
|
|
248
275
|
enumerable: true,
|
|
249
276
|
configurable: true,
|
|
250
277
|
writable: true,
|
|
251
278
|
value: ["langchain", "schema", "runnable", "remote"]
|
|
252
279
|
});
|
|
253
|
-
const { url, options } = fields;
|
|
280
|
+
const { url, options, fetch: fetchImplementation, fetchRequestOptions, } = fields;
|
|
254
281
|
this.url = url.replace(/\/$/, ""); // remove trailing slash
|
|
255
282
|
this.options = options;
|
|
283
|
+
this.fetchImplementation = fetchImplementation ?? this.fetchImplementation;
|
|
284
|
+
this.fetchRequestOptions = fetchRequestOptions;
|
|
256
285
|
}
|
|
257
286
|
async post(path, body, signal) {
|
|
258
|
-
return
|
|
287
|
+
return this.fetchImplementation(`${this.url}${path}`, {
|
|
259
288
|
method: "POST",
|
|
260
289
|
body: JSON.stringify(serialize(body)),
|
|
290
|
+
signal: signal ?? AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
291
|
+
...this.fetchRequestOptions,
|
|
261
292
|
headers: {
|
|
262
293
|
"Content-Type": "application/json",
|
|
294
|
+
...this.fetchRequestOptions?.headers,
|
|
263
295
|
...this.options?.headers,
|
|
264
296
|
},
|
|
265
|
-
signal: signal ?? AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
266
297
|
});
|
|
267
298
|
}
|
|
268
299
|
async _invoke(input, options, _) {
|
|
@@ -7,13 +7,30 @@ type RemoteRunnableOptions = {
|
|
|
7
7
|
timeout?: number;
|
|
8
8
|
headers?: Record<string, unknown>;
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Client for interacting with LangChain runnables
|
|
12
|
+
* that are hosted as LangServe endpoints.
|
|
13
|
+
*
|
|
14
|
+
* Allows you to interact with hosted runnables using the standard
|
|
15
|
+
* `.invoke()`, `.stream()`, `.streamEvents()`, etc. methods that
|
|
16
|
+
* other runnables support.
|
|
17
|
+
*
|
|
18
|
+
* @param url - The base URL of the LangServe endpoint.
|
|
19
|
+
* @param options - Optional configuration for the remote runnable, including timeout and headers.
|
|
20
|
+
* @param fetch - Optional custom fetch implementation.
|
|
21
|
+
* @param fetchRequestOptions - Optional additional options for fetch requests.
|
|
22
|
+
*/
|
|
10
23
|
export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
11
24
|
private url;
|
|
12
25
|
private options?;
|
|
26
|
+
fetchImplementation: (...args: any[]) => any;
|
|
27
|
+
fetchRequestOptions?: Record<string, any>;
|
|
13
28
|
lc_namespace: string[];
|
|
14
29
|
constructor(fields: {
|
|
15
30
|
url: string;
|
|
16
31
|
options?: RemoteRunnableOptions;
|
|
32
|
+
fetch?: (...args: any[]) => any;
|
|
33
|
+
fetchRequestOptions?: Record<string, any>;
|
|
17
34
|
});
|
|
18
35
|
private post;
|
|
19
36
|
_invoke(input: RunInput, options?: Partial<CallOptions>, _?: CallbackManagerForChainRun): Promise<RunOutput>;
|
package/dist/runnables/remote.js
CHANGED
|
@@ -226,6 +226,19 @@ function serialize(input) {
|
|
|
226
226
|
}
|
|
227
227
|
return input;
|
|
228
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Client for interacting with LangChain runnables
|
|
231
|
+
* that are hosted as LangServe endpoints.
|
|
232
|
+
*
|
|
233
|
+
* Allows you to interact with hosted runnables using the standard
|
|
234
|
+
* `.invoke()`, `.stream()`, `.streamEvents()`, etc. methods that
|
|
235
|
+
* other runnables support.
|
|
236
|
+
*
|
|
237
|
+
* @param url - The base URL of the LangServe endpoint.
|
|
238
|
+
* @param options - Optional configuration for the remote runnable, including timeout and headers.
|
|
239
|
+
* @param fetch - Optional custom fetch implementation.
|
|
240
|
+
* @param fetchRequestOptions - Optional additional options for fetch requests.
|
|
241
|
+
*/
|
|
229
242
|
export class RemoteRunnable extends Runnable {
|
|
230
243
|
constructor(fields) {
|
|
231
244
|
super(fields);
|
|
@@ -241,25 +254,43 @@ export class RemoteRunnable extends Runnable {
|
|
|
241
254
|
writable: true,
|
|
242
255
|
value: void 0
|
|
243
256
|
});
|
|
257
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
+
Object.defineProperty(this, "fetchImplementation", {
|
|
259
|
+
enumerable: true,
|
|
260
|
+
configurable: true,
|
|
261
|
+
writable: true,
|
|
262
|
+
value: fetch
|
|
263
|
+
});
|
|
264
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
265
|
+
Object.defineProperty(this, "fetchRequestOptions", {
|
|
266
|
+
enumerable: true,
|
|
267
|
+
configurable: true,
|
|
268
|
+
writable: true,
|
|
269
|
+
value: void 0
|
|
270
|
+
});
|
|
244
271
|
Object.defineProperty(this, "lc_namespace", {
|
|
245
272
|
enumerable: true,
|
|
246
273
|
configurable: true,
|
|
247
274
|
writable: true,
|
|
248
275
|
value: ["langchain", "schema", "runnable", "remote"]
|
|
249
276
|
});
|
|
250
|
-
const { url, options } = fields;
|
|
277
|
+
const { url, options, fetch: fetchImplementation, fetchRequestOptions, } = fields;
|
|
251
278
|
this.url = url.replace(/\/$/, ""); // remove trailing slash
|
|
252
279
|
this.options = options;
|
|
280
|
+
this.fetchImplementation = fetchImplementation ?? this.fetchImplementation;
|
|
281
|
+
this.fetchRequestOptions = fetchRequestOptions;
|
|
253
282
|
}
|
|
254
283
|
async post(path, body, signal) {
|
|
255
|
-
return
|
|
284
|
+
return this.fetchImplementation(`${this.url}${path}`, {
|
|
256
285
|
method: "POST",
|
|
257
286
|
body: JSON.stringify(serialize(body)),
|
|
287
|
+
signal: signal ?? AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
288
|
+
...this.fetchRequestOptions,
|
|
258
289
|
headers: {
|
|
259
290
|
"Content-Type": "application/json",
|
|
291
|
+
...this.fetchRequestOptions?.headers,
|
|
260
292
|
...this.options?.headers,
|
|
261
293
|
},
|
|
262
|
-
signal: signal ?? AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
263
294
|
});
|
|
264
295
|
}
|
|
265
296
|
async _invoke(input, options, _) {
|