Crates.io | stone-mason |
lib.rs | stone-mason |
version | 0.1.0 |
source | src |
created_at | 2023-11-27 02:44:12.889118 |
updated_at | 2023-11-27 02:44:12.889118 |
description | stone-mason is a library to simplify using the Amazon Bedrock Rust SDK aws-sdk-bedrockruntime. |
homepage | |
repository | https://github.com/nated0g/stone-mason |
max_upload_size | |
id | 1049677 |
size | 65,878 |
stone-mason
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.
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.