Update Bedrock.ts to support apiBase and headers from config.json file
We extend the code for the BedrockRuntimeClient to - support `endpoint` in the constructor in order to pass an `apiBase` parameter - support new headers defined on the config.json file, using `middlewareStack.add`
This commit is contained in:
parent
d60617fa34
commit
4eea793943
1 changed files with 20 additions and 0 deletions
|
|
@ -49,8 +49,10 @@ class Bedrock extends BaseLLM {
|
|||
options: CompletionOptions,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
const credentials = await this._getCredentials();
|
||||
|
||||
const client = new BedrockRuntimeClient({
|
||||
region: this.region,
|
||||
endpoint: this.apiBase,
|
||||
credentials: {
|
||||
accessKeyId: credentials.accessKeyId,
|
||||
secretAccessKey: credentials.secretAccessKey,
|
||||
|
|
@ -58,6 +60,24 @@ class Bedrock extends BaseLLM {
|
|||
},
|
||||
});
|
||||
|
||||
let config_headers = this.requestOptions && this.requestOptions.headers ? this.requestOptions.headers : {};
|
||||
// AWS SigV4 requires strict canonicalization of headers.
|
||||
// DO NOT USE "_" in your header name. It will return an error like below.
|
||||
// "The request signature we calculated does not match the signature you provided."
|
||||
|
||||
client.middlewareStack.add(
|
||||
(next) => async (args) => {
|
||||
args.request.headers = {
|
||||
...args.request.headers,
|
||||
...config_headers
|
||||
};
|
||||
return next(args);
|
||||
},
|
||||
{
|
||||
step: 'build'
|
||||
}
|
||||
);
|
||||
|
||||
const input = this._generateConverseInput(messages, options);
|
||||
const command = new ConverseStreamCommand(input);
|
||||
const response = await client.send(command);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue