Skip to content

Commit

Permalink
feat(client-bedrock-runtime): Add model timeout exception for InvokeM…
Browse files Browse the repository at this point in the history
…odelWithResponseStream API and update validator for invoke model identifier.
  • Loading branch information
awstools committed Oct 2, 2023
1 parent d233302 commit b07fb6e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface InvokeModelCommandOutput extends InvokeModelCommandOutputType,
* @public
* <p>Invokes the specified Bedrock model to run inference using the input provided in the request body.
* You use InvokeModel to run inference for text models, image models, and embedding models.</p>
* <p>For more information about invoking models, see Using the API in the <a href="https://d2eo22ngex1n9g.cloudfront.net/Documentation/BedrockUserGuide.pdf">Bedrock User Guide</a>.</p>
* <p>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>
* <p>For example requests, see Examples (after the Errors section).</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface InvokeModelWithResponseStreamCommandOutput
* @public
* <p>Invoke the specified Bedrock model to run inference using the input provided.
* Return the response in a stream.</p>
* <p>For more information about invoking models, see Using the API in the <a href="https://d2eo22ngex1n9g.cloudfront.net/Documentation/BedrockUserGuide.pdf">Bedrock User Guide</a>.</p>
* <p>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>
* <p>For an example request and response, see Examples (after the Errors section).</p>
* @example
* Use a bare-bones client and the command you need to make an API call.
Expand Down Expand Up @@ -93,6 +93,9 @@ export interface InvokeModelWithResponseStreamCommandOutput
* // throttlingException: { // ThrottlingException
* // message: "STRING_VALUE",
* // },
* // modelTimeoutException: { // ModelTimeoutException
* // message: "STRING_VALUE",
* // },
* // },
* // contentType: "STRING_VALUE", // required
* // };
Expand Down
24 changes: 24 additions & 0 deletions clients/client-bedrock-runtime/src/models/models_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export type ResponseStream =
| ResponseStream.ChunkMember
| ResponseStream.InternalServerExceptionMember
| ResponseStream.ModelStreamErrorExceptionMember
| ResponseStream.ModelTimeoutExceptionMember
| ResponseStream.ThrottlingExceptionMember
| ResponseStream.ValidationExceptionMember
| ResponseStream.$UnknownMember;
Expand All @@ -349,6 +350,7 @@ export namespace ResponseStream {
modelStreamErrorException?: never;
validationException?: never;
throttlingException?: never;
modelTimeoutException?: never;
$unknown?: never;
}

Expand All @@ -362,6 +364,7 @@ export namespace ResponseStream {
modelStreamErrorException?: never;
validationException?: never;
throttlingException?: never;
modelTimeoutException?: never;
$unknown?: never;
}

Expand All @@ -375,6 +378,7 @@ export namespace ResponseStream {
modelStreamErrorException: ModelStreamErrorException;
validationException?: never;
throttlingException?: never;
modelTimeoutException?: never;
$unknown?: never;
}

Expand All @@ -388,6 +392,7 @@ export namespace ResponseStream {
modelStreamErrorException?: never;
validationException: ValidationException;
throttlingException?: never;
modelTimeoutException?: never;
$unknown?: never;
}

Expand All @@ -401,6 +406,21 @@ export namespace ResponseStream {
modelStreamErrorException?: never;
validationException?: never;
throttlingException: ThrottlingException;
modelTimeoutException?: never;
$unknown?: never;
}

/**
* @public
* <p>The request took too long to process. Processing time exceeded the model timeout length.</p>
*/
export interface ModelTimeoutExceptionMember {
chunk?: never;
internalServerException?: never;
modelStreamErrorException?: never;
validationException?: never;
throttlingException?: never;
modelTimeoutException: ModelTimeoutException;
$unknown?: never;
}

Expand All @@ -413,6 +433,7 @@ export namespace ResponseStream {
modelStreamErrorException?: never;
validationException?: never;
throttlingException?: never;
modelTimeoutException?: never;
$unknown: [string, any];
}

Expand All @@ -422,6 +443,7 @@ export namespace ResponseStream {
modelStreamErrorException: (value: ModelStreamErrorException) => T;
validationException: (value: ValidationException) => T;
throttlingException: (value: ThrottlingException) => T;
modelTimeoutException: (value: ModelTimeoutException) => T;
_: (name: string, value: any) => T;
}

Expand All @@ -433,6 +455,7 @@ export namespace ResponseStream {
return visitor.modelStreamErrorException(value.modelStreamErrorException);
if (value.validationException !== undefined) return visitor.validationException(value.validationException);
if (value.throttlingException !== undefined) return visitor.throttlingException(value.throttlingException);
if (value.modelTimeoutException !== undefined) return visitor.modelTimeoutException(value.modelTimeoutException);
return visitor._(value.$unknown[0], value.$unknown[1]);
};
}
Expand Down Expand Up @@ -497,6 +520,7 @@ export const ResponseStreamFilterSensitiveLog = (obj: ResponseStream): any => {
if (obj.modelStreamErrorException !== undefined) return { modelStreamErrorException: obj.modelStreamErrorException };
if (obj.validationException !== undefined) return { validationException: obj.validationException };
if (obj.throttlingException !== undefined) return { throttlingException: obj.throttlingException };
if (obj.modelTimeoutException !== undefined) return { modelTimeoutException: obj.modelTimeoutException };
if (obj.$unknown !== undefined) return { [obj.$unknown[0]]: "UNKNOWN" };
};

Expand Down
12 changes: 12 additions & 0 deletions clients/client-bedrock-runtime/src/protocols/Aws_restJson1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ const de_ResponseStream = (
throttlingException: await de_ThrottlingException_event(event["throttlingException"], context),
};
}
if (event["modelTimeoutException"] != null) {
return {
modelTimeoutException: await de_ModelTimeoutException_event(event["modelTimeoutException"], context),
};
}
return { $unknown: output };
});
};
Expand All @@ -495,6 +500,13 @@ const de_ModelStreamErrorException_event = async (
};
return de_ModelStreamErrorExceptionRes(parsedOutput, context);
};
const de_ModelTimeoutException_event = async (output: any, context: __SerdeContext): Promise<ModelTimeoutException> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
};
return de_ModelTimeoutExceptionRes(parsedOutput, context);
};
const de_PayloadPart_event = async (output: any, context: __SerdeContext): Promise<PayloadPart> => {
const contents: PayloadPart = {} as any;
const data: any = await parseBody(output.body, context);
Expand Down
9 changes: 6 additions & 3 deletions codegen/sdk-codegen/aws-models/bedrock-runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@
}
],
"traits": {
"smithy.api#documentation": "<p>Invokes the specified Bedrock model to run inference using the input provided in the request body. \n You use InvokeModel to run inference for text models, image models, and embedding models.</p>\n <p>For more information about invoking models, see Using the API in the <a href=\"https://d2eo22ngex1n9g.cloudfront.net/Documentation/BedrockUserGuide.pdf\">Bedrock User Guide</a>.</p>\n <p>For example requests, see Examples (after the Errors section).</p>",
"smithy.api#documentation": "<p>Invokes the specified Bedrock model to run inference using the input provided in the request body. \n You use InvokeModel to run inference for text models, image models, and embedding models.</p>\n <p>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>\n <p>For example requests, see Examples (after the Errors section).</p>",
"smithy.api#http": {
"code": 200,
"method": "POST",
Expand All @@ -786,7 +786,7 @@
"min": 1,
"max": 2048
},
"smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63})([:][a-z0-9-]{1,63}){0,2})|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63})([:][a-z0-9-]{1,63}){0,2})|(([0-9a-zA-Z][_-]?)+)$"
"smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63}))|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63}))|(([0-9a-zA-Z][_-]?)+)$"
}
},
"com.amazonaws.bedrockruntime#InvokeModelRequest": {
Expand Down Expand Up @@ -892,7 +892,7 @@
}
],
"traits": {
"smithy.api#documentation": "<p>Invoke the specified Bedrock model to run inference using the input provided.\n Return the response in a stream.</p>\n <p>For more information about invoking models, see Using the API in the <a href=\"https://d2eo22ngex1n9g.cloudfront.net/Documentation/BedrockUserGuide.pdf\">Bedrock User Guide</a>.</p>\n <p>For an example request and response, see Examples (after the Errors section).</p>",
"smithy.api#documentation": "<p>Invoke the specified Bedrock model to run inference using the input provided.\n Return the response in a stream.</p>\n <p>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>\n <p>For an example request and response, see Examples (after the Errors section).</p>",
"smithy.api#http": {
"code": 200,
"method": "POST",
Expand Down Expand Up @@ -1104,6 +1104,9 @@
},
"throttlingException": {
"target": "com.amazonaws.bedrockruntime#ThrottlingException"
},
"modelTimeoutException": {
"target": "com.amazonaws.bedrockruntime#ModelTimeoutException"
}
},
"traits": {
Expand Down

0 comments on commit b07fb6e

Please sign in to comment.