Expand description
§aither-derive
Procedural macros for converting Rust functions into AI tools that can be called by language models.
This crate provides the #[tool] attribute macro that automatically generates the necessary
boilerplate code to make your async functions callable by AI models through the aither framework.
§Quick Start
Transform any async function into an AI tool by adding the #[tool] attribute:
use aither::Result;
use aither_derive::tool;
#[tool(description = "Get the current UTC time")]
pub async fn get_time() -> Result<&'static str> {
Ok("2023-10-01T12:00:00Z")
}§Function Patterns
§No Parameters
#[tool(description = "Check service health status")]
pub async fn health_check() -> Result<String> {
Ok("Service is healthy".to_string())
}§Simple Parameters
use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct SearchResult {
title: String,
url: String,
}
#[tool(description = "Search the web for content")]
pub async fn search(keywords: Vec<String>, limit: u32) -> Result<Vec<SearchResult>> {
// Your search implementation here
Ok(vec![])
}§Complex Parameters with Documentation
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Debug, JsonSchema, Deserialize)]
pub struct ImageArgs {
/// The text prompt for image generation
pub prompt: String,
/// Image width in pixels
#[serde(default = "default_width")]
pub width: u32,
/// Image height in pixels
#[serde(default = "default_height")]
pub height: u32,
}
fn default_width() -> u32 { 512 }
fn default_height() -> u32 { 512 }
#[tool(description = "Generate an image from a text prompt")]
pub async fn generate_image(args: ImageArgs) -> Result<String> {
// Your image generation logic here
Ok(format!("Generated image: {}", args.prompt))
}§Requirements
- Functions must be
async - Return type must be
Result<T>whereT: serde::Serialize - Parameters must implement
serde::Deserializeandschemars::JsonSchema - No
selfparameters (static functions only) - No lifetime or generic parameters
Attribute Macros§
- tool
- Converts an async function into an AI tool that can be called by language models.