Skip to content

Commit 714d106

Browse files
authored
feat(bedrock): add clientOptions to BedrockEmbeddings and ChatBedrock… (#8653)
1 parent c19f1ec commit 714d106

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

libs/langchain-aws/src/chat_models.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
} from "@aws-sdk/client-bedrock-runtime";
2020
import {
2121
BedrockRuntimeClient,
22+
BedrockRuntimeClientConfig,
2223
ConverseCommand,
2324
ConverseStreamCommand,
2425
} from "@aws-sdk/client-bedrock-runtime";
@@ -71,6 +72,13 @@ export interface ChatBedrockConverseInput
7172
*/
7273
client?: BedrockRuntimeClient;
7374

75+
/**
76+
* Overrideable configuration options for the BedrockRuntimeClient.
77+
* Allows customization of client configuration such as requestHandler, etc.
78+
* Will be ignored if 'client' is provided.
79+
*/
80+
clientOptions?: BedrockRuntimeClientConfig;
81+
7482
/**
7583
* Whether or not to stream responses
7684
*/
@@ -244,6 +252,10 @@ export interface ChatBedrockConverseCallOptions
244252
* secretAccessKey: process.env.BEDROCK_AWS_SECRET_ACCESS_KEY!,
245253
* accessKeyId: process.env.BEDROCK_AWS_ACCESS_KEY_ID!,
246254
* },
255+
* // Configure client options (e.g., custom request handler)
256+
* // clientOptions: {
257+
* // requestHandler: myCustomRequestHandler,
258+
* // },
247259
* // other params...
248260
* });
249261
* ```
@@ -666,6 +678,8 @@ export class ChatBedrockConverse
666678

667679
client: BedrockRuntimeClient;
668680

681+
clientOptions?: BedrockRuntimeClientConfig;
682+
669683
/**
670684
* Which types of `tool_choice` values the model supports.
671685
*
@@ -713,6 +727,7 @@ export class ChatBedrockConverse
713727
this.client =
714728
fields?.client ??
715729
new BedrockRuntimeClient({
730+
...fields?.clientOptions,
716731
region,
717732
credentials,
718733
endpoint: rest.endpointHost
@@ -731,6 +746,7 @@ export class ChatBedrockConverse
731746
this.streamUsage = rest?.streamUsage ?? this.streamUsage;
732747
this.guardrailConfig = rest?.guardrailConfig;
733748
this.performanceConfig = rest?.performanceConfig;
749+
this.clientOptions = rest?.clientOptions;
734750

735751
if (rest?.supportsToolChoiceValues === undefined) {
736752
this.supportsToolChoiceValues = supportedToolChoiceValuesForModel(

libs/langchain-aws/src/embeddings.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
BedrockRuntimeClient,
3+
BedrockRuntimeClientConfig,
34
InvokeModelCommand,
45
} from "@aws-sdk/client-bedrock-runtime";
56
import { Embeddings, EmbeddingsParams } from "@langchain/core/embeddings";
@@ -22,6 +23,13 @@ export interface BedrockEmbeddingsParams extends EmbeddingsParams {
2223
*/
2324
client?: BedrockRuntimeClient;
2425

26+
/**
27+
* Overrideable configuration options for the BedrockRuntimeClient.
28+
* Allows customization of client configuration such as requestHandler, etc.
29+
* Will be ignored if 'client' is provided.
30+
*/
31+
clientOptions?: BedrockRuntimeClientConfig;
32+
2533
region?: string;
2634

2735
credentials?: CredentialType;
@@ -39,6 +47,10 @@ export interface BedrockEmbeddingsParams extends EmbeddingsParams {
3947
* secretAccessKey: "your-secret-access-key",
4048
* },
4149
* model: "amazon.titan-embed-text-v1",
50+
* // Configure client options (e.g., custom request handler)
51+
* // clientOptions: {
52+
* // requestHandler: myCustomRequestHandler,
53+
* // },
4254
* });
4355
*
4456
* // Embed a query and log the result
@@ -56,16 +68,20 @@ export class BedrockEmbeddings
5668

5769
client: BedrockRuntimeClient;
5870

71+
clientOptions?: BedrockRuntimeClientConfig;
72+
5973
batchSize = 512;
6074

6175
constructor(fields?: BedrockEmbeddingsParams) {
6276
super(fields ?? {});
6377

6478
this.model = fields?.model ?? "amazon.titan-embed-text-v1";
79+
this.clientOptions = fields?.clientOptions;
6580

6681
this.client =
6782
fields?.client ??
6883
new BedrockRuntimeClient({
84+
...fields?.clientOptions,
6985
region: fields?.region,
7086
credentials: fields?.credentials,
7187
});

0 commit comments

Comments
 (0)