allow change bedrock region.

This commit is contained in:
Chen188 2024-04-08 08:59:13 +00:00
parent 1a071847b7
commit 01ac5aa78c
3 changed files with 10 additions and 4 deletions

View File

@ -1711,6 +1711,10 @@ async function sendOpenAIRequest(type, messages, signal) {
if (!isQuiet) {
generate_data['assistant_prefill'] = substituteParams(oai_settings.assistant_prefill);
}
if (isBedrock) {
generate_data['bedrock_region'] = oai_settings.bedrock_region;
}
}
if (isOpenRouter) {

View File

@ -9,7 +9,7 @@ const getClient = (function() {
let aksk = '';
return function(region_name) {
const secrets = readSecret(SECRET_KEYS.BEDROCK);
const _aksk = secrets[0] + secrets[1];
const _aksk = secrets[0] + secrets[1] || '';
const refresh = _aksk != aksk;
if(! client[region_name] || refresh) {
@ -37,7 +37,7 @@ const getRuntimeClient = (function() {
let aksk = '';
return function(region_name) {
const secrets = readSecret(SECRET_KEYS.BEDROCK);
const _aksk = secrets[0] + secrets[1];
const _aksk = secrets[0] + secrets[1] || '';
const refresh = _aksk != aksk;
if(! client[region_name] || refresh) {

View File

@ -568,9 +568,11 @@ async function sendBedrockRequest(request, response) {
modelId: request.body.model, // required
};
const bedrock_region = request.body.bedrock_region || 'us-east-1';
console.log('Claude request:', JSON.stringify(bedrockClaudeRequestBody));
if (request.body.stream) {
const respBedrockStream = await invokeModelWithStreaming('us-east-1', bedrockClaudeRequestBody);
const respBedrockStream = await invokeModelWithStreaming(bedrock_region, bedrockClaudeRequestBody);
// Pipe remote SSE stream to Express response
forwardBedrockStreamResponse(respBedrockStream, response);
@ -579,7 +581,7 @@ async function sendBedrockRequest(request, response) {
// console.log(color.red(`Claude API returned error: ${generateResponse.status} ${generateResponse.statusText}\n${await generateResponse.text()}\n${divider}`));
// return response.status(generateResponse.status).send({ error: true });
// }
const resp = await invokeModel('us-east-1', bedrockClaudeRequestBody);
const resp = await invokeModel(bedrock_region, bedrockClaudeRequestBody);
const statusCode = resp['$metadata']['httpStatusCode'];
const body = resp.body.transformToString();