aws_sdk_bedrockagentruntime/operation/optimize_prompt/
builders.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::optimize_prompt::_optimize_prompt_output::OptimizePromptOutputBuilder;
3
4pub use crate::operation::optimize_prompt::_optimize_prompt_input::OptimizePromptInputBuilder;
5
6impl crate::operation::optimize_prompt::builders::OptimizePromptInputBuilder {
7    /// Sends a request with this input using the given client.
8    pub async fn send_with(
9        self,
10        client: &crate::Client,
11    ) -> ::std::result::Result<
12        crate::operation::optimize_prompt::OptimizePromptOutput,
13        ::aws_smithy_runtime_api::client::result::SdkError<
14            crate::operation::optimize_prompt::OptimizePromptError,
15            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16        >,
17    > {
18        let mut fluent_builder = client.optimize_prompt();
19        fluent_builder.inner = self;
20        fluent_builder.send().await
21    }
22}
23/// Fluent builder constructing a request to `OptimizePrompt`.
24///
25/// <p>Optimizes a prompt for the task that you specify. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-management-optimize.html">Optimize a prompt</a> in the <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-service.html">Amazon Bedrock User Guide</a>.</p>
26#[derive(::std::clone::Clone, ::std::fmt::Debug)]
27pub struct OptimizePromptFluentBuilder {
28    handle: ::std::sync::Arc<crate::client::Handle>,
29    inner: crate::operation::optimize_prompt::builders::OptimizePromptInputBuilder,
30    config_override: ::std::option::Option<crate::config::Builder>,
31}
32impl
33    crate::client::customize::internal::CustomizableSend<
34        crate::operation::optimize_prompt::OptimizePromptOutput,
35        crate::operation::optimize_prompt::OptimizePromptError,
36    > for OptimizePromptFluentBuilder
37{
38    fn send(
39        self,
40        config_override: crate::config::Builder,
41    ) -> crate::client::customize::internal::BoxFuture<
42        crate::client::customize::internal::SendResult<
43            crate::operation::optimize_prompt::OptimizePromptOutput,
44            crate::operation::optimize_prompt::OptimizePromptError,
45        >,
46    > {
47        ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
48    }
49}
50impl OptimizePromptFluentBuilder {
51    /// Creates a new `OptimizePromptFluentBuilder`.
52    pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
53        Self {
54            handle,
55            inner: ::std::default::Default::default(),
56            config_override: ::std::option::Option::None,
57        }
58    }
59    /// Access the OptimizePrompt as a reference.
60    pub fn as_input(&self) -> &crate::operation::optimize_prompt::builders::OptimizePromptInputBuilder {
61        &self.inner
62    }
63    /// Sends the request and returns the response.
64    ///
65    /// If an error occurs, an `SdkError` will be returned with additional details that
66    /// can be matched against.
67    ///
68    /// By default, any retryable failures will be retried twice. Retry behavior
69    /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
70    /// set when configuring the client.
71    pub async fn send(
72        self,
73    ) -> ::std::result::Result<
74        crate::operation::optimize_prompt::OptimizePromptOutput,
75        ::aws_smithy_runtime_api::client::result::SdkError<
76            crate::operation::optimize_prompt::OptimizePromptError,
77            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
78        >,
79    > {
80        let input = self
81            .inner
82            .build()
83            .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
84        let runtime_plugins = crate::operation::optimize_prompt::OptimizePrompt::operation_runtime_plugins(
85            self.handle.runtime_plugins.clone(),
86            &self.handle.conf,
87            self.config_override,
88        );
89        let mut output = crate::operation::optimize_prompt::OptimizePrompt::orchestrate(&runtime_plugins, input).await?;
90
91        // Converts any error encountered beyond this point into an `SdkError` response error
92        // with an `HttpResponse`. However, since we have already exited the `orchestrate`
93        // function, the original `HttpResponse` is no longer available and cannot be restored.
94        // This means that header information from the original response has been lost.
95        //
96        // Note that the response body would have been consumed by the deserializer
97        // regardless, even if the initial message was hypothetically processed during
98        // the orchestrator's deserialization phase but later resulted in an error.
99        fn response_error(
100            err: impl ::std::convert::Into<::aws_smithy_runtime_api::box_error::BoxError>,
101        ) -> ::aws_smithy_runtime_api::client::result::SdkError<
102            crate::operation::optimize_prompt::OptimizePromptError,
103            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
104        > {
105            ::aws_smithy_runtime_api::client::result::SdkError::response_error(
106                err,
107                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse::new(
108                    ::aws_smithy_runtime_api::http::StatusCode::try_from(200).expect("valid successful code"),
109                    ::aws_smithy_types::body::SdkBody::empty(),
110                ),
111            )
112        }
113
114        let message = output.optimized_prompt.try_recv_initial_response().await.map_err(response_error)?;
115
116        match message {
117            ::std::option::Option::Some(_message) => ::std::result::Result::Ok(output),
118            ::std::option::Option::None => ::std::result::Result::Ok(output),
119        }
120    }
121
122    /// Consumes this builder, creating a customizable operation that can be modified before being sent.
123    pub fn customize(
124        self,
125    ) -> crate::client::customize::CustomizableOperation<
126        crate::operation::optimize_prompt::OptimizePromptOutput,
127        crate::operation::optimize_prompt::OptimizePromptError,
128        Self,
129    > {
130        crate::client::customize::CustomizableOperation::new(self)
131    }
132    pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
133        self.set_config_override(::std::option::Option::Some(config_override.into()));
134        self
135    }
136
137    pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
138        self.config_override = config_override;
139        self
140    }
141    /// <p>Contains the prompt to optimize.</p>
142    pub fn input(mut self, input: crate::types::InputPrompt) -> Self {
143        self.inner = self.inner.input(input);
144        self
145    }
146    /// <p>Contains the prompt to optimize.</p>
147    pub fn set_input(mut self, input: ::std::option::Option<crate::types::InputPrompt>) -> Self {
148        self.inner = self.inner.set_input(input);
149        self
150    }
151    /// <p>Contains the prompt to optimize.</p>
152    pub fn get_input(&self) -> &::std::option::Option<crate::types::InputPrompt> {
153        self.inner.get_input()
154    }
155    /// <p>The unique identifier of the model that you want to optimize the prompt for.</p>
156    pub fn target_model_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
157        self.inner = self.inner.target_model_id(input.into());
158        self
159    }
160    /// <p>The unique identifier of the model that you want to optimize the prompt for.</p>
161    pub fn set_target_model_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
162        self.inner = self.inner.set_target_model_id(input);
163        self
164    }
165    /// <p>The unique identifier of the model that you want to optimize the prompt for.</p>
166    pub fn get_target_model_id(&self) -> &::std::option::Option<::std::string::String> {
167        self.inner.get_target_model_id()
168    }
169}