Crates.io | misanthropic |
lib.rs | misanthropic |
version | |
source | src |
created_at | 2024-08-23 22:00:49.968069 |
updated_at | 2024-11-30 01:24:12.363473 |
description | An async, ergonomic, client for Anthropic's Messages API |
homepage | https://github.com/mdegans/misanthropic |
repository | https://github.com/mdegans/misanthropic |
max_upload_size | |
id | 1349659 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
misanthropic
Is an unofficial simple, ergonomic, client for the Anthropic Messages API.
// Create a client. The key is encrypted in memory and source string is zeroed.
// When requests are made, the key header is marked as sensitive.
let client = Client::new(key)?;
// Request a stream of events or errors. `json!` can be used, the `Prompt`
// builder pattern (shown in the `Single Message` example below), or anything
// serializable.
let stream = client
// Forces `stream=true` in the request.
.stream(json!({
"model": Model::Sonnet35,
"max_tokens": args.max_tokens,
"temperature": 0,
"system": args.system,
"messages": [
{
"role": Role::User,
"content": specs,
}
],
}))
.await?
// Filter out rate limit and overloaded errors. This is optional but
// recommended for most use cases. The stream will continue when the
// server is ready. Otherwise the stream will include these errors.
.filter_rate_limit()
// Filter out everything but text pieces (and errors).
.text();
// Collect the stream into a single string.
let content: String = stream
.try_collect()
.await?;
let client = Client::new(key)?;
// Many common usage patterns are supported out of the box for building
// `Prompt`s, such as messages from an iterable of tuples of `Role` and
// `String`.
let message = client
.message(Prompt::default().messages([(Role::User, args.prompt)]))
.await?;
println!("{}", message);
image
crate* Base64 encoded images are currently not implemented for HTML but this is a planned feature.
misanthropic
? No reason, really. I just like the word.
Anthropic is both a company and a word meaning "relating to mankind". This
crate is neither official or related to mankind so, misanthropic
it is.reqwest
depend on tokio
? On some platforms, yes.misanthropic
with Amazon or Vertex? Not yet, but it's on the
roadmap. for now the Client
does support custom endpoints and the inner
reqwest::Client
can be accessed directly to make necessary adjustments to
headers, etc.memsecurity
crate and any headers containing copies marked
as sensitive. rustls
is an optional feature and is recommended for security.
It is on by default.