Skip to content

Commit

Permalink
feat(client-bedrock-runtime): Added support for Async Invoke Operatio…
Browse files Browse the repository at this point in the history
…ns Start, List and Get. Support for invocation logs with `requestMetadata` field in Converse, ConverseStream, Invoke and InvokeStream. Video content blocks in Converse/ConverseStream accept raw bytes or S3 URI.
  • Loading branch information
awstools committed Dec 3, 2024
1 parent d8beae2 commit 9169d69
Show file tree
Hide file tree
Showing 18 changed files with 2,575 additions and 200 deletions.
38 changes: 31 additions & 7 deletions clients/client-bedrock-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ using your favorite package manager:

The AWS SDK is modulized by clients and commands.
To send a request, you only need to import the `BedrockRuntimeClient` and
the commands you need, for example `ConverseCommand`:
the commands you need, for example `ListAsyncInvokesCommand`:

```js
// ES5 example
const { BedrockRuntimeClient, ConverseCommand } = require("@aws-sdk/client-bedrock-runtime");
const { BedrockRuntimeClient, ListAsyncInvokesCommand } = require("@aws-sdk/client-bedrock-runtime");
```

```ts
// ES6+ example
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
import { BedrockRuntimeClient, ListAsyncInvokesCommand } from "@aws-sdk/client-bedrock-runtime";
```

### Usage
Expand All @@ -51,7 +51,7 @@ const client = new BedrockRuntimeClient({ region: "REGION" });
const params = {
/** input parameters */
};
const command = new ConverseCommand(params);
const command = new ListAsyncInvokesCommand(params);
```

#### Async/await
Expand Down Expand Up @@ -130,15 +130,15 @@ const client = new AWS.BedrockRuntime({ region: "REGION" });

// async/await.
try {
const data = await client.converse(params);
const data = await client.listAsyncInvokes(params);
// process data.
} catch (error) {
// error handling.
}

// Promises.
client
.converse(params)
.listAsyncInvokes(params)
.then((data) => {
// process data.
})
Expand All @@ -147,7 +147,7 @@ client
});

// callbacks.
client.converse(params, (err, data) => {
client.listAsyncInvokes(params, (err, data) => {
// process err and data.
});
```
Expand Down Expand Up @@ -226,6 +226,14 @@ ConverseStream

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/ConverseStreamCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/ConverseStreamCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/ConverseStreamCommandOutput/)

</details>
<details>
<summary>
GetAsyncInvoke
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/GetAsyncInvokeCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/GetAsyncInvokeCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/GetAsyncInvokeCommandOutput/)

</details>
<details>
<summary>
Expand All @@ -243,3 +251,19 @@ InvokeModelWithResponseStream
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/InvokeModelWithResponseStreamCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelWithResponseStreamCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelWithResponseStreamCommandOutput/)

</details>
<details>
<summary>
ListAsyncInvokes
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/ListAsyncInvokesCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/ListAsyncInvokesCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/ListAsyncInvokesCommandOutput/)

</details>
<details>
<summary>
StartAsyncInvoke
</summary>

[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/StartAsyncInvokeCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/StartAsyncInvokeCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/StartAsyncInvokeCommandOutput/)

</details>
4 changes: 3 additions & 1 deletion clients/client-bedrock-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
"@smithy/util-retry": "^3.0.10",
"@smithy/util-stream": "^3.3.1",
"@smithy/util-utf8": "^3.0.0",
"tslib": "^2.6.2"
"@types/uuid": "^9.0.1",
"tslib": "^2.6.2",
"uuid": "^9.0.1"
},
"devDependencies": {
"@tsconfig/node16": "16.1.3",
Expand Down
67 changes: 67 additions & 0 deletions clients/client-bedrock-runtime/src/BedrockRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,37 @@ import {
ConverseStreamCommandInput,
ConverseStreamCommandOutput,
} from "./commands/ConverseStreamCommand";
import {
GetAsyncInvokeCommand,
GetAsyncInvokeCommandInput,
GetAsyncInvokeCommandOutput,
} from "./commands/GetAsyncInvokeCommand";
import { InvokeModelCommand, InvokeModelCommandInput, InvokeModelCommandOutput } from "./commands/InvokeModelCommand";
import {
InvokeModelWithResponseStreamCommand,
InvokeModelWithResponseStreamCommandInput,
InvokeModelWithResponseStreamCommandOutput,
} from "./commands/InvokeModelWithResponseStreamCommand";
import {
ListAsyncInvokesCommand,
ListAsyncInvokesCommandInput,
ListAsyncInvokesCommandOutput,
} from "./commands/ListAsyncInvokesCommand";
import {
StartAsyncInvokeCommand,
StartAsyncInvokeCommandInput,
StartAsyncInvokeCommandOutput,
} from "./commands/StartAsyncInvokeCommand";

const commands = {
ApplyGuardrailCommand,
ConverseCommand,
ConverseStreamCommand,
GetAsyncInvokeCommand,
InvokeModelCommand,
InvokeModelWithResponseStreamCommand,
ListAsyncInvokesCommand,
StartAsyncInvokeCommand,
};

export interface BedrockRuntime {
Expand Down Expand Up @@ -69,6 +87,20 @@ export interface BedrockRuntime {
cb: (err: any, data?: ConverseStreamCommandOutput) => void
): void;

/**
* @see {@link GetAsyncInvokeCommand}
*/
getAsyncInvoke(
args: GetAsyncInvokeCommandInput,
options?: __HttpHandlerOptions
): Promise<GetAsyncInvokeCommandOutput>;
getAsyncInvoke(args: GetAsyncInvokeCommandInput, cb: (err: any, data?: GetAsyncInvokeCommandOutput) => void): void;
getAsyncInvoke(
args: GetAsyncInvokeCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: GetAsyncInvokeCommandOutput) => void
): void;

/**
* @see {@link InvokeModelCommand}
*/
Expand Down Expand Up @@ -96,6 +128,41 @@ export interface BedrockRuntime {
options: __HttpHandlerOptions,
cb: (err: any, data?: InvokeModelWithResponseStreamCommandOutput) => void
): void;

/**
* @see {@link ListAsyncInvokesCommand}
*/
listAsyncInvokes(): Promise<ListAsyncInvokesCommandOutput>;
listAsyncInvokes(
args: ListAsyncInvokesCommandInput,
options?: __HttpHandlerOptions
): Promise<ListAsyncInvokesCommandOutput>;
listAsyncInvokes(
args: ListAsyncInvokesCommandInput,
cb: (err: any, data?: ListAsyncInvokesCommandOutput) => void
): void;
listAsyncInvokes(
args: ListAsyncInvokesCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: ListAsyncInvokesCommandOutput) => void
): void;

/**
* @see {@link StartAsyncInvokeCommand}
*/
startAsyncInvoke(
args: StartAsyncInvokeCommandInput,
options?: __HttpHandlerOptions
): Promise<StartAsyncInvokeCommandOutput>;
startAsyncInvoke(
args: StartAsyncInvokeCommandInput,
cb: (err: any, data?: StartAsyncInvokeCommandOutput) => void
): void;
startAsyncInvoke(
args: StartAsyncInvokeCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: StartAsyncInvokeCommandOutput) => void
): void;
}

/**
Expand Down
13 changes: 11 additions & 2 deletions clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ import {
import { ApplyGuardrailCommandInput, ApplyGuardrailCommandOutput } from "./commands/ApplyGuardrailCommand";
import { ConverseCommandInput, ConverseCommandOutput } from "./commands/ConverseCommand";
import { ConverseStreamCommandInput, ConverseStreamCommandOutput } from "./commands/ConverseStreamCommand";
import { GetAsyncInvokeCommandInput, GetAsyncInvokeCommandOutput } from "./commands/GetAsyncInvokeCommand";
import { InvokeModelCommandInput, InvokeModelCommandOutput } from "./commands/InvokeModelCommand";
import {
InvokeModelWithResponseStreamCommandInput,
InvokeModelWithResponseStreamCommandOutput,
} from "./commands/InvokeModelWithResponseStreamCommand";
import { ListAsyncInvokesCommandInput, ListAsyncInvokesCommandOutput } from "./commands/ListAsyncInvokesCommand";
import { StartAsyncInvokeCommandInput, StartAsyncInvokeCommandOutput } from "./commands/StartAsyncInvokeCommand";
import {
ClientInputEndpointParameters,
ClientResolvedEndpointParameters,
Expand All @@ -85,8 +88,11 @@ export type ServiceInputTypes =
| ApplyGuardrailCommandInput
| ConverseCommandInput
| ConverseStreamCommandInput
| GetAsyncInvokeCommandInput
| InvokeModelCommandInput
| InvokeModelWithResponseStreamCommandInput;
| InvokeModelWithResponseStreamCommandInput
| ListAsyncInvokesCommandInput
| StartAsyncInvokeCommandInput;

/**
* @public
Expand All @@ -95,8 +101,11 @@ export type ServiceOutputTypes =
| ApplyGuardrailCommandOutput
| ConverseCommandOutput
| ConverseStreamCommandOutput
| GetAsyncInvokeCommandOutput
| InvokeModelCommandOutput
| InvokeModelWithResponseStreamCommandOutput;
| InvokeModelWithResponseStreamCommandOutput
| ListAsyncInvokesCommandOutput
| StartAsyncInvokeCommandOutput;

/**
* @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export interface ApplyGuardrailCommandOutput extends ApplyGuardrailResponse, __M

/**
* <p>The action to apply a guardrail.</p>
* <p>For troubleshooting some of the common errors you might encounter when using the <code>ApplyGuardrail</code> API,
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html">Troubleshooting Amazon Bedrock API Error Codes</a> in the Amazon Bedrock User Guide</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
Expand Down
43 changes: 43 additions & 0 deletions clients/client-bedrock-runtime/src/commands/ConverseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* },
* },
* video: { // VideoBlock
* format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* source: { // VideoSource Union: only one key present
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* s3Location: { // S3Location
* uri: "STRING_VALUE", // required
* bucketOwner: "STRING_VALUE",
* },
* },
* },
* toolUse: { // ToolUseBlock
* toolUseId: "STRING_VALUE", // required
* name: "STRING_VALUE", // required
Expand All @@ -103,6 +113,16 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* },
* },
* video: {
* format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* source: {// Union: only one key present
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* s3Location: {
* uri: "STRING_VALUE", // required
* bucketOwner: "STRING_VALUE",
* },
* },
* },
* },
* ],
* status: "success" || "error",
Expand Down Expand Up @@ -174,6 +194,9 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths
* "STRING_VALUE",
* ],
* requestMetadata: { // RequestMetadata
* "<keys>": "STRING_VALUE",
* },
* performanceConfig: { // PerformanceConfiguration
* latency: "standard" || "optimized",
* },
Expand All @@ -200,6 +223,16 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* // bytes: new Uint8Array(),
* // },
* // },
* // video: { // VideoBlock
* // format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* // source: { // VideoSource Union: only one key present
* // bytes: new Uint8Array(),
* // s3Location: { // S3Location
* // uri: "STRING_VALUE", // required
* // bucketOwner: "STRING_VALUE",
* // },
* // },
* // },
* // toolUse: { // ToolUseBlock
* // toolUseId: "STRING_VALUE", // required
* // name: "STRING_VALUE", // required
Expand All @@ -224,6 +257,16 @@ export interface ConverseCommandOutput extends ConverseResponse, __MetadataBeare
* // bytes: new Uint8Array(),
* // },
* // },
* // video: {
* // format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* // source: {// Union: only one key present
* // bytes: new Uint8Array(),
* // s3Location: {
* // uri: "STRING_VALUE", // required
* // bucketOwner: "STRING_VALUE",
* // },
* // },
* // },
* // },
* // ],
* // status: "success" || "error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* },
* },
* video: { // VideoBlock
* format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* source: { // VideoSource Union: only one key present
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* s3Location: { // S3Location
* uri: "STRING_VALUE", // required
* bucketOwner: "STRING_VALUE",
* },
* },
* },
* toolUse: { // ToolUseBlock
* toolUseId: "STRING_VALUE", // required
* name: "STRING_VALUE", // required
Expand All @@ -114,6 +124,16 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* },
* },
* video: {
* format: "mkv" || "mov" || "mp4" || "webm" || "flv" || "mpeg" || "mpg" || "wmv" || "three_gp", // required
* source: {// Union: only one key present
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
* s3Location: {
* uri: "STRING_VALUE", // required
* bucketOwner: "STRING_VALUE",
* },
* },
* },
* },
* ],
* status: "success" || "error",
Expand Down Expand Up @@ -186,6 +206,9 @@ export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __M
* additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths
* "STRING_VALUE",
* ],
* requestMetadata: { // RequestMetadata
* "<keys>": "STRING_VALUE",
* },
* performanceConfig: { // PerformanceConfiguration
* latency: "standard" || "optimized",
* },
Expand Down
Loading

0 comments on commit 9169d69

Please sign in to comment.