1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! # 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
//! ```rust
//! 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(())
//! }
use lazy_static;
use version;
extern crate derive_builder;
lazy_static!
/// A constant to represent the human prompt.
pub const HUMAN_PROMPT: &str = "\n\nHuman:";
/// A constant to represent the assistant prompt.
pub const AI_PROMPT: &str = "\n\nAssistant:";
/// Default model to use.
pub const DEFAULT_MODEL: &str = "claude-v1";
/// Default v1 API base url.
pub const DEFAULT_API_BASE: &str = "https://api.anthropic.com";
/// Auth header key.
const AUTHORIZATION_HEADER_KEY: &str = "x-api-key";
/// Client id header key.
const CLIENT_ID_HEADER_KEY: &str = "Client";
/// API version header key.
/// Ref: https://docs.anthropic.com/claude/reference/versioning
const API_VERSION_HEADER_KEY: &str = "anthropic-version";
/// Ref: https://docs.anthropic.com/claude/reference/versioning
const API_VERSION: &str = "2023-06-01";
/// Get the client id.