Skip to content

Commit 1eb09e3

Browse files
committed
readd kwargs
1 parent 097e1af commit 1eb09e3

File tree

1 file changed

+32
-7
lines changed
  • libs/langchain-core/src/runnables

1 file changed

+32
-7
lines changed

libs/langchain-core/src/runnables/base.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export abstract class Runnable<
160160
// eslint-disable-next-line @typescript-eslint/no-use-before-define
161161
return new RunnableRetry({
162162
bound: this,
163+
kwargs: {},
163164
config: {},
164165
maxAttemptNumber: fields?.stopAfterAttempt,
165166
...fields,
@@ -178,6 +179,7 @@ export abstract class Runnable<
178179
return new RunnableBinding({
179180
bound: this,
180181
config,
182+
kwargs: {},
181183
});
182184
}
183185

@@ -1192,6 +1194,8 @@ export type RunnableBindingArgs<
11921194
CallOptions extends RunnableConfig = RunnableConfig
11931195
> = {
11941196
bound: Runnable<RunInput, RunOutput, CallOptions>;
1197+
/** @deprecated Use {@link config} instead. */
1198+
kwargs?: Partial<CallOptions>;
11951199
config: RunnableConfig;
11961200
configFactories?: Array<
11971201
(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>
@@ -1256,13 +1260,16 @@ export class RunnableBinding<
12561260

12571261
config: RunnableConfig;
12581262

1263+
kwargs?: Partial<CallOptions>;
1264+
12591265
configFactories?: Array<
12601266
(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>
12611267
>;
12621268

12631269
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>) {
12641270
super(fields);
12651271
this.bound = fields.bound;
1272+
this.kwargs = fields.kwargs;
12661273
this.config = fields.config;
12671274
this.configFactories = fields.configFactories;
12681275
}
@@ -1296,6 +1303,7 @@ export class RunnableBinding<
12961303
): RunnableBinding<RunInput, RunOutput, CallOptions>;
12971304
})({
12981305
bound: this.bound,
1306+
kwargs: this.kwargs,
12991307
config: { ...this.config, ...config },
13001308
});
13011309
}
@@ -1307,6 +1315,7 @@ export class RunnableBinding<
13071315
// eslint-disable-next-line @typescript-eslint/no-use-before-define
13081316
return new RunnableRetry({
13091317
bound: this.bound,
1318+
kwargs: this.kwargs,
13101319
config: this.config,
13111320
maxAttemptNumber: fields?.stopAfterAttempt,
13121321
...fields,
@@ -1317,7 +1326,10 @@ export class RunnableBinding<
13171326
input: RunInput,
13181327
options?: Partial<CallOptions>
13191328
): Promise<RunOutput> {
1320-
return this.bound.invoke(input, await ensureConfig(options));
1329+
return this.bound.invoke(
1330+
input,
1331+
await this._mergeConfig(options, this.kwargs)
1332+
);
13211333
}
13221334

13231335
async batch(
@@ -1346,32 +1358,41 @@ export class RunnableBinding<
13461358
const mergedOptions = Array.isArray(options)
13471359
? await Promise.all(
13481360
options.map(async (individualOption) =>
1349-
ensureConfig(individualOption)
1361+
this._mergeConfig(ensureConfig(individualOption), this.kwargs)
13501362
)
13511363
)
1352-
: await ensureConfig(options);
1364+
: await this._mergeConfig(ensureConfig(options), this.kwargs);
13531365
return this.bound.batch(inputs, mergedOptions, batchOptions);
13541366
}
13551367

13561368
async *_streamIterator(
13571369
input: RunInput,
13581370
options?: Partial<CallOptions> | undefined
13591371
) {
1360-
yield* this.bound._streamIterator(input, await ensureConfig(options));
1372+
yield* this.bound._streamIterator(
1373+
input,
1374+
await this._mergeConfig(ensureConfig(options), this.kwargs)
1375+
);
13611376
}
13621377

13631378
async stream(
13641379
input: RunInput,
13651380
options?: Partial<CallOptions> | undefined
13661381
): Promise<IterableReadableStream<RunOutput>> {
1367-
return this.bound.stream(input, await ensureConfig(options));
1382+
return this.bound.stream(
1383+
input,
1384+
await this._mergeConfig(ensureConfig(options), this.kwargs)
1385+
);
13681386
}
13691387

13701388
async *transform(
13711389
generator: AsyncGenerator<RunInput>,
13721390
options?: Partial<CallOptions>
13731391
): AsyncGenerator<RunOutput> {
1374-
yield* this.bound.transform(generator, await ensureConfig(options));
1392+
yield* this.bound.transform(
1393+
generator,
1394+
await this._mergeConfig(ensureConfig(options), this.kwargs)
1395+
);
13751396
}
13761397

13771398
streamEvents(
@@ -1402,7 +1423,10 @@ export class RunnableBinding<
14021423
yield* outerThis.bound.streamEvents(
14031424
input,
14041425
{
1405-
...ensureConfig(options),
1426+
...(await outerThis._mergeConfig(
1427+
ensureConfig(options),
1428+
outerThis.kwargs
1429+
)),
14061430
version: options.version,
14071431
},
14081432
streamOptions
@@ -1441,6 +1465,7 @@ export class RunnableBinding<
14411465
}): Runnable<RunInput, RunOutput, CallOptions> {
14421466
return new RunnableBinding<RunInput, RunOutput, CallOptions>({
14431467
bound: this.bound,
1468+
kwargs: this.kwargs,
14441469
config: this.config,
14451470
configFactories: [
14461471
(config) => ({

0 commit comments

Comments
 (0)