#[derive(ToolSet)]
Expand description
The ToolSet
procedural macro is used to derive a structure
which encapsulates various chat completion commands.
This macro should be applied to an enum. It generates various supporting structures and methods, including structures representing the command arguments, methods for converting between the argument structures and the original enum, JSON conversion methods, and an implementation of the original enum that provides methods for executing the commands and dealing with the responses.
Each variant of the original enum will be converted into a corresponding structure,
and each field in the variant will become a field in the generated structure.
The generated structures will derive serde::Deserialize
and Debug
automatically.
This macro also generates methods for calculating the token count of a string and for executing commands based on function calls received from the chat API.
The types of fields in the enum variants determine how the corresponding fields in the
generated structures are treated. For example, fields of type String
or &str
are
converted to JSON value arguments with type "string"
, while fields of type u8
, u16
,
u32
, u64
, usize
, i8
, i16
, i32
, i64
, isize
, f32
or f64
are converted
to JSON value arguments with type "integer"
or "number"
respectively.
For fields with a tuple type, currently this macro simply prints that the field is of a tuple type.
For fields with an array type, they are converted to JSON value arguments with type "array"
.
When running the chat command, a custom system message can be optionally provided. If provided, this message will be used as the system message in the chat request. If not provided, a default system message will be used.
If the total token count of the request exceeds a specified limit, an error will be returned.
The derive_subcommand_gpt
function consumes a TokenStream
representing the enum
to which the macro is applied and produces a TokenStream
representing the generated code.
ยงPanics
This macro will panic (only at compile time) if it is applied to a non-enum item.