aws_sdk_sagemakerruntimehttp2/operation/invoke_endpoint_with_bidirectional_stream/
builders.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::invoke_endpoint_with_bidirectional_stream::_invoke_endpoint_with_bidirectional_stream_output::InvokeEndpointWithBidirectionalStreamOutputBuilder;
3
4pub use crate::operation::invoke_endpoint_with_bidirectional_stream::_invoke_endpoint_with_bidirectional_stream_input::InvokeEndpointWithBidirectionalStreamInputBuilder;
5
6impl crate::operation::invoke_endpoint_with_bidirectional_stream::builders::InvokeEndpointWithBidirectionalStreamInputBuilder {
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::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamOutput,
13        ::aws_smithy_runtime_api::client::result::SdkError<
14            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
15            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16        >,
17    > {
18        let mut fluent_builder = client.invoke_endpoint_with_bidirectional_stream();
19        fluent_builder.inner = self;
20        fluent_builder.send().await
21    }
22}
23/// Fluent builder constructing a request to `InvokeEndpointWithBidirectionalStream`.
24///
25/// <p>Invokes a model endpoint with bidirectional streaming capabilities. This operation establishes a persistent connection that allows you to send multiple requests and receive streaming responses from the model in real-time.</p>
26/// <p>Bidirectional streaming is useful for interactive applications such as chatbots, real-time translation, or any scenario where you need to maintain a conversation-like interaction with the model. The connection remains open, allowing you to send additional input and receive responses without establishing a new connection for each request.</p>
27/// <p>For an overview of Amazon SageMaker AI, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/how-it-works.html">How It Works</a>.</p>
28/// <p>Amazon SageMaker AI strips all POST headers except those supported by the API. Amazon SageMaker AI might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.</p>
29/// <p>Calls to <code>InvokeEndpointWithBidirectionalStream</code> are authenticated by using Amazon Web Services Signature Version 4. For information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html">Authenticating Requests (Amazon Web Services Signature Version 4)</a> in the <i>Amazon S3 API Reference</i>.</p>
30/// <p>The bidirectional stream maintains the connection until either the client closes it or the model indicates completion. Each request and response in the stream is sent as an event with optional headers for data type and completion state.</p><note>
31/// <p>Endpoints are scoped to an individual account, and are not public. The URL does not contain the account ID, but Amazon SageMaker AI determines the account ID from the authentication token that is supplied by the caller.</p>
32/// </note>
33#[derive(::std::fmt::Debug)]
34pub struct InvokeEndpointWithBidirectionalStreamFluentBuilder {
35    handle: ::std::sync::Arc<crate::client::Handle>,
36    inner: crate::operation::invoke_endpoint_with_bidirectional_stream::builders::InvokeEndpointWithBidirectionalStreamInputBuilder,
37    config_override: ::std::option::Option<crate::config::Builder>,
38}
39impl
40    crate::client::customize::internal::CustomizableSend<
41        crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamOutput,
42        crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
43    > for InvokeEndpointWithBidirectionalStreamFluentBuilder
44{
45    fn send(
46        self,
47        config_override: crate::config::Builder,
48    ) -> crate::client::customize::internal::BoxFuture<
49        crate::client::customize::internal::SendResult<
50            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamOutput,
51            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
52        >,
53    > {
54        ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
55    }
56}
57impl InvokeEndpointWithBidirectionalStreamFluentBuilder {
58    /// Creates a new `InvokeEndpointWithBidirectionalStreamFluentBuilder`.
59    pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
60        Self {
61            handle,
62            inner: ::std::default::Default::default(),
63            config_override: ::std::option::Option::None,
64        }
65    }
66    /// Access the InvokeEndpointWithBidirectionalStream as a reference.
67    pub fn as_input(
68        &self,
69    ) -> &crate::operation::invoke_endpoint_with_bidirectional_stream::builders::InvokeEndpointWithBidirectionalStreamInputBuilder {
70        &self.inner
71    }
72    /// Sends the request and returns the response.
73    ///
74    /// If an error occurs, an `SdkError` will be returned with additional details that
75    /// can be matched against.
76    ///
77    /// By default, any retryable failures will be retried twice. Retry behavior
78    /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
79    /// set when configuring the client.
80    pub async fn send(
81        self,
82    ) -> ::std::result::Result<
83        crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamOutput,
84        ::aws_smithy_runtime_api::client::result::SdkError<
85            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
86            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
87        >,
88    > {
89        let input = self
90            .inner
91            .build()
92            .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
93        let runtime_plugins =
94            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStream::operation_runtime_plugins(
95                self.handle.runtime_plugins.clone(),
96                &self.handle.conf,
97                self.config_override,
98            );
99        let mut output =
100            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStream::orchestrate(&runtime_plugins, input)
101                .await?;
102
103        // Converts any error encountered beyond this point into an `SdkError` response error
104        // with an `HttpResponse`. However, since we have already exited the `orchestrate`
105        // function, the original `HttpResponse` is no longer available and cannot be restored.
106        // This means that header information from the original response has been lost.
107        //
108        // Note that the response body would have been consumed by the deserializer
109        // regardless, even if the initial message was hypothetically processed during
110        // the orchestrator's deserialization phase but later resulted in an error.
111        fn response_error(
112            err: impl ::std::convert::Into<::aws_smithy_runtime_api::box_error::BoxError>,
113        ) -> ::aws_smithy_runtime_api::client::result::SdkError<
114            crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
115            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
116        > {
117            ::aws_smithy_runtime_api::client::result::SdkError::response_error(
118                err,
119                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse::new(
120                    ::aws_smithy_runtime_api::http::StatusCode::try_from(200).expect("valid successful code"),
121                    ::aws_smithy_types::body::SdkBody::empty(),
122                ),
123            )
124        }
125
126        let message = output.body.try_recv_initial_response().await.map_err(response_error)?;
127
128        match message {
129            ::std::option::Option::Some(_message) => ::std::result::Result::Ok(output),
130            ::std::option::Option::None => ::std::result::Result::Ok(output),
131        }
132    }
133
134    /// Consumes this builder, creating a customizable operation that can be modified before being sent.
135    pub fn customize(
136        self,
137    ) -> crate::client::customize::CustomizableOperation<
138        crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamOutput,
139        crate::operation::invoke_endpoint_with_bidirectional_stream::InvokeEndpointWithBidirectionalStreamError,
140        Self,
141    > {
142        crate::client::customize::CustomizableOperation::new(self)
143    }
144    pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
145        self.set_config_override(::std::option::Option::Some(config_override.into()));
146        self
147    }
148
149    pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
150        self.config_override = config_override;
151        self
152    }
153    /// <p>The name of the endpoint to invoke.</p>
154    pub fn endpoint_name(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
155        self.inner = self.inner.endpoint_name(input.into());
156        self
157    }
158    /// <p>The name of the endpoint to invoke.</p>
159    pub fn set_endpoint_name(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
160        self.inner = self.inner.set_endpoint_name(input);
161        self
162    }
163    /// <p>The name of the endpoint to invoke.</p>
164    pub fn get_endpoint_name(&self) -> &::std::option::Option<::std::string::String> {
165        self.inner.get_endpoint_name()
166    }
167    /// <p>The request payload stream.</p>
168    pub fn body(
169        mut self,
170        input: ::aws_smithy_http::event_stream::EventStreamSender<crate::types::RequestStreamEvent, crate::types::error::RequestStreamEventError>,
171    ) -> Self {
172        self.inner = self.inner.body(input);
173        self
174    }
175    /// <p>The request payload stream.</p>
176    pub fn set_body(
177        mut self,
178        input: ::std::option::Option<
179            ::aws_smithy_http::event_stream::EventStreamSender<crate::types::RequestStreamEvent, crate::types::error::RequestStreamEventError>,
180        >,
181    ) -> Self {
182        self.inner = self.inner.set_body(input);
183        self
184    }
185    /// <p>The request payload stream.</p>
186    pub fn get_body(
187        &self,
188    ) -> &::std::option::Option<
189        ::aws_smithy_http::event_stream::EventStreamSender<crate::types::RequestStreamEvent, crate::types::error::RequestStreamEventError>,
190    > {
191        self.inner.get_body()
192    }
193    /// <p>Target variant for the request.</p>
194    pub fn target_variant(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
195        self.inner = self.inner.target_variant(input.into());
196        self
197    }
198    /// <p>Target variant for the request.</p>
199    pub fn set_target_variant(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
200        self.inner = self.inner.set_target_variant(input);
201        self
202    }
203    /// <p>Target variant for the request.</p>
204    pub fn get_target_variant(&self) -> &::std::option::Option<::std::string::String> {
205        self.inner.get_target_variant()
206    }
207    /// <p>Model invocation path.</p>
208    pub fn model_invocation_path(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
209        self.inner = self.inner.model_invocation_path(input.into());
210        self
211    }
212    /// <p>Model invocation path.</p>
213    pub fn set_model_invocation_path(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
214        self.inner = self.inner.set_model_invocation_path(input);
215        self
216    }
217    /// <p>Model invocation path.</p>
218    pub fn get_model_invocation_path(&self) -> &::std::option::Option<::std::string::String> {
219        self.inner.get_model_invocation_path()
220    }
221    /// <p>Model query string.</p>
222    pub fn model_query_string(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
223        self.inner = self.inner.model_query_string(input.into());
224        self
225    }
226    /// <p>Model query string.</p>
227    pub fn set_model_query_string(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
228        self.inner = self.inner.set_model_query_string(input);
229        self
230    }
231    /// <p>Model query string.</p>
232    pub fn get_model_query_string(&self) -> &::std::option::Option<::std::string::String> {
233        self.inner.get_model_query_string()
234    }
235}