aws_sdk_bedrockagentruntime/operation/retrieve_and_generate_stream/
builders.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::retrieve_and_generate_stream::_retrieve_and_generate_stream_output::RetrieveAndGenerateStreamOutputBuilder;
3
4pub use crate::operation::retrieve_and_generate_stream::_retrieve_and_generate_stream_input::RetrieveAndGenerateStreamInputBuilder;
5
6impl crate::operation::retrieve_and_generate_stream::builders::RetrieveAndGenerateStreamInputBuilder {
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::retrieve_and_generate_stream::RetrieveAndGenerateStreamOutput,
13        ::aws_smithy_runtime_api::client::result::SdkError<
14            crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
15            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16        >,
17    > {
18        let mut fluent_builder = client.retrieve_and_generate_stream();
19        fluent_builder.inner = self;
20        fluent_builder.send().await
21    }
22}
23/// Fluent builder constructing a request to `RetrieveAndGenerateStream`.
24///
25/// <p>Queries a knowledge base and generates responses based on the retrieved results, with output in streaming format.</p><note>
26/// <p>The CLI doesn't support streaming operations in Amazon Bedrock, including <code>InvokeModelWithResponseStream</code>.</p>
27/// </note>
28/// <p>This operation requires permission for the <code> bedrock:RetrieveAndGenerate</code> action.</p>
29#[derive(::std::clone::Clone, ::std::fmt::Debug)]
30pub struct RetrieveAndGenerateStreamFluentBuilder {
31    handle: ::std::sync::Arc<crate::client::Handle>,
32    inner: crate::operation::retrieve_and_generate_stream::builders::RetrieveAndGenerateStreamInputBuilder,
33    config_override: ::std::option::Option<crate::config::Builder>,
34}
35impl
36    crate::client::customize::internal::CustomizableSend<
37        crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamOutput,
38        crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
39    > for RetrieveAndGenerateStreamFluentBuilder
40{
41    fn send(
42        self,
43        config_override: crate::config::Builder,
44    ) -> crate::client::customize::internal::BoxFuture<
45        crate::client::customize::internal::SendResult<
46            crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamOutput,
47            crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
48        >,
49    > {
50        ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
51    }
52}
53impl RetrieveAndGenerateStreamFluentBuilder {
54    /// Creates a new `RetrieveAndGenerateStreamFluentBuilder`.
55    pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
56        Self {
57            handle,
58            inner: ::std::default::Default::default(),
59            config_override: ::std::option::Option::None,
60        }
61    }
62    /// Access the RetrieveAndGenerateStream as a reference.
63    pub fn as_input(&self) -> &crate::operation::retrieve_and_generate_stream::builders::RetrieveAndGenerateStreamInputBuilder {
64        &self.inner
65    }
66    /// Sends the request and returns the response.
67    ///
68    /// If an error occurs, an `SdkError` will be returned with additional details that
69    /// can be matched against.
70    ///
71    /// By default, any retryable failures will be retried twice. Retry behavior
72    /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
73    /// set when configuring the client.
74    pub async fn send(
75        self,
76    ) -> ::std::result::Result<
77        crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamOutput,
78        ::aws_smithy_runtime_api::client::result::SdkError<
79            crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
80            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
81        >,
82    > {
83        let input = self
84            .inner
85            .build()
86            .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
87        let runtime_plugins = crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStream::operation_runtime_plugins(
88            self.handle.runtime_plugins.clone(),
89            &self.handle.conf,
90            self.config_override,
91        );
92        let mut output = crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStream::orchestrate(&runtime_plugins, input).await?;
93
94        // Converts any error encountered beyond this point into an `SdkError` response error
95        // with an `HttpResponse`. However, since we have already exited the `orchestrate`
96        // function, the original `HttpResponse` is no longer available and cannot be restored.
97        // This means that header information from the original response has been lost.
98        //
99        // Note that the response body would have been consumed by the deserializer
100        // regardless, even if the initial message was hypothetically processed during
101        // the orchestrator's deserialization phase but later resulted in an error.
102        fn response_error(
103            err: impl ::std::convert::Into<::aws_smithy_runtime_api::box_error::BoxError>,
104        ) -> ::aws_smithy_runtime_api::client::result::SdkError<
105            crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
106            ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
107        > {
108            ::aws_smithy_runtime_api::client::result::SdkError::response_error(
109                err,
110                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse::new(
111                    ::aws_smithy_runtime_api::http::StatusCode::try_from(200).expect("valid successful code"),
112                    ::aws_smithy_types::body::SdkBody::empty(),
113                ),
114            )
115        }
116
117        let message = output.stream.try_recv_initial_response().await.map_err(response_error)?;
118
119        match message {
120            ::std::option::Option::Some(_message) => ::std::result::Result::Ok(output),
121            ::std::option::Option::None => ::std::result::Result::Ok(output),
122        }
123    }
124
125    /// Consumes this builder, creating a customizable operation that can be modified before being sent.
126    pub fn customize(
127        self,
128    ) -> crate::client::customize::CustomizableOperation<
129        crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamOutput,
130        crate::operation::retrieve_and_generate_stream::RetrieveAndGenerateStreamError,
131        Self,
132    > {
133        crate::client::customize::CustomizableOperation::new(self)
134    }
135    pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
136        self.set_config_override(::std::option::Option::Some(config_override.into()));
137        self
138    }
139
140    pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
141        self.config_override = config_override;
142        self
143    }
144    /// <p>The unique identifier of the session. When you first make a <code>RetrieveAndGenerate</code> request, Amazon Bedrock automatically generates this value. You must reuse this value for all subsequent requests in the same conversational session. This value allows Amazon Bedrock to maintain context and knowledge from previous interactions. You can't explicitly set the <code>sessionId</code> yourself.</p>
145    pub fn session_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
146        self.inner = self.inner.session_id(input.into());
147        self
148    }
149    /// <p>The unique identifier of the session. When you first make a <code>RetrieveAndGenerate</code> request, Amazon Bedrock automatically generates this value. You must reuse this value for all subsequent requests in the same conversational session. This value allows Amazon Bedrock to maintain context and knowledge from previous interactions. You can't explicitly set the <code>sessionId</code> yourself.</p>
150    pub fn set_session_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
151        self.inner = self.inner.set_session_id(input);
152        self
153    }
154    /// <p>The unique identifier of the session. When you first make a <code>RetrieveAndGenerate</code> request, Amazon Bedrock automatically generates this value. You must reuse this value for all subsequent requests in the same conversational session. This value allows Amazon Bedrock to maintain context and knowledge from previous interactions. You can't explicitly set the <code>sessionId</code> yourself.</p>
155    pub fn get_session_id(&self) -> &::std::option::Option<::std::string::String> {
156        self.inner.get_session_id()
157    }
158    /// <p>Contains the query to be made to the knowledge base.</p>
159    pub fn input(mut self, input: crate::types::RetrieveAndGenerateInput) -> Self {
160        self.inner = self.inner.input(input);
161        self
162    }
163    /// <p>Contains the query to be made to the knowledge base.</p>
164    pub fn set_input(mut self, input: ::std::option::Option<crate::types::RetrieveAndGenerateInput>) -> Self {
165        self.inner = self.inner.set_input(input);
166        self
167    }
168    /// <p>Contains the query to be made to the knowledge base.</p>
169    pub fn get_input(&self) -> &::std::option::Option<crate::types::RetrieveAndGenerateInput> {
170        self.inner.get_input()
171    }
172    /// <p>Contains configurations for the knowledge base query and retrieval process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-config.html">Query configurations</a>.</p>
173    pub fn retrieve_and_generate_configuration(mut self, input: crate::types::RetrieveAndGenerateConfiguration) -> Self {
174        self.inner = self.inner.retrieve_and_generate_configuration(input);
175        self
176    }
177    /// <p>Contains configurations for the knowledge base query and retrieval process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-config.html">Query configurations</a>.</p>
178    pub fn set_retrieve_and_generate_configuration(mut self, input: ::std::option::Option<crate::types::RetrieveAndGenerateConfiguration>) -> Self {
179        self.inner = self.inner.set_retrieve_and_generate_configuration(input);
180        self
181    }
182    /// <p>Contains configurations for the knowledge base query and retrieval process. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/kb-test-config.html">Query configurations</a>.</p>
183    pub fn get_retrieve_and_generate_configuration(&self) -> &::std::option::Option<crate::types::RetrieveAndGenerateConfiguration> {
184        self.inner.get_retrieve_and_generate_configuration()
185    }
186    /// <p>Contains details about the session with the knowledge base.</p>
187    pub fn session_configuration(mut self, input: crate::types::RetrieveAndGenerateSessionConfiguration) -> Self {
188        self.inner = self.inner.session_configuration(input);
189        self
190    }
191    /// <p>Contains details about the session with the knowledge base.</p>
192    pub fn set_session_configuration(mut self, input: ::std::option::Option<crate::types::RetrieveAndGenerateSessionConfiguration>) -> Self {
193        self.inner = self.inner.set_session_configuration(input);
194        self
195    }
196    /// <p>Contains details about the session with the knowledge base.</p>
197    pub fn get_session_configuration(&self) -> &::std::option::Option<crate::types::RetrieveAndGenerateSessionConfiguration> {
198        self.inner.get_session_configuration()
199    }
200}