llmkit-rs 0.1.0

Unified multi-provider async LLM client for Rust — OpenAI, Anthropic, Ollama, with Tower middleware
Documentation
//! Tool derive macro + automatic tool loop.
//! Run with `ANTHROPIC_API_KEY=... cargo run --example tool_calling`.

use llmkit::prelude::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, JsonSchema, ToolSchema)]
#[tool(name = "get_weather", description = "Get current weather for a city")]
struct GetWeatherInput {
    /// City name to look up.
    city: String,
    /// "celsius" or "fahrenheit".
    #[serde(default)]
    units: Option<String>,
}

#[tokio::main]
async fn main() -> LlmResult<()> {
    let client = LlmClientBuilder::new()
        .provider(AnthropicProvider::from_env()?.model("claude-opus-4-8"))
        .build()?;

    let response = client
        .chat(ChatRequest::builder().user("What's the weather in Karachi?").build())
        .with_tool::<GetWeatherInput, _, _>(|input| async move {
            // A real handler would call a weather API here.
            Ok(format!("28°C in {}", input.city))
        })
        .await?;

    println!("{}", response.text().unwrap_or_default());
    Ok(())
}