diff --git a/clients/aws-sdk-bedrock-runtime/CHANGELOG.md b/clients/aws-sdk-bedrock-runtime/CHANGELOG.md index c37ee0c..bb32f84 100644 --- a/clients/aws-sdk-bedrock-runtime/CHANGELOG.md +++ b/clients/aws-sdk-bedrock-runtime/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +### Breaking +- Removed unused `serialize.py` and `deserialize.py` modules. + ## v0.1.0 ### API Changes diff --git a/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/deserialize.py b/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/deserialize.py deleted file mode 100644 index 3fd85cd..0000000 --- a/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/deserialize.py +++ /dev/null @@ -1,919 +0,0 @@ -# Code generated by smithy-python-codegen DO NOT EDIT. - -import json -from typing import Any - -from smithy_core.documents import DocumentValue -from smithy_core.types import TimestampFormat -from smithy_http.aio.interfaces import HTTPResponse -from smithy_http.aio.restjson import parse_rest_json_error_info -from smithy_json import JSONCodec - -from .config import Config -from .models import ( - AccessDeniedException, - ApiError, - ApplyGuardrailOutput, - ConflictException, - ConverseOperationOutput, - ConverseStreamOperationOutput, - GetAsyncInvokeOutput, - InternalServerException, - InvokeModelOutput, - InvokeModelWithBidirectionalStreamOperationOutput, - InvokeModelWithResponseStreamOutput, - ListAsyncInvokesOutput, - ModelErrorException, - ModelNotReadyException, - ModelStreamErrorException, - ModelTimeoutException, - ResourceNotFoundException, - ServiceQuotaExceededException, - ServiceUnavailableException, - StartAsyncInvokeOutput, - ThrottlingException, - UnknownApiError, - ValidationException, -) - - -async def _deserialize_apply_guardrail( - http_response: HTTPResponse, config: Config -) -> ApplyGuardrailOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_apply_guardrail(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ApplyGuardrailOutput.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ApplyGuardrailOutput(**kwargs) - - -async def _deserialize_error_apply_guardrail( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "servicequotaexceededexception": - return await _deserialize_error_service_quota_exceeded_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_converse( - http_response: HTTPResponse, config: Config -) -> ConverseOperationOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_converse(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ConverseOperationOutput.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ConverseOperationOutput(**kwargs) - - -async def _deserialize_error_converse( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "modelerrorexception": - return await _deserialize_error_model_error_exception( - http_response, config, parsed_body, message - ) - - case "modelnotreadyexception": - return await _deserialize_error_model_not_ready_exception( - http_response, config, parsed_body, message - ) - - case "modeltimeoutexception": - return await _deserialize_error_model_timeout_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_converse_stream( - http_response: HTTPResponse, config: Config -) -> ConverseStreamOperationOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_converse_stream(http_response, config) - - kwargs: dict[str, Any] = {} - - return ConverseStreamOperationOutput(**kwargs) - - -async def _deserialize_error_converse_stream( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "modelerrorexception": - return await _deserialize_error_model_error_exception( - http_response, config, parsed_body, message - ) - - case "modelnotreadyexception": - return await _deserialize_error_model_not_ready_exception( - http_response, config, parsed_body, message - ) - - case "modeltimeoutexception": - return await _deserialize_error_model_timeout_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_get_async_invoke( - http_response: HTTPResponse, config: Config -) -> GetAsyncInvokeOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_get_async_invoke(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = GetAsyncInvokeOutput.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return GetAsyncInvokeOutput(**kwargs) - - -async def _deserialize_error_get_async_invoke( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_invoke_model( - http_response: HTTPResponse, config: Config -) -> InvokeModelOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_invoke_model(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - kwargs["body"] = body - - for fld in http_response.fields: - for key, value in fld.as_tuples(): - _key_lowercase = key.lower() - match _key_lowercase: - case "content-type": - kwargs["content_type"] = value - - case "x-amzn-bedrock-performanceconfig-latency": - kwargs["performance_config_latency"] = value - - case _: - pass - - return InvokeModelOutput(**kwargs) - - -async def _deserialize_error_invoke_model( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "modelerrorexception": - return await _deserialize_error_model_error_exception( - http_response, config, parsed_body, message - ) - - case "modelnotreadyexception": - return await _deserialize_error_model_not_ready_exception( - http_response, config, parsed_body, message - ) - - case "modeltimeoutexception": - return await _deserialize_error_model_timeout_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "servicequotaexceededexception": - return await _deserialize_error_service_quota_exceeded_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_invoke_model_with_bidirectional_stream( - http_response: HTTPResponse, config: Config -) -> InvokeModelWithBidirectionalStreamOperationOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_invoke_model_with_bidirectional_stream( - http_response, config - ) - - kwargs: dict[str, Any] = {} - - return InvokeModelWithBidirectionalStreamOperationOutput(**kwargs) - - -async def _deserialize_error_invoke_model_with_bidirectional_stream( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "modelerrorexception": - return await _deserialize_error_model_error_exception( - http_response, config, parsed_body, message - ) - - case "modelnotreadyexception": - return await _deserialize_error_model_not_ready_exception( - http_response, config, parsed_body, message - ) - - case "modelstreamerrorexception": - return await _deserialize_error_model_stream_error_exception( - http_response, config, parsed_body, message - ) - - case "modeltimeoutexception": - return await _deserialize_error_model_timeout_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "servicequotaexceededexception": - return await _deserialize_error_service_quota_exceeded_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_invoke_model_with_response_stream( - http_response: HTTPResponse, config: Config -) -> InvokeModelWithResponseStreamOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_invoke_model_with_response_stream( - http_response, config - ) - - kwargs: dict[str, Any] = {} - - for fld in http_response.fields: - for key, value in fld.as_tuples(): - _key_lowercase = key.lower() - match _key_lowercase: - case "x-amzn-bedrock-content-type": - kwargs["content_type"] = value - - case "x-amzn-bedrock-performanceconfig-latency": - kwargs["performance_config_latency"] = value - - case _: - pass - - return InvokeModelWithResponseStreamOutput(**kwargs) - - -async def _deserialize_error_invoke_model_with_response_stream( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "modelerrorexception": - return await _deserialize_error_model_error_exception( - http_response, config, parsed_body, message - ) - - case "modelnotreadyexception": - return await _deserialize_error_model_not_ready_exception( - http_response, config, parsed_body, message - ) - - case "modelstreamerrorexception": - return await _deserialize_error_model_stream_error_exception( - http_response, config, parsed_body, message - ) - - case "modeltimeoutexception": - return await _deserialize_error_model_timeout_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "servicequotaexceededexception": - return await _deserialize_error_service_quota_exceeded_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_list_async_invokes( - http_response: HTTPResponse, config: Config -) -> ListAsyncInvokesOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_list_async_invokes(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ListAsyncInvokesOutput.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ListAsyncInvokesOutput(**kwargs) - - -async def _deserialize_error_list_async_invokes( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_start_async_invoke( - http_response: HTTPResponse, config: Config -) -> StartAsyncInvokeOutput: - if http_response.status != 200 and http_response.status >= 300: - raise await _deserialize_error_start_async_invoke(http_response, config) - - kwargs: dict[str, Any] = {} - - body = await http_response.consume_body_async() - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = StartAsyncInvokeOutput.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return StartAsyncInvokeOutput(**kwargs) - - -async def _deserialize_error_start_async_invoke( - http_response: HTTPResponse, config: Config -) -> ApiError: - code, message, parsed_body = await parse_rest_json_error_info(http_response) - - match code.lower(): - case "accessdeniedexception": - return await _deserialize_error_access_denied_exception( - http_response, config, parsed_body, message - ) - - case "conflictexception": - return await _deserialize_error_conflict_exception( - http_response, config, parsed_body, message - ) - - case "internalserverexception": - return await _deserialize_error_internal_server_exception( - http_response, config, parsed_body, message - ) - - case "resourcenotfoundexception": - return await _deserialize_error_resource_not_found_exception( - http_response, config, parsed_body, message - ) - - case "servicequotaexceededexception": - return await _deserialize_error_service_quota_exceeded_exception( - http_response, config, parsed_body, message - ) - - case "serviceunavailableexception": - return await _deserialize_error_service_unavailable_exception( - http_response, config, parsed_body, message - ) - - case "throttlingexception": - return await _deserialize_error_throttling_exception( - http_response, config, parsed_body, message - ) - - case "validationexception": - return await _deserialize_error_validation_exception( - http_response, config, parsed_body, message - ) - - case _: - return UnknownApiError(f"{code}: {message}") - - -async def _deserialize_error_access_denied_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> AccessDeniedException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = AccessDeniedException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return AccessDeniedException(**kwargs) - - -async def _deserialize_error_conflict_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ConflictException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ConflictException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ConflictException(**kwargs) - - -async def _deserialize_error_internal_server_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> InternalServerException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = InternalServerException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return InternalServerException(**kwargs) - - -async def _deserialize_error_model_error_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ModelErrorException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ModelErrorException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ModelErrorException(**kwargs) - - -async def _deserialize_error_model_not_ready_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ModelNotReadyException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ModelNotReadyException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ModelNotReadyException(**kwargs) - - -async def _deserialize_error_model_stream_error_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ModelStreamErrorException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ModelStreamErrorException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ModelStreamErrorException(**kwargs) - - -async def _deserialize_error_model_timeout_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ModelTimeoutException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ModelTimeoutException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ModelTimeoutException(**kwargs) - - -async def _deserialize_error_resource_not_found_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ResourceNotFoundException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ResourceNotFoundException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ResourceNotFoundException(**kwargs) - - -async def _deserialize_error_service_quota_exceeded_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ServiceQuotaExceededException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ServiceQuotaExceededException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ServiceQuotaExceededException(**kwargs) - - -async def _deserialize_error_service_unavailable_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ServiceUnavailableException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ServiceUnavailableException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ServiceUnavailableException(**kwargs) - - -async def _deserialize_error_throttling_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ThrottlingException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ThrottlingException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ThrottlingException(**kwargs) - - -async def _deserialize_error_validation_exception( - http_response: HTTPResponse, - config: Config, - parsed_body: dict[str, DocumentValue] | None, - default_message: str, -) -> ValidationException: - kwargs: dict[str, Any] = {"message": default_message} - - if parsed_body is None: - body = await http_response.consume_body_async() - else: - body = json.dumps(parsed_body).encode("utf-8") - - if body: - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - deserializer = codec.create_deserializer(body) - body_kwargs = ValidationException.deserialize_kwargs(deserializer) - kwargs.update(body_kwargs) - - return ValidationException(**kwargs) diff --git a/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/serialize.py b/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/serialize.py deleted file mode 100644 index 39742d0..0000000 --- a/clients/aws-sdk-bedrock-runtime/src/aws_sdk_bedrock_runtime/serialize.py +++ /dev/null @@ -1,455 +0,0 @@ -# Code generated by smithy-python-codegen DO NOT EDIT. - -from typing import AsyncIterable -from urllib.parse import quote as urlquote - -from smithy_core import URI as _URI -from smithy_core.aio.types import ( - AsyncBytesProvider, - AsyncBytesReader, - SeekableAsyncBytesReader, -) -from smithy_core.types import TimestampFormat -from smithy_core.utils import ensure_utc, serialize_rfc3339 -from smithy_http import Field, Fields -from smithy_http.aio import HTTPRequest as _HTTPRequest -from smithy_http.aio.interfaces import HTTPRequest -from smithy_http.utils import join_query_params -from smithy_json import JSONCodec - -from .config import Config -from .models import ( - ApplyGuardrailInput, - ConverseInput, - ConverseStreamInput, - GetAsyncInvokeInput, - InvokeModelInput, - InvokeModelWithBidirectionalStreamOperationInput, - InvokeModelWithResponseStreamInput, - ListAsyncInvokesInput, - ServiceError, - StartAsyncInvokeInput, -) - - -async def _serialize_apply_guardrail( - input: ApplyGuardrailInput, config: Config -) -> HTTPRequest: - if not input.guardrail_identifier: - raise ServiceError("guardrail_identifier must not be empty.") - - if not input.guardrail_version: - raise ServiceError("guardrail_version must not be empty.") - - path = "/guardrail/{guardrail_identifier}/version/{guardrail_version}/apply".format( - guardrail_identifier=urlquote(input.guardrail_identifier, safe=""), - guardrail_version=urlquote(input.guardrail_version, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - content = codec.serialize(input) - if not content: - content = b"{}" - content_length = len(content) - body = SeekableAsyncBytesReader(content) - - headers = Fields( - [ - Field(name="Content-Type", values=["application/json"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_converse(input: ConverseInput, config: Config) -> HTTPRequest: - if not input.model_id: - raise ServiceError("model_id must not be empty.") - - path = "/model/{model_id}/converse".format( - model_id=urlquote(input.model_id, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - content = codec.serialize(input) - if not content: - content = b"{}" - content_length = len(content) - body = SeekableAsyncBytesReader(content) - - headers = Fields( - [ - Field(name="Content-Type", values=["application/json"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_converse_stream( - input: ConverseStreamInput, config: Config -) -> HTTPRequest: - if not input.model_id: - raise ServiceError("model_id must not be empty.") - - path = "/model/{model_id}/converse-stream".format( - model_id=urlquote(input.model_id, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - content = codec.serialize(input) - if not content: - content = b"{}" - content_length = len(content) - body = SeekableAsyncBytesReader(content) - - headers = Fields( - [ - Field(name="Content-Type", values=["application/json"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_get_async_invoke( - input: GetAsyncInvokeInput, config: Config -) -> HTTPRequest: - if not input.invocation_arn: - raise ServiceError("invocation_arn must not be empty.") - - path = "/async-invoke/{invocation_arn}".format( - invocation_arn=urlquote(input.invocation_arn, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - headers = Fields([]) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="GET", - fields=headers, - body=body, - ) - - -async def _serialize_invoke_model( - input: InvokeModelInput, config: Config -) -> HTTPRequest: - if not input.model_id: - raise ServiceError("model_id must not be empty.") - - path = "/model/{model_id}/invoke".format( - model_id=urlquote(input.model_id, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - content_length: int = 0 - if input.body is not None: - content_length = len(input.body) - body = SeekableAsyncBytesReader(input.body) - headers = Fields( - [ - Field(name="Content-Type", values=["application/octet-stream"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - if input.content_type: - headers.extend( - Fields([Field(name="Content-Type", values=[input.content_type])]) - ) - if input.accept: - headers.extend(Fields([Field(name="Accept", values=[input.accept])])) - if input.trace: - headers.extend( - Fields([Field(name="X-Amzn-Bedrock-Trace", values=[input.trace])]) - ) - if input.guardrail_identifier: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-GuardrailIdentifier", - values=[input.guardrail_identifier], - ) - ] - ) - ) - if input.guardrail_version: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-GuardrailVersion", - values=[input.guardrail_version], - ) - ] - ) - ) - if input.performance_config_latency: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-PerformanceConfig-Latency", - values=[input.performance_config_latency], - ) - ] - ) - ) - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_invoke_model_with_bidirectional_stream( - input: InvokeModelWithBidirectionalStreamOperationInput, config: Config -) -> HTTPRequest: - if not input.model_id: - raise ServiceError("model_id must not be empty.") - - path = "/model/{model_id}/invoke-with-bidirectional-stream".format( - model_id=urlquote(input.model_id, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - body = AsyncBytesProvider() - headers = Fields( - [ - Field(name="Content-Type", values=["application/vnd.amazon.eventstream"]), - Field( - name="X-Amz-Content-SHA256", - values=["STREAMING-AWS4-HMAC-SHA256-EVENTS"], - ), - ] - ) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_invoke_model_with_response_stream( - input: InvokeModelWithResponseStreamInput, config: Config -) -> HTTPRequest: - if not input.model_id: - raise ServiceError("model_id must not be empty.") - - path = "/model/{model_id}/invoke-with-response-stream".format( - model_id=urlquote(input.model_id, safe=""), - ) - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - content_length: int = 0 - if input.body is not None: - content_length = len(input.body) - body = SeekableAsyncBytesReader(input.body) - headers = Fields( - [ - Field(name="Content-Type", values=["application/octet-stream"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - if input.content_type: - headers.extend( - Fields([Field(name="Content-Type", values=[input.content_type])]) - ) - if input.accept: - headers.extend( - Fields([Field(name="X-Amzn-Bedrock-Accept", values=[input.accept])]) - ) - if input.trace: - headers.extend( - Fields([Field(name="X-Amzn-Bedrock-Trace", values=[input.trace])]) - ) - if input.guardrail_identifier: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-GuardrailIdentifier", - values=[input.guardrail_identifier], - ) - ] - ) - ) - if input.guardrail_version: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-GuardrailVersion", - values=[input.guardrail_version], - ) - ] - ) - ) - if input.performance_config_latency: - headers.extend( - Fields( - [ - Field( - name="X-Amzn-Bedrock-PerformanceConfig-Latency", - values=[input.performance_config_latency], - ) - ] - ) - ) - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - ) - - -async def _serialize_list_async_invokes( - input: ListAsyncInvokesInput, config: Config -) -> HTTPRequest: - path = "/async-invoke" - query: str = "" - - query_params: list[tuple[str, str | None]] = [] - if input.submit_time_after is not None: - query_params.append( - ("submitTimeAfter", serialize_rfc3339(ensure_utc(input.submit_time_after))) - ) - if input.submit_time_before is not None: - query_params.append( - ( - "submitTimeBefore", - serialize_rfc3339(ensure_utc(input.submit_time_before)), - ) - ) - if input.status_equals is not None: - query_params.append(("statusEquals", input.status_equals)) - if input.max_results is not None: - query_params.append(("maxResults", str(input.max_results))) - if input.next_token is not None: - query_params.append(("nextToken", input.next_token)) - if input.sort_by is not None: - query_params.append(("sortBy", input.sort_by)) - if input.sort_order is not None: - query_params.append(("sortOrder", input.sort_order)) - - query = join_query_params(params=query_params, prefix=query) - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - headers = Fields([]) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="GET", - fields=headers, - body=body, - ) - - -async def _serialize_start_async_invoke( - input: StartAsyncInvokeInput, config: Config -) -> HTTPRequest: - path = "/async-invoke" - query: str = "" - - body: AsyncIterable[bytes] = AsyncBytesReader(b"") - codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS) - content = codec.serialize(input) - if not content: - content = b"{}" - content_length = len(content) - body = SeekableAsyncBytesReader(content) - - headers = Fields( - [ - Field(name="Content-Type", values=["application/json"]), - Field(name="Content-Length", values=[str(content_length)]), - ] - ) - - return _HTTPRequest( - destination=_URI( - host="", - path=path, - scheme="https", - query=query, - ), - method="POST", - fields=headers, - body=body, - )