{"id":17066107,"url":"https://github.com/cortesi/misanthropy","last_synced_at":"2025-04-09T20:04:19.558Z","repository":{"id":245999044,"uuid":"819620298","full_name":"cortesi/misanthropy","owner":"cortesi","description":"Rust bindings to the Anthropic API","archived":false,"fork":false,"pushed_at":"2025-03-17T04:29:22.000Z","size":125,"stargazers_count":27,"open_issues_count":1,"forks_count":6,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T20:04:15.686Z","etag":null,"topics":["ai","anthropic","anthropic-ai","claude","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cortesi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-24T22:02:37.000Z","updated_at":"2025-03-17T04:29:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"9677974b-d305-4199-b346-30aab26e429b","html_url":"https://github.com/cortesi/misanthropy","commit_stats":null,"previous_names":["cortesi/misanthropy"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortesi%2Fmisanthropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortesi%2Fmisanthropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortesi%2Fmisanthropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cortesi%2Fmisanthropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cortesi","download_url":"https://codeload.github.com/cortesi/misanthropy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","anthropic","anthropic-ai","claude","rust"],"created_at":"2024-10-14T11:05:58.753Z","updated_at":"2025-04-09T20:04:19.536Z","avatar_url":"https://github.com/cortesi.png","language":"Rust","funding_links":[],"categories":["API Clients"],"sub_categories":[],"readme":"# Misanthropy\n\n[![Crates.io](https://img.shields.io/crates/v/misanthropy)](https://crates.io/crates/misanthropy)\n[![docs.rs](https://img.shields.io/docsrs/misanthropy)](https://docs.rs/misanthropy)\n[![Rust](https://img.shields.io/badge/rust-1.75%2B-blue.svg?logo=rust)](https://www.rust-lang.org)\n\nMisanthropy is set of Rust bindings for Anthropic API, providing easy access to\nClaude and other Anthropic models. It consists of two main components:\n\n1. `misanthropy`: A Rust client library for the Anthropic API\n2. `misan`: A command-line interface (CLI) tool for quick interactions with the API\n\n\n## Features\n\n- Simple, idiomatic Rust interface for the Anthropic API\n- Support for text and image content in messages\n- Support for streaming real-time responses\n- Configurable client with defaults for model and token limits\n- CLI tool for quick interactions with the API from the command line\n\n\n## Usage\n\n### Library\n\nHere's a basic example of using the `misanthropy` library:\n\n```rust\nuse misanthropy::{Anthropic, MessagesRequest, Content};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    let client = Anthropic::from_env()?;\n    \n    let mut request = MessagesRequest::default();\n    request.add_user(Content::text(\"Hello, Claude!\"));\n\n    let response = client.messages(request).await?;\n    println!(\"{}\", response.format_nicely());\n\n    Ok(())\n}\n```\n\nFor more examples, please check the [`examples`](./crates/misanthropy/examples)\ndirectory in the `misanthropy` crate. These examples demonstrate various\nfeatures and use cases of the library. \n\n\n### CLI\n\nThe `misan` CLI tool provides a command-line interface for interacting with the\nAnthropic API. For usage instructions, run:\n\n```bash\nmisan --help\n```\n\n## Configuration\n\n- `ANTHROPIC_API_KEY`: Set this environment variable with your Anthropic API key.\n- Default model and max tokens can be set when creating the `Anthropic` client or overridden per request.\n\n## Advanced Features\n\n### Streaming Responses\n\nThe library supports streaming responses for real-time interactions:\n\n```rust\nlet mut stream = client.messages_stream(request)?;\n\nwhile let Some(event) = stream.next().await {\n    match event {\n        Ok(event) =\u003e {\n            // Handle the streaming event\n        }\n        Err(e) =\u003e eprintln!(\"Error: {}\", e),\n    }\n}\n```\n\n## Advanced Features\n\n### Using Tools\n\nThe library supports defining and using tools in conversations. Tools are\ndefined using the `schemars` crate to generate JSON schemas for the tool\ninputs.\n\n1. First, add `schemars` to your dependencies:\n\n```toml\n[dependencies]\nschemars = \"0.8\"\n```\n\n2. Define your tool input structure and derive `JsonSchema`:\n\n```rust\nuse schemars::JsonSchema;\nuse serde::{Deserialize, Serialize};\n\n/// Get the current weather for a location.\n#[derive(JsonSchema, Serialize, Deserialize)]\nstruct GetWeather {\n    /// The city and country, e.g., \"London, UK\"\n    location: String,\n    /// Temperature unit: \"celsius\" or \"fahrenheit\"\n    unit: Option\u003cString\u003e,\n}\n```\n\n3. Create a `Tool` from your input structure:\n\n```rust\nuse misanthropy::{Anthropic, MessagesRequest, Tool};\n\nlet weather_tool = Tool::new::\u003cGetWeather\u003e();\n```\n\n4. Add the tool to your request:\n\n```rust\nlet request = MessagesRequest::default()\n    .with_tool(weather_tool)\n    .with_system(vec![Content::text(\"You can use the GetWeather tool to check the weather.\")]);\n```\n\n5. When the AI uses the tool, you can deserialize the input:\n\n```rust\nif let Some(tool_use) = response.content.iter().find_map(|content| {\n    if let Content::ToolUse(tool_use) = content {\n        Some(tool_use)\n    } else {\n        None\n    }\n}) {\n    if tool_use.name == \"GetWeather\" {\n        let weather_input: GetWeather = serde_json::from_value(tool_use.input.clone())?;\n        println!(\"Weather requested for: {}\", weather_input.location);\n        // Here you would typically call an actual weather API\n    }\n}\n```\n\nThis approach allows you to define strongly-typed tool inputs that the AI can\nuse, while also providing a way to handle the tool usage in your code.\n\n\n\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortesi%2Fmisanthropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcortesi%2Fmisanthropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcortesi%2Fmisanthropy/lists"}