stone-mason
is a Rust library to simplify using the Amazon Bedrock Rust SDK
aws-sdk-bedrockruntime.
This library is still very early in its development, much of it has not been properly tested.
- Builder structs for generating request bodies for each of the base models offered in Bedrock
- Structs for deserialization of inference responses (WIP)
- Enums encoding model ids for all the models
Add the crate to your Cargo.toml
[dependencies]
"stone-mason" = "0.1.0"
You can run the following example with the following command:
cargo run --example anthropic
Note
You'll need valid AWS credentials with at least bedrock:InvokeModel
permissions in your environment, as well as to
have configured model access for the particular
model you're trying to use.
use aws_sdk_bedrockruntime::primitives::Blob;
use aws_sdk_bedrockruntime::Client;
use stone_mason::{
anthropic::{AnthropicModel::Claude, AnthropicParamsBuilder, AnthropicResponse},
BaseModel, FromModelOutput,
ModelVersion::*,
};
#[tokio::main]
async fn main() {
let shared_config = aws_config::from_env().region("us-west-2").load().await;
let client = Client::new(&shared_config);
let model = BaseModel::Anthropic(Claude(V2));
let prompt = "Outline a README.md file for an open source library called stone-mason, which \
is for working with Amazon Bedrock in Rust.";
let formatted_prompt = format!("\n\nHuman: {}\n\nAssistant:", prompt);
println!("{}", formatted_prompt);
let params = AnthropicParamsBuilder::default()
.prompt(formatted_prompt)
.temperature(0.3)
.max_tokens_to_sample(1000)
.build()
.unwrap();
let body_str = serde_json::to_string(¶ms).unwrap();
let body = Blob::new(body_str);
let res = client
.invoke_model()
.model_id(model.to_string())
.content_type("application/json")
.body(body)
.send()
.await
.unwrap();
let parsed = AnthropicResponse::from_model_output(&res).unwrap();
println!("\n\n{}", parsed.completion)
}
TODO
TODO
This project is licensed under the MIT license. See LICENSE for more details.