1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Ergonomic Tools API for type-safe function calling
//!
//! This module provides a high-level API for defining and dispatching tools
//! (function calling) with automatic JSON schema generation and type-safe
//! parameter handling.
//!
//! # Feature Flag
//!
//! This module requires the `tools` feature:
//!
//! ```toml
//! [dependencies]
//! ollama-oxide = { version = "0.1", features = ["tools"] }
//! ```
//!
//! # Overview
//!
//! The tools API provides three tiers of abstraction:
//!
//! 1. **Low-Level** (always available): `ToolDefinition`, `ToolCall` - manual JSON schemas
//! 2. **Type-Safe** (this module): `Tool` trait - auto-generated schemas from Rust types
//! 3. **Registry** (this module): `ToolRegistry` - automatic dispatch
//!
//! # Quick Start
//!
//! ```no_run
//! use ollama_oxide::tools::{Tool, ToolRegistry, ToolResult};
//! use schemars::JsonSchema;
//! use serde::{Deserialize, Serialize};
//!
//! // 1. Define parameter struct (JSON schema auto-generated!)
//! #[derive(Debug, Deserialize, JsonSchema)]
//! struct WeatherParams {
//! location: String,
//! #[serde(default)]
//! unit: Option<String>,
//! }
//!
//! // 2. Define output struct
//! #[derive(Serialize)]
//! struct WeatherResult {
//! temperature: f32,
//! description: String,
//! }
//!
//! // 3. Implement Tool trait
//! struct GetWeather;
//!
//! impl Tool for GetWeather {
//! type Params = WeatherParams;
//! type Output = WeatherResult;
//!
//! fn name(&self) -> &'static str { "get_weather" }
//! fn description(&self) -> &'static str { "Get current weather" }
//!
//! async fn execute(&self, params: Self::Params) -> ToolResult<Self::Output> {
//! // Your implementation here
//! Ok(WeatherResult {
//! temperature: 22.0,
//! description: format!("Sunny in {}", params.location),
//! })
//! }
//! }
//!
//! // 4. Register tools and use in chat
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut registry = ToolRegistry::new();
//! registry.register(GetWeather);
//!
//! // Use registry.definitions() in ChatRequest
//! // Use registry.execute_all(&response) to handle tool calls
//! Ok(())
//! }
//! ```
//!
//! # Comparison with Low-Level API
//!
//! **Low-Level (manual JSON schema):**
//! ```ignore
//! let tool = ToolDefinition::function("get_weather", json!({
//! "type": "object",
//! "properties": { "location": { "type": "string" } },
//! "required": ["location"]
//! }));
//!
//! // Manual dispatch required
//! match call.function_name() {
//! Some("get_weather") => { /* manual JSON parsing */ }
//! _ => {}
//! }
//! ```
//!
//! **Ergonomic (auto-generated schema):**
//! ```ignore
//! // Schema derived from WeatherParams automatically!
//! let definitions = registry.definitions();
//!
//! // Automatic dispatch with type-safe parsing
//! let results = registry.execute_all(&response).await;
//! ```
pub use ToolCall;
pub use ToolCallFunction;
pub use ToolDefinition;
pub use ;
pub use ToolFunction;
pub use ToolRegistry;
pub use Tool;