claus
claus is a client crate for Anthropic's API, which is often known only as "the Claude API". It allows having "conversations" with a hosted version of the latest Claude large language models.
claus is set apart by a few features from many other implementations:
- Layered: Direct access to API "primitives" is possible; all functionality is built on top of a set of data types covering a large portion of the API.
- I/O-less: claus itself does not perform any I/O, i.e., it does not make any HTTP requests and all of its methods are pure functions. This makes it HTTP client framework agnostic by default, although it contains convenience functions for some.
- Efficient: Uses data structures from the [
im] crate for efficient sharing and cloning of conversation history without deep copying.
Basic Usage
On the lowest layer sits an [Api] struct, which represents the configuration for making requests. You will need an API key to utilize it. Once it is set up, you can create calls to the API through the [MessagesRequestBuilder]:
use ;
use Role;
use HttpRequest;
let api = new;
let http_request: HttpRequest = new
.push_message
.build;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
// now the request can be sent with any HTTP client
This produces [http_request::HttpRequest]s that need to be sent using a suitable HTTP client
framework, see the module for details.
Calling the Anthropic API means sending the entire conversation every time a request is made, i.e., you are responsible for attaching all responses to the set of messages (that includes the user's) every time a request is made. See examples/simple_chat.rs for a complete example.
Higher-level: Conversations
For conversation management, you can use the [conversation::Conversation] type:
use ;
let api = new;
let mut conversation = new;
// Generate request for user message
let http_request = conversation.user_message;
let response_json: String = todo!;
let action = conversation.handle_response
.expect;
for item in action.contents
Streaming
The streaming API is supported as well, although not in conversations. See
examples/streaming.rs for a demonstration on how to use it.