Expand description
Anthropic Rust SDK
This is the Rust SDK for Anthropic. It is a work in progress. The goal is to provide a Rust interface to the Anthropic API.
Usage
use std::error::Error;
use anthropic::client::ClientBuilder;
use anthropic::config::AnthropicConfig;
use anthropic::types::CompleteRequestBuilder;
use anthropic::{AI_PROMPT, HUMAN_PROMPT};
use dotenv::dotenv;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Load the environment variables from the .env file.
dotenv().ok();
// Build with manual configuration.
let client = ClientBuilder::default().api_key("my-api-key".to_string()).build()?;
let complete_request = CompleteRequestBuilder::default()
.prompt(format!("{HUMAN_PROMPT}How many toes do dogs have?{AI_PROMPT}"))
.model("claude-v1".to_string())
.stream_response(false)
.stop_sequences(vec![HUMAN_PROMPT.to_string()])
.build()?;
// Send a completion request.
let _complete_response_result = client.complete(complete_request).await;
// Do something with the response.
Ok(())
}
Modules
- General configuration
- Definition of errors used in the library.
- Module for types used in the API.
Structs
- A value to represent the client id of this SDK.
Constants
- A constant to represent the assistant prompt.
- Auth header key.
- Client id header key.
- Default v1 API base url.
- Default model to use.
- A constant to represent the human prompt.
Functions
- Get the client id.