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
extern crate proc_macro;
use TokenStream;
use ;
/// Derives `rig_core::embeddings::Embed` using fields marked with `#[embed]`.
///
/// ```
/// use rig_derive::Embed;
///
/// #[derive(Embed)]
/// struct Document {
/// #[embed]
/// description: String,
/// }
/// ```
/// Derives `rig_core::tool::ContextValue` with the type name as its default key.
/// `#[context(key = "...")]` overrides the key. The type must support serde
/// serialization and deserialization.
///
/// ```
/// use rig_derive::ContextValue;
///
/// #[derive(serde::Serialize, serde::Deserialize, ContextValue)]
/// #[context(key = "session.id")]
/// struct SessionId(String);
/// ```
/// Generates a tool type, parameter struct, and uppercase static from a function
/// returning `Result<T, E>`. Functions with a mutable context implement
/// `rig_core::tool::Tool`; others implement `rig_core::tool::PortableTool`.
/// Imported context names need `#[rig(context)]`; qualified Rig paths are
/// recognized directly. The context is excluded from model arguments.
///
/// Accepts `name`, `description`, `params(name = "description")`, and
/// `required(name, ...)`. Explicit names must start with an ASCII letter or `_`,
/// contain only ASCII letters, digits, `_`, or `-`, and be at most 64 bytes.
/// Description attributes override doc comments. Unknown or duplicate options
/// and parameter names are rejected.
///
/// Non-`Option` arguments are required by default. An explicit required list
/// makes omitted arguments default through serde, requiring `Default`.
/// Listing an `Option` argument as required is rejected.
///
/// ```
/// use rig_derive::rig_tool;
///
/// #[rig_tool(description = "Add integers", params(a = "First operand"), required(a))]
/// fn add(a: i32, b: i32) -> Result<i32, rig_core::tool::ToolExecutionError> {
/// Ok(a + b)
/// }
/// ```