pub struct BedrockModel { /* private fields */ }Expand description
The Amazon Bedrock model provider (BedrockModel), on the Converse and ConverseStream APIs.
Supports streaming and non-streaming responses, tool use, reasoning, citations, documents and
media, prompt caching (BedrockCacheConfig), guardrails (BedrockGuardrailConfig),
native token counting and structured output.
Cheap to clone and to share as Arc<dyn Model>: clones share one configuration and one AWS
client, so update_config on any clone changes them all.
use strands::models::bedrock::{BedrockModel, BedrockModelConfig};
use strands::models::{Model, ModelRequest};
use strands::{AggregatedEvent, Message};
use futures::StreamExt;
let model = BedrockModel::new(BedrockModelConfig {
model_id: Some("global.anthropic.claude-sonnet-4-6".into()),
max_tokens: Some(1024),
..Default::default()
});
let request = ModelRequest::builder().messages(vec![Message::user("Hello!")]).build();
let mut stream = model.stream_aggregated(request);
while let Some(item) = stream.next().await {
if let AggregatedEvent::Done(result) = item? {
println!("{}", result.message.text());
}
}Implementations§
Source§impl BedrockModel
impl BedrockModel
Sourcepub fn new(options: impl Into<BedrockModelOptions>) -> Self
pub fn new(options: impl Into<BedrockModelOptions>) -> Self
Creates the provider from options or a bare BedrockModelConfig. The AWS client is built
on first use.
Sourcepub fn builder() -> BedrockModelOptionsBuilder
pub fn builder() -> BedrockModelOptionsBuilder
Starts a BedrockModelOptions builder whose build() returns the provider.
Sourcepub fn config(&self) -> BedrockModelConfig
pub fn config(&self) -> BedrockModelConfig
The configuration with the defaults the provider applies filled in: the model id,
max_tokens from the model’s output ceiling and context_window_limit from the model info.
Sourcepub fn update_config(&self, config: impl Into<BedrockModelConfig>) -> Result<()>
pub fn update_config(&self, config: impl Into<BedrockModelConfig>) -> Result<()>
Shallow-merges config into the configuration: every field it sets replaces the current
value. Takes a BedrockModelConfig or a BaseModelConfig; on the concrete type it
shadows Model::update_config, which does the same.
§Errors
None today; the Result matches the other providers’ update_config, which validate.
Trait Implementations§
Source§impl Clone for BedrockModel
impl Clone for BedrockModel
Source§impl Debug for BedrockModel
impl Debug for BedrockModel
Source§impl Default for BedrockModel
impl Default for BedrockModel
Source§impl From<BedrockModelOptions> for BedrockModel
impl From<BedrockModelOptions> for BedrockModel
Source§fn from(options: BedrockModelOptions) -> Self
fn from(options: BedrockModelOptions) -> Self
Source§impl Model for BedrockModel
impl Model for BedrockModel
Source§fn stream(
&self,
request: ModelRequest,
) -> BoxStream<'static, Result<ModelStreamEvent>>
fn stream( &self, request: ModelRequest, ) -> BoxStream<'static, Result<ModelStreamEvent>>
request as raw events. Read moreSource§fn get_config(&self) -> BaseModelConfig
fn get_config(&self) -> BaseModelConfig
Source§fn update_config(&self, config: BaseModelConfig) -> Result<()>
fn update_config(&self, config: BaseModelConfig) -> Result<()>
config into the configuration: every field it sets replaces the current value
(BaseModelConfig::merge). Read moreSource§fn model_info(&self) -> ModelInfo
fn model_info(&self) -> ModelInfo
Source§fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: CountTokensOptions,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: CountTokensOptions,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn stream_aggregated(
&self,
request: ModelRequest,
) -> BoxStream<'static, Result<AggregatedEvent>>
fn stream_aggregated( &self, request: ModelRequest, ) -> BoxStream<'static, Result<AggregatedEvent>>
Source§fn stateful(&self) -> bool
fn stateful(&self) -> bool
stateful), from
model_info().capabilities.stateful; false when unknown. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for BedrockModel
impl !UnwindSafe for BedrockModel
impl Freeze for BedrockModel
impl Send for BedrockModel
impl Sync for BedrockModel
impl Unpin for BedrockModel
impl UnsafeUnpin for BedrockModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more