Crate anthropic

Source
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-instant-1".to_string())
    .stream(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§

client
config
General configuration
error
Definition of errors used in the library.
types
Module for types used in the API.

Structs§

CLIENT_ID
A value to represent the client id of this SDK.

Constants§

AI_PROMPT
A constant to represent the assistant prompt.
DEFAULT_API_BASE
Default v1 API base url.
DEFAULT_MODEL
Default model to use.
HUMAN_PROMPT
A constant to represent the human prompt.

Functions§

client_id
Get the client id.