Giter Site home page Giter Site logo

anthropic-rs's Introduction

Anthropic unofficial Rust SDK ๐Ÿฆ€

GitHub Workflow Status Project license Pull Requests welcome Rust docs Rust crate

anthropic-rs is an unofficial Rust library to interact with Anthropic REST API, with async support.

Wanna play with Claude in Rust? This is the place to be!

Usage

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Load the environment variables from the .env file.
    dotenv().ok();

    // Build from configuration.
    let cfg = AnthropicConfig::new()?;
    let client = Client::try_from(cfg)?;

    let complete_request = CompleteRequestBuilder::default()
        .prompt(format!("{HUMAN_PROMPT}How many toes do dogs have?{AI_PROMPT}"))
        .model("claude-instant-1".to_string())
        .stream_response(false)
        .stop_sequences(vec![HUMAN_PROMPT.to_string()])
        .build()?;

    // Send a completion request.
    let complete_response = client.complete(complete_request).await?;

    println!("completion response: {complete_response:?}");

    Ok(())
}

You can find full working examples in the examples directory.

Configuration

anthropic-rs uses dotenv to automatically load environment variables from a .env file. You can also set these variables manually in your environment. Here is an example of the configuration variables used:

ANTHROPIC_API_KEY="..."
ANTHROPIC_DEFAULT_MODEL="claude-v1"

Replace the "..." with your actual tokens and preferences.

You can also set these variables manually when you crate a new Client instance, see more details in usage section.

Features

  • Completion (/v1/complete)
  • Manage stream mode

Contributing

Contributions to anthropic-rs are welcomed! Feel free to submit a pull request or create an issue.

License

anthropic-rs is licensed under the MIT License.

Acknowledgements

  • Anthropic API reference for the clear and concise documentation.
  • The architecture of the SDK is inspired by async-openai, an asynchronous Rust library developed for OpenAI. We extend our heartfelt gratitude to the creators for their invaluable work. We envisage significant benefits in developing a standardized interface for interaction with various AI GPT providers' APIs. As an example, it would facilitate the development of versatile wrappers that could seamlessly interface with different providers.

anthropic-rs's People

Contributors

abdelstark avatar ofalvai avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.