|
| 1 | +// smithy-typescript generated code |
| 2 | +import { getEndpointPlugin } from "@smithy/middleware-endpoint"; |
| 3 | +import { getSerdePlugin } from "@smithy/middleware-serde"; |
| 4 | +import { Command as $Command } from "@smithy/smithy-client"; |
| 5 | +import { MetadataBearer as __MetadataBearer } from "@smithy/types"; |
| 6 | + |
| 7 | +import { BedrockRuntimeClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../BedrockRuntimeClient"; |
| 8 | +import { commonParams } from "../endpoint/EndpointParameters"; |
| 9 | +import { |
| 10 | + ConverseStreamRequest, |
| 11 | + ConverseStreamResponse, |
| 12 | + ConverseStreamResponseFilterSensitiveLog, |
| 13 | +} from "../models/models_0"; |
| 14 | +import { de_ConverseStreamCommand, se_ConverseStreamCommand } from "../protocols/Aws_restJson1"; |
| 15 | + |
| 16 | +/** |
| 17 | + * @public |
| 18 | + */ |
| 19 | +export { __MetadataBearer, $Command }; |
| 20 | +/** |
| 21 | + * @public |
| 22 | + * |
| 23 | + * The input for {@link ConverseStreamCommand}. |
| 24 | + */ |
| 25 | +export interface ConverseStreamCommandInput extends ConverseStreamRequest {} |
| 26 | +/** |
| 27 | + * @public |
| 28 | + * |
| 29 | + * The output of {@link ConverseStreamCommand}. |
| 30 | + */ |
| 31 | +export interface ConverseStreamCommandOutput extends ConverseStreamResponse, __MetadataBearer {} |
| 32 | + |
| 33 | +/** |
| 34 | + * <p>Sends messages to the specified Amazon Bedrock model and returns |
| 35 | + * the response in a stream. <code>ConverseStream</code> provides a consistent API |
| 36 | + * that works with all Amazon Bedrock models that support messages. |
| 37 | + * This allows you to write code once and use it with different models. Should a |
| 38 | + * model have unique inference parameters, you can also pass those unique parameters to the |
| 39 | + * model. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p> |
| 40 | + * <p>To find out if a model supports streaming, call <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_GetFoundationModel.html">GetFoundationModel</a> |
| 41 | + * and check the <code>responseStreamingSupported</code> field in the response.</p> |
| 42 | + * <p>For example code, see <i>Invoke model with streaming code |
| 43 | + * example</i> in the <i>Amazon Bedrock User Guide</i>. |
| 44 | + * </p> |
| 45 | + * <p>This operation requires permission for the <code>bedrock:InvokeModelWithResponseStream</code> action.</p> |
| 46 | + * @example |
| 47 | + * Use a bare-bones client and the command you need to make an API call. |
| 48 | + * ```javascript |
| 49 | + * import { BedrockRuntimeClient, ConverseStreamCommand } from "@aws-sdk/client-bedrock-runtime"; // ES Modules import |
| 50 | + * // const { BedrockRuntimeClient, ConverseStreamCommand } = require("@aws-sdk/client-bedrock-runtime"); // CommonJS import |
| 51 | + * const client = new BedrockRuntimeClient(config); |
| 52 | + * const input = { // ConverseStreamRequest |
| 53 | + * modelId: "STRING_VALUE", // required |
| 54 | + * messages: [ // Messages // required |
| 55 | + * { // Message |
| 56 | + * role: "user" || "assistant", // required |
| 57 | + * content: [ // ContentBlocks // required |
| 58 | + * { // ContentBlock Union: only one key present |
| 59 | + * text: "STRING_VALUE", |
| 60 | + * image: { // ImageBlock |
| 61 | + * format: "png" || "jpeg" || "gif" || "webp", // required |
| 62 | + * source: { // ImageSource Union: only one key present |
| 63 | + * bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("") |
| 64 | + * }, |
| 65 | + * }, |
| 66 | + * toolUse: { // ToolUseBlock |
| 67 | + * toolUseId: "STRING_VALUE", // required |
| 68 | + * name: "STRING_VALUE", // required |
| 69 | + * input: "DOCUMENT_VALUE", // required |
| 70 | + * }, |
| 71 | + * toolResult: { // ToolResultBlock |
| 72 | + * toolUseId: "STRING_VALUE", // required |
| 73 | + * content: [ // ToolResultContentBlocks // required |
| 74 | + * { // ToolResultContentBlock Union: only one key present |
| 75 | + * json: "DOCUMENT_VALUE", |
| 76 | + * text: "STRING_VALUE", |
| 77 | + * image: { |
| 78 | + * format: "png" || "jpeg" || "gif" || "webp", // required |
| 79 | + * source: {// Union: only one key present |
| 80 | + * bytes: new Uint8Array(), // e.g. Buffer.from("") or new TextEncoder().encode("") |
| 81 | + * }, |
| 82 | + * }, |
| 83 | + * }, |
| 84 | + * ], |
| 85 | + * status: "success" || "error", |
| 86 | + * }, |
| 87 | + * }, |
| 88 | + * ], |
| 89 | + * }, |
| 90 | + * ], |
| 91 | + * system: [ // SystemContentBlocks |
| 92 | + * { // SystemContentBlock Union: only one key present |
| 93 | + * text: "STRING_VALUE", |
| 94 | + * }, |
| 95 | + * ], |
| 96 | + * inferenceConfig: { // InferenceConfiguration |
| 97 | + * maxTokens: Number("int"), |
| 98 | + * temperature: Number("float"), |
| 99 | + * topP: Number("float"), |
| 100 | + * stopSequences: [ // NonEmptyStringList |
| 101 | + * "STRING_VALUE", |
| 102 | + * ], |
| 103 | + * }, |
| 104 | + * toolConfig: { // ToolConfiguration |
| 105 | + * tools: [ // Tools // required |
| 106 | + * { // Tool Union: only one key present |
| 107 | + * toolSpec: { // ToolSpecification |
| 108 | + * name: "STRING_VALUE", // required |
| 109 | + * description: "STRING_VALUE", |
| 110 | + * inputSchema: { // ToolInputSchema Union: only one key present |
| 111 | + * json: "DOCUMENT_VALUE", |
| 112 | + * }, |
| 113 | + * }, |
| 114 | + * }, |
| 115 | + * ], |
| 116 | + * toolChoice: { // ToolChoice Union: only one key present |
| 117 | + * auto: {}, |
| 118 | + * any: {}, |
| 119 | + * tool: { // SpecificToolChoice |
| 120 | + * name: "STRING_VALUE", // required |
| 121 | + * }, |
| 122 | + * }, |
| 123 | + * }, |
| 124 | + * additionalModelRequestFields: "DOCUMENT_VALUE", |
| 125 | + * additionalModelResponseFieldPaths: [ // AdditionalModelResponseFieldPaths |
| 126 | + * "STRING_VALUE", |
| 127 | + * ], |
| 128 | + * }; |
| 129 | + * const command = new ConverseStreamCommand(input); |
| 130 | + * const response = await client.send(command); |
| 131 | + * // { // ConverseStreamResponse |
| 132 | + * // stream: { // ConverseStreamOutput Union: only one key present |
| 133 | + * // messageStart: { // MessageStartEvent |
| 134 | + * // role: "user" || "assistant", // required |
| 135 | + * // }, |
| 136 | + * // contentBlockStart: { // ContentBlockStartEvent |
| 137 | + * // start: { // ContentBlockStart Union: only one key present |
| 138 | + * // toolUse: { // ToolUseBlockStart |
| 139 | + * // toolUseId: "STRING_VALUE", // required |
| 140 | + * // name: "STRING_VALUE", // required |
| 141 | + * // }, |
| 142 | + * // }, |
| 143 | + * // contentBlockIndex: Number("int"), // required |
| 144 | + * // }, |
| 145 | + * // contentBlockDelta: { // ContentBlockDeltaEvent |
| 146 | + * // delta: { // ContentBlockDelta Union: only one key present |
| 147 | + * // text: "STRING_VALUE", |
| 148 | + * // toolUse: { // ToolUseBlockDelta |
| 149 | + * // input: "STRING_VALUE", // required |
| 150 | + * // }, |
| 151 | + * // }, |
| 152 | + * // contentBlockIndex: Number("int"), // required |
| 153 | + * // }, |
| 154 | + * // contentBlockStop: { // ContentBlockStopEvent |
| 155 | + * // contentBlockIndex: Number("int"), // required |
| 156 | + * // }, |
| 157 | + * // messageStop: { // MessageStopEvent |
| 158 | + * // stopReason: "end_turn" || "tool_use" || "max_tokens" || "stop_sequence" || "content_filtered", // required |
| 159 | + * // additionalModelResponseFields: "DOCUMENT_VALUE", |
| 160 | + * // }, |
| 161 | + * // metadata: { // ConverseStreamMetadataEvent |
| 162 | + * // usage: { // TokenUsage |
| 163 | + * // inputTokens: Number("int"), // required |
| 164 | + * // outputTokens: Number("int"), // required |
| 165 | + * // totalTokens: Number("int"), // required |
| 166 | + * // }, |
| 167 | + * // metrics: { // ConverseStreamMetrics |
| 168 | + * // latencyMs: Number("long"), // required |
| 169 | + * // }, |
| 170 | + * // }, |
| 171 | + * // internalServerException: { // InternalServerException |
| 172 | + * // message: "STRING_VALUE", |
| 173 | + * // }, |
| 174 | + * // modelStreamErrorException: { // ModelStreamErrorException |
| 175 | + * // message: "STRING_VALUE", |
| 176 | + * // originalStatusCode: Number("int"), |
| 177 | + * // originalMessage: "STRING_VALUE", |
| 178 | + * // }, |
| 179 | + * // validationException: { // ValidationException |
| 180 | + * // message: "STRING_VALUE", |
| 181 | + * // }, |
| 182 | + * // throttlingException: { // ThrottlingException |
| 183 | + * // message: "STRING_VALUE", |
| 184 | + * // }, |
| 185 | + * // }, |
| 186 | + * // }; |
| 187 | + * |
| 188 | + * ``` |
| 189 | + * |
| 190 | + * @param ConverseStreamCommandInput - {@link ConverseStreamCommandInput} |
| 191 | + * @returns {@link ConverseStreamCommandOutput} |
| 192 | + * @see {@link ConverseStreamCommandInput} for command's `input` shape. |
| 193 | + * @see {@link ConverseStreamCommandOutput} for command's `response` shape. |
| 194 | + * @see {@link BedrockRuntimeClientResolvedConfig | config} for BedrockRuntimeClient's `config` shape. |
| 195 | + * |
| 196 | + * @throws {@link AccessDeniedException} (client fault) |
| 197 | + * <p>The request is denied because of missing access permissions.</p> |
| 198 | + * |
| 199 | + * @throws {@link InternalServerException} (server fault) |
| 200 | + * <p>An internal server error occurred. Retry your request.</p> |
| 201 | + * |
| 202 | + * @throws {@link ModelErrorException} (client fault) |
| 203 | + * <p>The request failed due to an error while processing the model.</p> |
| 204 | + * |
| 205 | + * @throws {@link ModelNotReadyException} (client fault) |
| 206 | + * <p>The model specified in the request is not ready to serve inference requests.</p> |
| 207 | + * |
| 208 | + * @throws {@link ModelTimeoutException} (client fault) |
| 209 | + * <p>The request took too long to process. Processing time exceeded the model timeout length.</p> |
| 210 | + * |
| 211 | + * @throws {@link ResourceNotFoundException} (client fault) |
| 212 | + * <p>The specified resource ARN was not found. Check the ARN and try your request again.</p> |
| 213 | + * |
| 214 | + * @throws {@link ThrottlingException} (client fault) |
| 215 | + * <p>The number of requests exceeds the limit. Resubmit your request later.</p> |
| 216 | + * |
| 217 | + * @throws {@link ValidationException} (client fault) |
| 218 | + * <p>Input validation failed. Check your request parameters and retry the request.</p> |
| 219 | + * |
| 220 | + * @throws {@link BedrockRuntimeServiceException} |
| 221 | + * <p>Base exception class for all service exceptions from BedrockRuntime service.</p> |
| 222 | + * |
| 223 | + * @public |
| 224 | + */ |
| 225 | +export class ConverseStreamCommand extends $Command |
| 226 | + .classBuilder< |
| 227 | + ConverseStreamCommandInput, |
| 228 | + ConverseStreamCommandOutput, |
| 229 | + BedrockRuntimeClientResolvedConfig, |
| 230 | + ServiceInputTypes, |
| 231 | + ServiceOutputTypes |
| 232 | + >() |
| 233 | + .ep({ |
| 234 | + ...commonParams, |
| 235 | + }) |
| 236 | + .m(function (this: any, Command: any, cs: any, config: BedrockRuntimeClientResolvedConfig, o: any) { |
| 237 | + return [ |
| 238 | + getSerdePlugin(config, this.serialize, this.deserialize), |
| 239 | + getEndpointPlugin(config, Command.getEndpointParameterInstructions()), |
| 240 | + ]; |
| 241 | + }) |
| 242 | + .s("AmazonBedrockFrontendService", "ConverseStream", { |
| 243 | + /** |
| 244 | + * @internal |
| 245 | + */ |
| 246 | + eventStream: { |
| 247 | + output: true, |
| 248 | + }, |
| 249 | + }) |
| 250 | + .n("BedrockRuntimeClient", "ConverseStreamCommand") |
| 251 | + .f(void 0, ConverseStreamResponseFilterSensitiveLog) |
| 252 | + .ser(se_ConverseStreamCommand) |
| 253 | + .de(de_ConverseStreamCommand) |
| 254 | + .build() {} |
0 commit comments