142 146 | ::std::borrow::Cow::Owned(rcb)
|
143 147 | }
|
144 148 | }
|
145 149 |
|
146 150 | #[derive(Debug)]
|
147 151 | struct InvokeModelResponseDeserializer;
|
148 152 | impl ::aws_smithy_runtime_api::client::ser_de::DeserializeResponse for InvokeModelResponseDeserializer {
|
149 153 | fn deserialize_nonstreaming(
|
150 154 | &self,
|
151 155 | response: &::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
|
156 + | _cfg: &::aws_smithy_types::config_bag::ConfigBag,
|
152 157 | ) -> ::aws_smithy_runtime_api::client::interceptors::context::OutputOrError {
|
153 158 | let (success, status) = (response.status().is_success(), response.status().as_u16());
|
154 - | let headers = response.headers();
|
155 - | let body = response.body().bytes().expect("body loaded");
|
156 159 | #[allow(unused_mut)]
|
157 160 | let mut force_error = false;
|
158 161 | ::tracing::debug!(request_id = ?::aws_types::request_id::RequestId::request_id(response));
|
159 - | let parse_result = if !success && status != 200 || force_error {
|
160 - | crate::protocol_serde::shape_invoke_model::de_invoke_model_http_error(status, headers, body)
|
161 - | } else {
|
162 - | crate::protocol_serde::shape_invoke_model::de_invoke_model_http_response(status, headers, body)
|
162 + | if !success && status != 200 || force_error {
|
163 + | let headers = response.headers();
|
164 + | let body = response.body().bytes().expect("body loaded");
|
165 + | #[allow(unused_mut)]
|
166 + | let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(status, headers, body).map_err(|e| {
|
167 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
168 + | })?;
|
169 + | generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, headers);
|
170 + | let generic = generic_builder.build();
|
171 + | let error_code = match generic.code() {
|
172 + | ::std::option::Option::Some(code) => code,
|
173 + | ::std::option::Option::None => {
|
174 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
175 + | ::aws_smithy_runtime_api::box_error::BoxError::from(crate::operation::invoke_model::InvokeModelError::unhandled(generic)),
|
176 + | ))
|
177 + | }
|
178 + | };
|
179 + | let _error_message = generic.message().map(|msg| msg.to_owned());
|
180 + | let protocol = _cfg
|
181 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
182 + | .expect("a SharedClientProtocol is required");
|
183 + | let err = match error_code {
|
184 + | "AccessDeniedException" => crate::operation::invoke_model::InvokeModelError::AccessDeniedException({
|
185 + | let mut tmp = match protocol
|
186 + | .deserialize_response(response, crate::types::error::AccessDeniedException::SCHEMA, _cfg)
|
187 + | .and_then(|mut deser| {
|
188 + | crate::types::error::AccessDeniedException::deserialize_with_response(
|
189 + | &mut *deser,
|
190 + | response.headers(),
|
191 + | response.status().into(),
|
192 + | body,
|
193 + | )
|
194 + | }) {
|
195 + | ::std::result::Result::Ok(val) => val,
|
196 + | ::std::result::Result::Err(e) => {
|
197 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
198 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
199 + | ))
|
200 + | }
|
201 + | };
|
202 + | tmp.meta = generic;
|
203 + | if tmp.message.is_none() {
|
204 + | tmp.message = _error_message;
|
205 + | }
|
206 + | tmp
|
207 + | }),
|
208 + | "InternalServerException" => crate::operation::invoke_model::InvokeModelError::InternalServerException({
|
209 + | let mut tmp = match protocol
|
210 + | .deserialize_response(response, crate::types::error::InternalServerException::SCHEMA, _cfg)
|
211 + | .and_then(|mut deser| {
|
212 + | crate::types::error::InternalServerException::deserialize_with_response(
|
213 + | &mut *deser,
|
214 + | response.headers(),
|
215 + | response.status().into(),
|
216 + | body,
|
217 + | )
|
218 + | }) {
|
219 + | ::std::result::Result::Ok(val) => val,
|
220 + | ::std::result::Result::Err(e) => {
|
221 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
222 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
223 + | ))
|
224 + | }
|
225 + | };
|
226 + | tmp.meta = generic;
|
227 + | if tmp.message.is_none() {
|
228 + | tmp.message = _error_message;
|
229 + | }
|
230 + | tmp
|
231 + | }),
|
232 + | "ModelErrorException" => crate::operation::invoke_model::InvokeModelError::ModelErrorException({
|
233 + | let mut tmp = match protocol
|
234 + | .deserialize_response(response, crate::types::error::ModelErrorException::SCHEMA, _cfg)
|
235 + | .and_then(|mut deser| {
|
236 + | crate::types::error::ModelErrorException::deserialize_with_response(
|
237 + | &mut *deser,
|
238 + | response.headers(),
|
239 + | response.status().into(),
|
240 + | body,
|
241 + | )
|
242 + | }) {
|
243 + | ::std::result::Result::Ok(val) => val,
|
244 + | ::std::result::Result::Err(e) => {
|
245 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
246 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
247 + | ))
|
248 + | }
|
249 + | };
|
250 + | tmp.meta = generic;
|
251 + | if tmp.message.is_none() {
|
252 + | tmp.message = _error_message;
|
253 + | }
|
254 + | tmp
|
255 + | }),
|
256 + | "ModelNotReadyException" => crate::operation::invoke_model::InvokeModelError::ModelNotReadyException({
|
257 + | let mut tmp = match protocol
|
258 + | .deserialize_response(response, crate::types::error::ModelNotReadyException::SCHEMA, _cfg)
|
259 + | .and_then(|mut deser| {
|
260 + | crate::types::error::ModelNotReadyException::deserialize_with_response(
|
261 + | &mut *deser,
|
262 + | response.headers(),
|
263 + | response.status().into(),
|
264 + | body,
|
265 + | )
|
266 + | }) {
|
267 + | ::std::result::Result::Ok(val) => val,
|
268 + | ::std::result::Result::Err(e) => {
|
269 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
270 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
271 + | ))
|
272 + | }
|
273 + | };
|
274 + | tmp.meta = generic;
|
275 + | if tmp.message.is_none() {
|
276 + | tmp.message = _error_message;
|
277 + | }
|
278 + | tmp
|
279 + | }),
|
280 + | "ModelTimeoutException" => crate::operation::invoke_model::InvokeModelError::ModelTimeoutException({
|
281 + | let mut tmp = match protocol
|
282 + | .deserialize_response(response, crate::types::error::ModelTimeoutException::SCHEMA, _cfg)
|
283 + | .and_then(|mut deser| {
|
284 + | crate::types::error::ModelTimeoutException::deserialize_with_response(
|
285 + | &mut *deser,
|
286 + | response.headers(),
|
287 + | response.status().into(),
|
288 + | body,
|
289 + | )
|
290 + | }) {
|
291 + | ::std::result::Result::Ok(val) => val,
|
292 + | ::std::result::Result::Err(e) => {
|
293 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
294 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
295 + | ))
|
296 + | }
|
297 + | };
|
298 + | tmp.meta = generic;
|
299 + | if tmp.message.is_none() {
|
300 + | tmp.message = _error_message;
|
301 + | }
|
302 + | tmp
|
303 + | }),
|
304 + | "ResourceNotFoundException" => crate::operation::invoke_model::InvokeModelError::ResourceNotFoundException({
|
305 + | let mut tmp = match protocol
|
306 + | .deserialize_response(response, crate::types::error::ResourceNotFoundException::SCHEMA, _cfg)
|
307 + | .and_then(|mut deser| {
|
308 + | crate::types::error::ResourceNotFoundException::deserialize_with_response(
|
309 + | &mut *deser,
|
310 + | response.headers(),
|
311 + | response.status().into(),
|
312 + | body,
|
313 + | )
|
314 + | }) {
|
315 + | ::std::result::Result::Ok(val) => val,
|
316 + | ::std::result::Result::Err(e) => {
|
317 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
318 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
319 + | ))
|
320 + | }
|
163 321 | };
|
164 - | crate::protocol_serde::type_erase_result(parse_result)
|
322 + | tmp.meta = generic;
|
323 + | if tmp.message.is_none() {
|
324 + | tmp.message = _error_message;
|
325 + | }
|
326 + | tmp
|
327 + | }),
|
328 + | "ServiceQuotaExceededException" => crate::operation::invoke_model::InvokeModelError::ServiceQuotaExceededException({
|
329 + | let mut tmp = match protocol
|
330 + | .deserialize_response(response, crate::types::error::ServiceQuotaExceededException::SCHEMA, _cfg)
|
331 + | .and_then(|mut deser| {
|
332 + | crate::types::error::ServiceQuotaExceededException::deserialize_with_response(
|
333 + | &mut *deser,
|
334 + | response.headers(),
|
335 + | response.status().into(),
|
336 + | body,
|
337 + | )
|
338 + | }) {
|
339 + | ::std::result::Result::Ok(val) => val,
|
340 + | ::std::result::Result::Err(e) => {
|
341 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
342 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
343 + | ))
|
344 + | }
|
345 + | };
|
346 + | tmp.meta = generic;
|
347 + | if tmp.message.is_none() {
|
348 + | tmp.message = _error_message;
|
349 + | }
|
350 + | tmp
|
351 + | }),
|
352 + | "ServiceUnavailableException" => crate::operation::invoke_model::InvokeModelError::ServiceUnavailableException({
|
353 + | let mut tmp = match protocol
|
354 + | .deserialize_response(response, crate::types::error::ServiceUnavailableException::SCHEMA, _cfg)
|
355 + | .and_then(|mut deser| {
|
356 + | crate::types::error::ServiceUnavailableException::deserialize_with_response(
|
357 + | &mut *deser,
|
358 + | response.headers(),
|
359 + | response.status().into(),
|
360 + | body,
|
361 + | )
|
362 + | }) {
|
363 + | ::std::result::Result::Ok(val) => val,
|
364 + | ::std::result::Result::Err(e) => {
|
365 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
366 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
367 + | ))
|
368 + | }
|
369 + | };
|
370 + | tmp.meta = generic;
|
371 + | if tmp.message.is_none() {
|
372 + | tmp.message = _error_message;
|
373 + | }
|
374 + | tmp
|
375 + | }),
|
376 + | "ThrottlingException" => crate::operation::invoke_model::InvokeModelError::ThrottlingException({
|
377 + | let mut tmp = match protocol
|
378 + | .deserialize_response(response, crate::types::error::ThrottlingException::SCHEMA, _cfg)
|
379 + | .and_then(|mut deser| {
|
380 + | crate::types::error::ThrottlingException::deserialize_with_response(
|
381 + | &mut *deser,
|
382 + | response.headers(),
|
383 + | response.status().into(),
|
384 + | body,
|
385 + | )
|
386 + | }) {
|
387 + | ::std::result::Result::Ok(val) => val,
|
388 + | ::std::result::Result::Err(e) => {
|
389 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
390 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
391 + | ))
|
392 + | }
|
393 + | };
|
394 + | tmp.meta = generic;
|
395 + | if tmp.message.is_none() {
|
396 + | tmp.message = _error_message;
|
397 + | }
|
398 + | tmp
|
399 + | }),
|
400 + | "ValidationException" => crate::operation::invoke_model::InvokeModelError::ValidationException({
|
401 + | let mut tmp = match protocol
|
402 + | .deserialize_response(response, crate::types::error::ValidationException::SCHEMA, _cfg)
|
403 + | .and_then(|mut deser| {
|
404 + | crate::types::error::ValidationException::deserialize_with_response(
|
405 + | &mut *deser,
|
406 + | response.headers(),
|
407 + | response.status().into(),
|
408 + | body,
|
409 + | )
|
410 + | }) {
|
411 + | ::std::result::Result::Ok(val) => val,
|
412 + | ::std::result::Result::Err(e) => {
|
413 + | return ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(
|
414 + | ::aws_smithy_runtime_api::box_error::BoxError::from(e),
|
415 + | ))
|
416 + | }
|
417 + | };
|
418 + | tmp.meta = generic;
|
419 + | if tmp.message.is_none() {
|
420 + | tmp.message = _error_message;
|
421 + | }
|
422 + | tmp
|
423 + | }),
|
424 + | _ => crate::operation::invoke_model::InvokeModelError::generic(generic),
|
425 + | };
|
426 + | ::std::result::Result::Err(::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::operation(
|
427 + | ::aws_smithy_runtime_api::client::interceptors::context::Error::erase(err),
|
428 + | ))
|
429 + | } else {
|
430 + | let protocol = _cfg
|
431 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
432 + | .expect("a SharedClientProtocol is required");
|
433 + | let mut deser = protocol.deserialize_response(response, InvokeModel::OUTPUT_SCHEMA, _cfg).map_err(|e| {
|
434 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
435 + | })?;
|
436 + | let body = response.body().bytes().expect("body loaded");
|
437 + | let output = crate::operation::invoke_model::InvokeModelOutput::deserialize_with_response(
|
438 + | &mut *deser,
|
439 + | response.headers(),
|
440 + | response.status().into(),
|
441 + | body,
|
442 + | )
|
443 + | .map_err(|e| {
|
444 + | ::aws_smithy_runtime_api::client::orchestrator::OrchestratorError::other(::aws_smithy_runtime_api::box_error::BoxError::from(e))
|
445 + | })?;
|
446 + | ::std::result::Result::Ok(::aws_smithy_runtime_api::client::interceptors::context::Output::erase(output))
|
447 + | }
|
165 448 | }
|
166 449 | }
|
167 450 | #[derive(Debug)]
|
168 451 | struct InvokeModelRequestSerializer;
|
169 452 | impl ::aws_smithy_runtime_api::client::ser_de::SerializeRequest for InvokeModelRequestSerializer {
|
170 453 | #[allow(unused_mut, clippy::let_and_return, clippy::needless_borrow, clippy::useless_conversion)]
|
171 454 | fn serialize_input(
|
172 455 | &self,
|
173 456 | input: ::aws_smithy_runtime_api::client::interceptors::context::Input,
|
174 457 | _cfg: &mut ::aws_smithy_types::config_bag::ConfigBag,
|
175 458 | ) -> ::std::result::Result<::aws_smithy_runtime_api::client::orchestrator::HttpRequest, ::aws_smithy_runtime_api::box_error::BoxError> {
|
176 459 | let input = input
|
177 460 | .downcast::<crate::operation::invoke_model::InvokeModelInput>()
|
178 461 | .expect("correct type");
|
179 - | let _header_serialization_settings = _cfg
|
180 - | .load::<crate::serialization_settings::HeaderSerializationSettings>()
|
181 - | .cloned()
|
182 - | .unwrap_or_default();
|
183 - | let mut request_builder = {
|
184 - | #[allow(clippy::uninlined_format_args)]
|
185 - | fn uri_base(
|
186 - | _input: &crate::operation::invoke_model::InvokeModelInput,
|
187 - | output: &mut ::std::string::String,
|
188 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::BuildError> {
|
189 - | use ::std::fmt::Write as _;
|
190 - | let input_1 = &_input.model_id;
|
191 - | let input_1 = input_1
|
192 - | .as_ref()
|
193 - | .ok_or_else(|| ::aws_smithy_types::error::operation::BuildError::missing_field("model_id", "cannot be empty or unset"))?;
|
194 - | let model_id = ::aws_smithy_http::label::fmt_string(input_1, ::aws_smithy_http::label::EncodingStrategy::Default);
|
195 - | if model_id.is_empty() {
|
196 - | return ::std::result::Result::Err(::aws_smithy_types::error::operation::BuildError::missing_field(
|
197 - | "model_id",
|
198 - | "cannot be empty or unset",
|
199 - | ));
|
462 + | let protocol = _cfg
|
463 + | .load::<::aws_smithy_schema::protocol::SharedClientProtocol>()
|
464 + | .expect("a SharedClientProtocol is required");
|
465 + | if protocol.supports_http_bindings() {
|
466 + | let mut input = input;
|
467 + | let payload = input.body.take();
|
468 + | let mut request = protocol
|
469 + | .serialize_body(&input, InvokeModel::INPUT_SCHEMA, "", _cfg)
|
470 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
471 + | if let ::std::option::Option::Some(payload) = payload {
|
472 + | *request.body_mut() = ::aws_smithy_types::body::SdkBody::from(payload.into_inner());
|
473 + | request.headers_mut().insert("Content-Type", "application/octet-stream");
|
474 + | if let ::std::option::Option::Some(content_length) = request.body().content_length() {
|
475 + | request.headers_mut().insert("Content-Length", content_length.to_string());
|
476 + | }
|
477 + | }
|
478 + | {
|
479 + | let mut uri = "/model/{modelId}/invoke".to_string();
|
480 + | let mut query_params: Vec<(String, String)> = Vec::new();
|
481 + | if let Some(ref val) = input.content_type {
|
482 + | request.headers_mut().insert("Content-Type", val.to_string());
|
483 + | }
|
484 + | if let Some(ref val) = input.accept {
|
485 + | request.headers_mut().insert("Accept", val.to_string());
|
486 + | }
|
487 + | if let Some(ref val) = input.model_id {
|
488 + | uri = uri.replace("{modelId}", &::aws_smithy_schema::http_protocol::percent_encode(&val.to_string()));
|
489 + | }
|
490 + | if let Some(ref val) = input.trace {
|
491 + | request.headers_mut().insert("X-Amzn-Bedrock-Trace", val.as_str().to_string());
|
492 + | }
|
493 + | if let Some(ref val) = input.guardrail_identifier {
|
494 + | request.headers_mut().insert("X-Amzn-Bedrock-GuardrailIdentifier", val.to_string());
|
495 + | }
|
496 + | if let Some(ref val) = input.guardrail_version {
|
497 + | request.headers_mut().insert("X-Amzn-Bedrock-GuardrailVersion", val.to_string());
|
498 + | }
|
499 + | if let Some(ref val) = input.performance_config_latency {
|
500 + | request
|
501 + | .headers_mut()
|
502 + | .insert("X-Amzn-Bedrock-PerformanceConfig-Latency", val.as_str().to_string());
|
503 + | }
|
504 + | if !query_params.is_empty() {
|
505 + | uri.push(if uri.contains('?') { '&' } else { '?' });
|
506 + | let pairs: Vec<String> = query_params
|
507 + | .iter()
|
508 + | .map(|(k, v)| {
|
509 + | format!(
|
510 + | "{}={}",
|
511 + | ::aws_smithy_schema::http_protocol::percent_encode(k),
|
512 + | ::aws_smithy_schema::http_protocol::percent_encode(v)
|
513 + | )
|
514 + | })
|
515 + | .collect();
|
516 + | uri.push_str(&pairs.join("&"));
|
200 517 | }
|
201 - | ::std::write!(output, "/model/{modelId}/invoke", modelId = model_id).expect("formatting should succeed");
|
202 - | ::std::result::Result::Ok(())
|
518 + | request.set_uri(uri.as_str()).expect("valid URI");
|
203 519 | }
|
204 - | #[allow(clippy::unnecessary_wraps)]
|
205 - | fn update_http_builder(
|
206 - | input: &crate::operation::invoke_model::InvokeModelInput,
|
207 - | builder: ::http_1x::request::Builder,
|
208 - | ) -> ::std::result::Result<::http_1x::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
|
209 - | let mut uri = ::std::string::String::new();
|
210 - | uri_base(input, &mut uri)?;
|
211 - | let builder = crate::protocol_serde::shape_invoke_model::ser_invoke_model_headers(input, builder)?;
|
212 - | ::std::result::Result::Ok(builder.method("POST").uri(uri))
|
213 - | }
|
214 - | let mut builder = update_http_builder(&input, ::http_1x::request::Builder::new())?;
|
215 - | builder = _header_serialization_settings.set_default_header(builder, ::http_1x::header::CONTENT_TYPE, "application/octet-stream");
|
216 - | builder
|
217 - | };
|
218 - | let body = ::aws_smithy_types::body::SdkBody::from(crate::protocol_serde::shape_invoke_model_input::ser_body_http_payload(input.body)?);
|
219 - | if let Some(content_length) = body.content_length() {
|
220 - | let content_length = content_length.to_string();
|
221 - | request_builder = _header_serialization_settings.set_default_header(request_builder, ::http_1x::header::CONTENT_LENGTH, &content_length);
|
520 + |
|
521 + | return ::std::result::Result::Ok(request);
|
522 + | } else {
|
523 + | let mut request = protocol
|
524 + | .serialize_request(&input, InvokeModel::INPUT_SCHEMA, "", _cfg)
|
525 + | .map_err(::aws_smithy_runtime_api::box_error::BoxError::from)?;
|
526 + |
|
527 + | return ::std::result::Result::Ok(request);
|
222 528 | }
|
223 - | ::std::result::Result::Ok(request_builder.body(body).expect("valid request").try_into().unwrap())
|
224 529 | }
|
225 530 | }
|
226 531 | #[derive(Debug)]
|
227 532 | struct InvokeModelEndpointParamsInterceptor;
|
228 533 |
|
229 534 | impl ::aws_smithy_runtime_api::client::interceptors::Intercept for InvokeModelEndpointParamsInterceptor {
|
230 535 | fn name(&self) -> &'static str {
|
231 536 | "InvokeModelEndpointParamsInterceptor"
|
232 537 | }
|
233 538 |
|