Skip to content

Commit

Permalink
update bedrock/api.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
narengogi committed Jan 17, 2025
1 parent fa2c44b commit 44fbd01
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions src/providers/bedrock/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,41 @@ const BedrockAPIConfig: ProviderAPIConfig = {
);
},
getEndpoint: ({ fn, gatewayRequestBodyJSON, gatewayRequestURL }) => {
if (fn === 'uploadFile') return '';
if (fn === 'retrieveFileContent') {
const objectName = gatewayRequestURL.split('/v1/files/')[1].split('/')[0];
return `/${objectName}`;
}
if (fn === 'cancelBatch') {
const batchId = gatewayRequestURL.split('/v1/batches/')[1].split('/')[0];
return `/model-invocation-job/${batchId}/stop`;
switch (fn) {
case 'uploadFile':
return '';
case 'retrieveFile':
return '';
case 'listFiles':
return '';
case 'deleteFile':
return '';
case 'retrieveFileContent': {
const objectName = gatewayRequestURL
.split('/v1/files/')[1]
.split('/')[0];
return `/${objectName}`;
}
case 'getBatchOutput':
return '';
case 'createBatch': {
return '/model-invocation-job';
}
case 'cancelBatch': {
return `/model-invocation-job/${gatewayRequestURL.split('/v1/batches/')[1].split('/')[0]}/stop`;
}
case 'retrieveBatch': {
return `/model-invocation-job/${gatewayRequestURL.split('/v1/batches/')[1]}`;
}
case 'listBatches': {
return '/model-invocation-jobs';
}
default:
break;
}

const { model, stream } = gatewayRequestBodyJSON;
if (!model) throw new GatewayError('Model is required');
let mappedFn: string = fn;
if (stream) {
mappedFn = `stream-${fn}`;
Expand All @@ -143,6 +168,7 @@ const BedrockAPIConfig: ProviderAPIConfig = {
endpoint = `/model/${model}/converse`;
streamEndpoint = `/model/${model}/converse-stream`;
}

switch (mappedFn) {
case 'chatComplete': {
return endpoint;
Expand All @@ -162,18 +188,6 @@ const BedrockAPIConfig: ProviderAPIConfig = {
case 'imageGenerate': {
return endpoint;
}
case 'createBatch': {
return '/model-invocation-job';
}
case 'cancelBatch': {
return `/model-invocation-job/${gatewayRequestURL.split('/').pop()}/stop`;
}
case 'retrieveBatch': {
return `/model-invocation-job/${gatewayRequestURL.split('/v1/batches/')[1]}`;
}
case 'listBatches': {
return '/model-invocation-jobs';
}
default:
return '';
}
Expand Down

0 comments on commit 44fbd01

Please sign in to comment.