aws_sdk_bedrockruntime/operation/invoke_model/builders.rs
1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub use crate::operation::invoke_model::_invoke_model_output::InvokeModelOutputBuilder;
3
4pub use crate::operation::invoke_model::_invoke_model_input::InvokeModelInputBuilder;
5
6impl crate::operation::invoke_model::builders::InvokeModelInputBuilder {
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_model::InvokeModelOutput,
13 ::aws_smithy_runtime_api::client::result::SdkError<
14 crate::operation::invoke_model::InvokeModelError,
15 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
16 >,
17 > {
18 let mut fluent_builder = client.invoke_model();
19 fluent_builder.inner = self;
20 fluent_builder.send().await
21 }
22}
23/// Fluent builder constructing a request to `InvokeModel`.
24///
25/// <p>Invokes the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. You use model inference to generate text, images, and embeddings.</p>
26/// <p>For example code, see <i>Invoke model code examples</i> in the <i>Amazon Bedrock User Guide</i>.</p>
27/// <p>This operation requires permission for the <code>bedrock:InvokeModel</code> action.</p><important>
28/// <p>To deny all inference access to resources that you specify in the modelId field, you need to deny access to the <code>bedrock:InvokeModel</code> and <code>bedrock:InvokeModelWithResponseStream</code> actions. Doing this also denies access to the resource through the Converse API actions (<a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_Converse.html">Converse</a> and <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_ConverseStream.html">ConverseStream</a>). For more information see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-deny-inference">Deny access for inference on specific models</a>.</p>
29/// </important>
30/// <p>For troubleshooting some of the common errors you might encounter when using the <code>InvokeModel</code> API, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/troubleshooting-api-error-codes.html">Troubleshooting Amazon Bedrock API Error Codes</a> in the Amazon Bedrock User Guide</p>
31#[derive(::std::clone::Clone, ::std::fmt::Debug)]
32pub struct InvokeModelFluentBuilder {
33 handle: ::std::sync::Arc<crate::client::Handle>,
34 inner: crate::operation::invoke_model::builders::InvokeModelInputBuilder,
35 config_override: ::std::option::Option<crate::config::Builder>,
36}
37impl
38 crate::client::customize::internal::CustomizableSend<
39 crate::operation::invoke_model::InvokeModelOutput,
40 crate::operation::invoke_model::InvokeModelError,
41 > for InvokeModelFluentBuilder
42{
43 fn send(
44 self,
45 config_override: crate::config::Builder,
46 ) -> crate::client::customize::internal::BoxFuture<
47 crate::client::customize::internal::SendResult<
48 crate::operation::invoke_model::InvokeModelOutput,
49 crate::operation::invoke_model::InvokeModelError,
50 >,
51 > {
52 ::std::boxed::Box::pin(async move { self.config_override(config_override).send().await })
53 }
54}
55impl InvokeModelFluentBuilder {
56 /// Creates a new `InvokeModelFluentBuilder`.
57 pub(crate) fn new(handle: ::std::sync::Arc<crate::client::Handle>) -> Self {
58 Self {
59 handle,
60 inner: ::std::default::Default::default(),
61 config_override: ::std::option::Option::None,
62 }
63 }
64 /// Access the InvokeModel as a reference.
65 pub fn as_input(&self) -> &crate::operation::invoke_model::builders::InvokeModelInputBuilder {
66 &self.inner
67 }
68 /// Sends the request and returns the response.
69 ///
70 /// If an error occurs, an `SdkError` will be returned with additional details that
71 /// can be matched against.
72 ///
73 /// By default, any retryable failures will be retried twice. Retry behavior
74 /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be
75 /// set when configuring the client.
76 pub async fn send(
77 self,
78 ) -> ::std::result::Result<
79 crate::operation::invoke_model::InvokeModelOutput,
80 ::aws_smithy_runtime_api::client::result::SdkError<
81 crate::operation::invoke_model::InvokeModelError,
82 ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
83 >,
84 > {
85 let input = self
86 .inner
87 .build()
88 .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)?;
89 let runtime_plugins = crate::operation::invoke_model::InvokeModel::operation_runtime_plugins(
90 self.handle.runtime_plugins.clone(),
91 &self.handle.conf,
92 self.config_override,
93 );
94 crate::operation::invoke_model::InvokeModel::orchestrate(&runtime_plugins, input).await
95 }
96
97 /// Consumes this builder, creating a customizable operation that can be modified before being sent.
98 pub fn customize(
99 self,
100 ) -> crate::client::customize::CustomizableOperation<
101 crate::operation::invoke_model::InvokeModelOutput,
102 crate::operation::invoke_model::InvokeModelError,
103 Self,
104 > {
105 crate::client::customize::CustomizableOperation::new(self)
106 }
107 pub(crate) fn config_override(mut self, config_override: impl ::std::convert::Into<crate::config::Builder>) -> Self {
108 self.set_config_override(::std::option::Option::Some(config_override.into()));
109 self
110 }
111
112 pub(crate) fn set_config_override(&mut self, config_override: ::std::option::Option<crate::config::Builder>) -> &mut Self {
113 self.config_override = config_override;
114 self
115 }
116 /// <p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
117 pub fn body(mut self, input: ::aws_smithy_types::Blob) -> Self {
118 self.inner = self.inner.body(input);
119 self
120 }
121 /// <p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
122 pub fn set_body(mut self, input: ::std::option::Option<::aws_smithy_types::Blob>) -> Self {
123 self.inner = self.inner.set_body(input);
124 self
125 }
126 /// <p>The prompt and inference parameters in the format specified in the <code>contentType</code> in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters.html">Inference parameters</a>. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/api-methods-run.html">Run inference</a> in the Bedrock User Guide.</p>
127 pub fn get_body(&self) -> &::std::option::Option<::aws_smithy_types::Blob> {
128 self.inner.get_body()
129 }
130 /// <p>The MIME type of the input data in the request. You must specify <code>application/json</code>.</p>
131 pub fn content_type(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
132 self.inner = self.inner.content_type(input.into());
133 self
134 }
135 /// <p>The MIME type of the input data in the request. You must specify <code>application/json</code>.</p>
136 pub fn set_content_type(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
137 self.inner = self.inner.set_content_type(input);
138 self
139 }
140 /// <p>The MIME type of the input data in the request. You must specify <code>application/json</code>.</p>
141 pub fn get_content_type(&self) -> &::std::option::Option<::std::string::String> {
142 self.inner.get_content_type()
143 }
144 /// <p>The desired MIME type of the inference body in the response. The default value is <code>application/json</code>.</p>
145 pub fn accept(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
146 self.inner = self.inner.accept(input.into());
147 self
148 }
149 /// <p>The desired MIME type of the inference body in the response. The default value is <code>application/json</code>.</p>
150 pub fn set_accept(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
151 self.inner = self.inner.set_accept(input);
152 self
153 }
154 /// <p>The desired MIME type of the inference body in the response. The default value is <code>application/json</code>.</p>
155 pub fn get_accept(&self) -> &::std::option::Option<::std::string::String> {
156 self.inner.get_accept()
157 }
158 /// <p>The unique identifier of the model to invoke to run inference.</p>
159 /// <p>The <code>modelId</code> to provide depends on the type of model or throughput that you use:</p>
160 /// <ul>
161 /// <li>
162 /// <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p></li>
163 /// <li>
164 /// <p>If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference profile IDs, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html">Supported Regions and models for cross-region inference</a> in the Amazon Bedrock User Guide.</p></li>
165 /// <li>
166 /// <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p></li>
167 /// <li>
168 /// <p>If you use a custom model, specify the ARN of the custom model deployment (for on-demand inference) or the ARN of your provisioned model (for Provisioned Throughput). For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p></li>
169 /// <li>
170 /// <p>If you use an <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html">imported model</a>, specify the ARN of the imported model. You can get the model ARN from a successful call to <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelImportJob.html">CreateModelImportJob</a> or from the Imported models page in the Amazon Bedrock console.</p></li>
171 /// </ul>
172 pub fn model_id(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
173 self.inner = self.inner.model_id(input.into());
174 self
175 }
176 /// <p>The unique identifier of the model to invoke to run inference.</p>
177 /// <p>The <code>modelId</code> to provide depends on the type of model or throughput that you use:</p>
178 /// <ul>
179 /// <li>
180 /// <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p></li>
181 /// <li>
182 /// <p>If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference profile IDs, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html">Supported Regions and models for cross-region inference</a> in the Amazon Bedrock User Guide.</p></li>
183 /// <li>
184 /// <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p></li>
185 /// <li>
186 /// <p>If you use a custom model, specify the ARN of the custom model deployment (for on-demand inference) or the ARN of your provisioned model (for Provisioned Throughput). For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p></li>
187 /// <li>
188 /// <p>If you use an <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html">imported model</a>, specify the ARN of the imported model. You can get the model ARN from a successful call to <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelImportJob.html">CreateModelImportJob</a> or from the Imported models page in the Amazon Bedrock console.</p></li>
189 /// </ul>
190 pub fn set_model_id(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
191 self.inner = self.inner.set_model_id(input);
192 self
193 }
194 /// <p>The unique identifier of the model to invoke to run inference.</p>
195 /// <p>The <code>modelId</code> to provide depends on the type of model or throughput that you use:</p>
196 /// <ul>
197 /// <li>
198 /// <p>If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html#model-ids-arns">Amazon Bedrock base model IDs (on-demand throughput)</a> in the Amazon Bedrock User Guide.</p></li>
199 /// <li>
200 /// <p>If you use an inference profile, specify the inference profile ID or its ARN. For a list of inference profile IDs, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference-support.html">Supported Regions and models for cross-region inference</a> in the Amazon Bedrock User Guide.</p></li>
201 /// <li>
202 /// <p>If you use a provisioned model, specify the ARN of the Provisioned Throughput. For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/prov-thru-use.html">Run inference using a Provisioned Throughput</a> in the Amazon Bedrock User Guide.</p></li>
203 /// <li>
204 /// <p>If you use a custom model, specify the ARN of the custom model deployment (for on-demand inference) or the ARN of your provisioned model (for Provisioned Throughput). For more information, see <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-use.html">Use a custom model in Amazon Bedrock</a> in the Amazon Bedrock User Guide.</p></li>
205 /// <li>
206 /// <p>If you use an <a href="https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-import-model.html">imported model</a>, specify the ARN of the imported model. You can get the model ARN from a successful call to <a href="https://docs.aws.amazon.com/bedrock/latest/APIReference/API_CreateModelImportJob.html">CreateModelImportJob</a> or from the Imported models page in the Amazon Bedrock console.</p></li>
207 /// </ul>
208 pub fn get_model_id(&self) -> &::std::option::Option<::std::string::String> {
209 self.inner.get_model_id()
210 }
211 /// <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p>
212 pub fn trace(mut self, input: crate::types::Trace) -> Self {
213 self.inner = self.inner.trace(input);
214 self
215 }
216 /// <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p>
217 pub fn set_trace(mut self, input: ::std::option::Option<crate::types::Trace>) -> Self {
218 self.inner = self.inner.set_trace(input);
219 self
220 }
221 /// <p>Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.</p>
222 pub fn get_trace(&self) -> &::std::option::Option<crate::types::Trace> {
223 self.inner.get_trace()
224 }
225 /// <p>The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied to the invocation.</p>
226 /// <p>An error will be thrown in the following situations.</p>
227 /// <ul>
228 /// <li>
229 /// <p>You don't provide a guardrail identifier but you specify the <code>amazon-bedrock-guardrailConfig</code> field in the request body.</p></li>
230 /// <li>
231 /// <p>You enable the guardrail but the <code>contentType</code> isn't <code>application/json</code>.</p></li>
232 /// <li>
233 /// <p>You provide a guardrail identifier, but <code>guardrailVersion</code> isn't specified.</p></li>
234 /// </ul>
235 pub fn guardrail_identifier(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
236 self.inner = self.inner.guardrail_identifier(input.into());
237 self
238 }
239 /// <p>The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied to the invocation.</p>
240 /// <p>An error will be thrown in the following situations.</p>
241 /// <ul>
242 /// <li>
243 /// <p>You don't provide a guardrail identifier but you specify the <code>amazon-bedrock-guardrailConfig</code> field in the request body.</p></li>
244 /// <li>
245 /// <p>You enable the guardrail but the <code>contentType</code> isn't <code>application/json</code>.</p></li>
246 /// <li>
247 /// <p>You provide a guardrail identifier, but <code>guardrailVersion</code> isn't specified.</p></li>
248 /// </ul>
249 pub fn set_guardrail_identifier(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
250 self.inner = self.inner.set_guardrail_identifier(input);
251 self
252 }
253 /// <p>The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied to the invocation.</p>
254 /// <p>An error will be thrown in the following situations.</p>
255 /// <ul>
256 /// <li>
257 /// <p>You don't provide a guardrail identifier but you specify the <code>amazon-bedrock-guardrailConfig</code> field in the request body.</p></li>
258 /// <li>
259 /// <p>You enable the guardrail but the <code>contentType</code> isn't <code>application/json</code>.</p></li>
260 /// <li>
261 /// <p>You provide a guardrail identifier, but <code>guardrailVersion</code> isn't specified.</p></li>
262 /// </ul>
263 pub fn get_guardrail_identifier(&self) -> &::std::option::Option<::std::string::String> {
264 self.inner.get_guardrail_identifier()
265 }
266 /// <p>The version number for the guardrail. The value can also be <code>DRAFT</code>.</p>
267 pub fn guardrail_version(mut self, input: impl ::std::convert::Into<::std::string::String>) -> Self {
268 self.inner = self.inner.guardrail_version(input.into());
269 self
270 }
271 /// <p>The version number for the guardrail. The value can also be <code>DRAFT</code>.</p>
272 pub fn set_guardrail_version(mut self, input: ::std::option::Option<::std::string::String>) -> Self {
273 self.inner = self.inner.set_guardrail_version(input);
274 self
275 }
276 /// <p>The version number for the guardrail. The value can also be <code>DRAFT</code>.</p>
277 pub fn get_guardrail_version(&self) -> &::std::option::Option<::std::string::String> {
278 self.inner.get_guardrail_version()
279 }
280 /// <p>Model performance settings for the request.</p>
281 pub fn performance_config_latency(mut self, input: crate::types::PerformanceConfigLatency) -> Self {
282 self.inner = self.inner.performance_config_latency(input);
283 self
284 }
285 /// <p>Model performance settings for the request.</p>
286 pub fn set_performance_config_latency(mut self, input: ::std::option::Option<crate::types::PerformanceConfigLatency>) -> Self {
287 self.inner = self.inner.set_performance_config_latency(input);
288 self
289 }
290 /// <p>Model performance settings for the request.</p>
291 pub fn get_performance_config_latency(&self) -> &::std::option::Option<crate::types::PerformanceConfigLatency> {
292 self.inner.get_performance_config_latency()
293 }
294}