Skip to content

Commit 8f0175d

Browse files
author
awstools
committed
feat(client-bedrock-runtime): This release introduces our latest bedrock runtime API, InvokeModelWithBidirectionalStream. The API supports both input and output streams and is supported by only HTTP2.0.
1 parent f0a5384 commit 8f0175d

File tree

12 files changed

+920
-3
lines changed

12 files changed

+920
-3
lines changed

clients/client-bedrock-runtime/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ InvokeModel
242242

243243
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/InvokeModelCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelCommandOutput/)
244244

245+
</details>
246+
<details>
247+
<summary>
248+
InvokeModelWithBidirectionalStream
249+
</summary>
250+
251+
[Command API Reference](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/bedrock-runtime/command/InvokeModelWithBidirectionalStreamCommand/) / [Input](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelWithBidirectionalStreamCommandInput/) / [Output](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-bedrock-runtime/Interface/InvokeModelWithBidirectionalStreamCommandOutput/)
252+
245253
</details>
246254
<details>
247255
<summary>

clients/client-bedrock-runtime/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"@aws-crypto/sha256-js": "5.2.0",
2323
"@aws-sdk/core": "*",
2424
"@aws-sdk/credential-provider-node": "*",
25+
"@aws-sdk/eventstream-handler-node": "*",
26+
"@aws-sdk/middleware-eventstream": "*",
2527
"@aws-sdk/middleware-host-header": "*",
2628
"@aws-sdk/middleware-logger": "*",
2729
"@aws-sdk/middleware-recursion-detection": "*",

clients/client-bedrock-runtime/src/BedrockRuntime.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import {
2020
GetAsyncInvokeCommandOutput,
2121
} from "./commands/GetAsyncInvokeCommand";
2222
import { InvokeModelCommand, InvokeModelCommandInput, InvokeModelCommandOutput } from "./commands/InvokeModelCommand";
23+
import {
24+
InvokeModelWithBidirectionalStreamCommand,
25+
InvokeModelWithBidirectionalStreamCommandInput,
26+
InvokeModelWithBidirectionalStreamCommandOutput,
27+
} from "./commands/InvokeModelWithBidirectionalStreamCommand";
2328
import {
2429
InvokeModelWithResponseStreamCommand,
2530
InvokeModelWithResponseStreamCommandInput,
@@ -42,6 +47,7 @@ const commands = {
4247
ConverseStreamCommand,
4348
GetAsyncInvokeCommand,
4449
InvokeModelCommand,
50+
InvokeModelWithBidirectionalStreamCommand,
4551
InvokeModelWithResponseStreamCommand,
4652
ListAsyncInvokesCommand,
4753
StartAsyncInvokeCommand,
@@ -112,6 +118,23 @@ export interface BedrockRuntime {
112118
cb: (err: any, data?: InvokeModelCommandOutput) => void
113119
): void;
114120

121+
/**
122+
* @see {@link InvokeModelWithBidirectionalStreamCommand}
123+
*/
124+
invokeModelWithBidirectionalStream(
125+
args: InvokeModelWithBidirectionalStreamCommandInput,
126+
options?: __HttpHandlerOptions
127+
): Promise<InvokeModelWithBidirectionalStreamCommandOutput>;
128+
invokeModelWithBidirectionalStream(
129+
args: InvokeModelWithBidirectionalStreamCommandInput,
130+
cb: (err: any, data?: InvokeModelWithBidirectionalStreamCommandOutput) => void
131+
): void;
132+
invokeModelWithBidirectionalStream(
133+
args: InvokeModelWithBidirectionalStreamCommandInput,
134+
options: __HttpHandlerOptions,
135+
cb: (err: any, data?: InvokeModelWithBidirectionalStreamCommandOutput) => void
136+
): void;
137+
115138
/**
116139
* @see {@link InvokeModelWithResponseStreamCommand}
117140
*/

clients/client-bedrock-runtime/src/BedrockRuntimeClient.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
// smithy-typescript generated code
2+
import {
3+
EventStreamInputConfig,
4+
EventStreamResolvedConfig,
5+
resolveEventStreamConfig,
6+
} from "@aws-sdk/middleware-eventstream";
27
import {
38
getHostHeaderPlugin,
49
HostHeaderInputConfig,
@@ -13,6 +18,7 @@ import {
1318
UserAgentInputConfig,
1419
UserAgentResolvedConfig,
1520
} from "@aws-sdk/middleware-user-agent";
21+
import { EventStreamPayloadHandlerProvider as __EventStreamPayloadHandlerProvider } from "@aws-sdk/types";
1622
import { RegionInputConfig, RegionResolvedConfig, resolveRegionConfig } from "@smithy/config-resolver";
1723
import {
1824
DefaultIdentityProviderConfig,
@@ -64,6 +70,10 @@ import { ConverseCommandInput, ConverseCommandOutput } from "./commands/Converse
6470
import { ConverseStreamCommandInput, ConverseStreamCommandOutput } from "./commands/ConverseStreamCommand";
6571
import { GetAsyncInvokeCommandInput, GetAsyncInvokeCommandOutput } from "./commands/GetAsyncInvokeCommand";
6672
import { InvokeModelCommandInput, InvokeModelCommandOutput } from "./commands/InvokeModelCommand";
73+
import {
74+
InvokeModelWithBidirectionalStreamCommandInput,
75+
InvokeModelWithBidirectionalStreamCommandOutput,
76+
} from "./commands/InvokeModelWithBidirectionalStreamCommand";
6777
import {
6878
InvokeModelWithResponseStreamCommandInput,
6979
InvokeModelWithResponseStreamCommandOutput,
@@ -90,6 +100,7 @@ export type ServiceInputTypes =
90100
| ConverseStreamCommandInput
91101
| GetAsyncInvokeCommandInput
92102
| InvokeModelCommandInput
103+
| InvokeModelWithBidirectionalStreamCommandInput
93104
| InvokeModelWithResponseStreamCommandInput
94105
| ListAsyncInvokesCommandInput
95106
| StartAsyncInvokeCommandInput;
@@ -103,6 +114,7 @@ export type ServiceOutputTypes =
103114
| ConverseStreamCommandOutput
104115
| GetAsyncInvokeCommandOutput
105116
| InvokeModelCommandOutput
117+
| InvokeModelWithBidirectionalStreamCommandOutput
106118
| InvokeModelWithResponseStreamCommandOutput
107119
| ListAsyncInvokesCommandOutput
108120
| StartAsyncInvokeCommandOutput;
@@ -261,6 +273,12 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
261273
* The {@link @smithy/smithy-client#DefaultsMode} that will be used to determine how certain default configuration options are resolved in the SDK.
262274
*/
263275
defaultsMode?: __DefaultsMode | __Provider<__DefaultsMode>;
276+
277+
/**
278+
* The function that provides necessary utilities for handling request event stream.
279+
* @internal
280+
*/
281+
eventStreamPayloadHandlerProvider?: __EventStreamPayloadHandlerProvider;
264282
}
265283

266284
/**
@@ -275,6 +293,7 @@ export type BedrockRuntimeClientConfigType = Partial<__SmithyConfiguration<__Htt
275293
EndpointInputConfig<EndpointParameters> &
276294
EventStreamSerdeInputConfig &
277295
HttpAuthSchemeInputConfig &
296+
EventStreamInputConfig &
278297
ClientInputEndpointParameters;
279298
/**
280299
* @public
@@ -296,6 +315,7 @@ export type BedrockRuntimeClientResolvedConfigType = __SmithyResolvedConfigurati
296315
EndpointResolvedConfig<EndpointParameters> &
297316
EventStreamSerdeResolvedConfig &
298317
HttpAuthSchemeResolvedConfig &
318+
EventStreamResolvedConfig &
299319
ClientResolvedEndpointParameters;
300320
/**
301321
* @public
@@ -331,8 +351,9 @@ export class BedrockRuntimeClient extends __Client<
331351
const _config_6 = resolveEndpointConfig(_config_5);
332352
const _config_7 = resolveEventStreamSerdeConfig(_config_6);
333353
const _config_8 = resolveHttpAuthSchemeConfig(_config_7);
334-
const _config_9 = resolveRuntimeExtensions(_config_8, configuration?.extensions || []);
335-
this.config = _config_9;
354+
const _config_9 = resolveEventStreamConfig(_config_8);
355+
const _config_10 = resolveRuntimeExtensions(_config_9, configuration?.extensions || []);
356+
this.config = _config_10;
336357
this.middlewareStack.use(getUserAgentPlugin(this.config));
337358
this.middlewareStack.use(getRetryPlugin(this.config));
338359
this.middlewareStack.use(getContentLengthPlugin(this.config));
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// smithy-typescript generated code
2+
import { getEventStreamPlugin } from "@aws-sdk/middleware-eventstream";
3+
import { getEndpointPlugin } from "@smithy/middleware-endpoint";
4+
import { getSerdePlugin } from "@smithy/middleware-serde";
5+
import { Command as $Command } from "@smithy/smithy-client";
6+
import { MetadataBearer as __MetadataBearer } from "@smithy/types";
7+
8+
import { BedrockRuntimeClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../BedrockRuntimeClient";
9+
import { commonParams } from "../endpoint/EndpointParameters";
10+
import {
11+
InvokeModelWithBidirectionalStreamRequest,
12+
InvokeModelWithBidirectionalStreamRequestFilterSensitiveLog,
13+
InvokeModelWithBidirectionalStreamResponse,
14+
InvokeModelWithBidirectionalStreamResponseFilterSensitiveLog,
15+
} from "../models/models_0";
16+
import {
17+
de_InvokeModelWithBidirectionalStreamCommand,
18+
se_InvokeModelWithBidirectionalStreamCommand,
19+
} from "../protocols/Aws_restJson1";
20+
21+
/**
22+
* @public
23+
*/
24+
export type { __MetadataBearer };
25+
export { $Command };
26+
/**
27+
* @public
28+
*
29+
* The input for {@link InvokeModelWithBidirectionalStreamCommand}.
30+
*/
31+
export interface InvokeModelWithBidirectionalStreamCommandInput extends InvokeModelWithBidirectionalStreamRequest {}
32+
/**
33+
* @public
34+
*
35+
* The output of {@link InvokeModelWithBidirectionalStreamCommand}.
36+
*/
37+
export interface InvokeModelWithBidirectionalStreamCommandOutput
38+
extends InvokeModelWithBidirectionalStreamResponse,
39+
__MetadataBearer {}
40+
41+
/**
42+
* <p>Invoke the specified Amazon Bedrock model to run inference using the bidirectional stream. The response is returned in a stream that remains open for 8 minutes. A single session can contain multiple prompts and responses from the model. The prompts to the model are provided as audio files and the model's responses are spoken back to the user and transcribed.</p>
43+
* <p>It is possible for users to interrupt the model's response with a new prompt, which will halt the response speech. The model will retain contextual awareness of the conversation while pivoting to respond to the new prompt.</p>
44+
* @example
45+
* Use a bare-bones client and the command you need to make an API call.
46+
* ```javascript
47+
* import { BedrockRuntimeClient, InvokeModelWithBidirectionalStreamCommand } from "@aws-sdk/client-bedrock-runtime"; // ES Modules import
48+
* // const { BedrockRuntimeClient, InvokeModelWithBidirectionalStreamCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import
49+
* const client = new BedrockRuntimeClient(config);
50+
* const input = { // InvokeModelWithBidirectionalStreamRequest
51+
* modelId: "STRING_VALUE", // required
52+
* body: { // InvokeModelWithBidirectionalStreamInput Union: only one key present
53+
* chunk: { // BidirectionalInputPayloadPart
54+
* bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("")
55+
* },
56+
* },
57+
* };
58+
* const command = new InvokeModelWithBidirectionalStreamCommand(input);
59+
* const response = await client.send(command);
60+
* // { // InvokeModelWithBidirectionalStreamResponse
61+
* // body: { // InvokeModelWithBidirectionalStreamOutput Union: only one key present
62+
* // chunk: { // BidirectionalOutputPayloadPart
63+
* // bytes: new Uint8Array(),
64+
* // },
65+
* // internalServerException: { // InternalServerException
66+
* // message: "STRING_VALUE",
67+
* // },
68+
* // modelStreamErrorException: { // ModelStreamErrorException
69+
* // message: "STRING_VALUE",
70+
* // originalStatusCode: Number("int"),
71+
* // originalMessage: "STRING_VALUE",
72+
* // },
73+
* // validationException: { // ValidationException
74+
* // message: "STRING_VALUE",
75+
* // },
76+
* // throttlingException: { // ThrottlingException
77+
* // message: "STRING_VALUE",
78+
* // },
79+
* // modelTimeoutException: { // ModelTimeoutException
80+
* // message: "STRING_VALUE",
81+
* // },
82+
* // serviceUnavailableException: { // ServiceUnavailableException
83+
* // message: "STRING_VALUE",
84+
* // },
85+
* // },
86+
* // };
87+
*
88+
* ```
89+
*
90+
* @param InvokeModelWithBidirectionalStreamCommandInput - {@link InvokeModelWithBidirectionalStreamCommandInput}
91+
* @returns {@link InvokeModelWithBidirectionalStreamCommandOutput}
92+
* @see {@link InvokeModelWithBidirectionalStreamCommandInput} for command's `input` shape.
93+
* @see {@link InvokeModelWithBidirectionalStreamCommandOutput} for command's `response` shape.
94+
* @see {@link BedrockRuntimeClientResolvedConfig | config} for BedrockRuntimeClient's `config` shape.
95+
*
96+
* @throws {@link AccessDeniedException} (client fault)
97+
* <p>The request is denied because you do not have sufficient permissions to perform the requested action. For troubleshooting this error,
98+
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-access-denied">AccessDeniedException</a> in the Amazon Bedrock User Guide</p>
99+
*
100+
* @throws {@link InternalServerException} (server fault)
101+
* <p>An internal server error occurred. For troubleshooting this error,
102+
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-internal-failure">InternalFailure</a> in the Amazon Bedrock User Guide</p>
103+
*
104+
* @throws {@link ModelErrorException} (client fault)
105+
* <p>The request failed due to an error while processing the model.</p>
106+
*
107+
* @throws {@link ModelNotReadyException} (client fault)
108+
* <p>The model specified in the request is not ready to serve inference requests. The AWS SDK
109+
* will automatically retry the operation up to 5 times. For information about configuring
110+
* automatic retries, see <a href="https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html">Retry behavior</a> in the <i>AWS SDKs and Tools</i>
111+
* reference guide.</p>
112+
*
113+
* @throws {@link ModelStreamErrorException} (client fault)
114+
* <p>An error occurred while streaming the response. Retry your request.</p>
115+
*
116+
* @throws {@link ModelTimeoutException} (client fault)
117+
* <p>The request took too long to process. Processing time exceeded the model timeout length.</p>
118+
*
119+
* @throws {@link ResourceNotFoundException} (client fault)
120+
* <p>The specified resource ARN was not found. For troubleshooting this error,
121+
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-resource-not-found">ResourceNotFound</a> in the Amazon Bedrock User Guide</p>
122+
*
123+
* @throws {@link ServiceQuotaExceededException} (client fault)
124+
* <p>Your request exceeds the service quota for your account. You can view your quotas at <a href="https://docs.aws.amazon.com/servicequotas/latest/userguide/gs-request-quota.html">Viewing service quotas</a>. You can resubmit your request later.</p>
125+
*
126+
* @throws {@link ServiceUnavailableException} (server fault)
127+
* <p>The service isn't currently available. For troubleshooting this error,
128+
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-service-unavailable">ServiceUnavailable</a> in the Amazon Bedrock User Guide</p>
129+
*
130+
* @throws {@link ThrottlingException} (client fault)
131+
* <p>Your request was denied due to exceeding the account quotas for <i>Amazon Bedrock</i>. For
132+
* troubleshooting this error, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-throttling-exception">ThrottlingException</a> in the Amazon Bedrock User Guide</p>
133+
*
134+
* @throws {@link ValidationException} (client fault)
135+
* <p>The input fails to satisfy the constraints specified by <i>Amazon Bedrock</i>. For troubleshooting this error,
136+
* see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html#ts-validation-error">ValidationError</a> in the Amazon Bedrock User Guide</p>
137+
*
138+
* @throws {@link BedrockRuntimeServiceException}
139+
* <p>Base exception class for all service exceptions from BedrockRuntime service.</p>
140+
*
141+
*
142+
* @public
143+
*/
144+
export class InvokeModelWithBidirectionalStreamCommand extends $Command
145+
.classBuilder<
146+
InvokeModelWithBidirectionalStreamCommandInput,
147+
InvokeModelWithBidirectionalStreamCommandOutput,
148+
BedrockRuntimeClientResolvedConfig,
149+
ServiceInputTypes,
150+
ServiceOutputTypes
151+
>()
152+
.ep(commonParams)
153+
.m(function (this: any, Command: any, cs: any, config: BedrockRuntimeClientResolvedConfig, o: any) {
154+
return [
155+
getSerdePlugin(config, this.serialize, this.deserialize),
156+
getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
157+
getEventStreamPlugin(config),
158+
];
159+
})
160+
.s("AmazonBedrockFrontendService", "InvokeModelWithBidirectionalStream", {
161+
/**
162+
* @internal
163+
*/
164+
eventStream: {
165+
input: true,
166+
output: true,
167+
},
168+
})
169+
.n("BedrockRuntimeClient", "InvokeModelWithBidirectionalStreamCommand")
170+
.f(
171+
InvokeModelWithBidirectionalStreamRequestFilterSensitiveLog,
172+
InvokeModelWithBidirectionalStreamResponseFilterSensitiveLog
173+
)
174+
.ser(se_InvokeModelWithBidirectionalStreamCommand)
175+
.de(de_InvokeModelWithBidirectionalStreamCommand)
176+
.build() {
177+
/** @internal type navigation helper, not in runtime. */
178+
protected declare static __types: {
179+
api: {
180+
input: InvokeModelWithBidirectionalStreamRequest;
181+
output: InvokeModelWithBidirectionalStreamResponse;
182+
};
183+
sdk: {
184+
input: InvokeModelWithBidirectionalStreamCommandInput;
185+
output: InvokeModelWithBidirectionalStreamCommandOutput;
186+
};
187+
};
188+
}

clients/client-bedrock-runtime/src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from "./ConverseCommand";
44
export * from "./ConverseStreamCommand";
55
export * from "./GetAsyncInvokeCommand";
66
export * from "./InvokeModelCommand";
7+
export * from "./InvokeModelWithBidirectionalStreamCommand";
78
export * from "./InvokeModelWithResponseStreamCommand";
89
export * from "./ListAsyncInvokesCommand";
910
export * from "./StartAsyncInvokeCommand";

0 commit comments

Comments
 (0)