1use super::content::present_nullable;
2use crate::Rest;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6#[serde(untagged)]
7#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
8#[derive(gproxy_protocol_macros::DeclaredFields)]
9pub enum ChatTool {
10 Function(FunctionTool),
11 Custom(CustomToolDefinition),
12}
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
14#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
15#[derive(gproxy_protocol_macros::DeclaredFields)]
16pub struct FunctionTool {
17 #[serde(rename = "type")]
18 pub type_: FunctionToolType,
19 pub function: FunctionDefinition,
20 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
21 pub rest: Rest,
22}
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
24#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
25#[derive(gproxy_protocol_macros::DeclaredFields)]
26pub enum FunctionToolType {
27 #[serde(rename = "function")]
28 Function,
29}
30#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
31#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
32#[derive(gproxy_protocol_macros::DeclaredFields)]
33pub struct CustomToolDefinition {
34 #[serde(rename = "type")]
35 pub type_: CustomToolDefinitionType,
36 pub custom: CustomTool,
37 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
38 pub rest: Rest,
39}
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
41#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
42#[derive(gproxy_protocol_macros::DeclaredFields)]
43pub enum CustomToolDefinitionType {
44 #[serde(rename = "custom")]
45 Custom,
46}
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
48#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
49#[derive(gproxy_protocol_macros::DeclaredFields)]
50pub enum ChatToolType {
51 #[serde(rename = "function")]
52 Function,
53 #[serde(rename = "custom")]
54 Custom,
55}
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
57#[serde(rename_all = "snake_case")]
58#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
59#[derive(gproxy_protocol_macros::DeclaredFields)]
60pub struct FunctionDefinition {
61 pub name: String,
62 #[serde(skip_serializing_if = "Option::is_none")]
63 pub description: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub parameters: Option<Rest>,
66 #[serde(
67 default,
68 deserialize_with = "present_nullable",
69 skip_serializing_if = "Option::is_none"
70 )]
71 pub strict: Option<Option<bool>>,
72 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
73 pub rest: Rest,
74}
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
76#[serde(rename_all = "snake_case")]
77#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
78#[derive(gproxy_protocol_macros::DeclaredFields)]
79pub struct CustomTool {
80 pub name: String,
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub description: Option<String>,
83 #[serde(skip_serializing_if = "Option::is_none")]
84 pub format: Option<CustomToolFormat>,
85 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
86 pub rest: Rest,
87}
88#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
89#[serde(untagged)]
90#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
91#[derive(gproxy_protocol_macros::DeclaredFields)]
92pub enum CustomToolFormat {
93 Text(TextFormat),
94 Grammar(GrammarFormat),
95}
96#[derive(
97 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
98)]
99#[serde(rename_all = "snake_case")]
100#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
101#[derive(gproxy_protocol_macros::DeclaredFields)]
102pub struct TextFormat {
103 #[serde(rename = "type")]
104 pub type_: TextFormatType,
105 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
106 pub rest: Rest,
107}
108#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
109#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
110#[derive(gproxy_protocol_macros::DeclaredFields)]
111pub enum TextFormatType {
112 #[serde(rename = "text")]
113 Text,
114}
115#[derive(
116 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
117)]
118#[serde(rename_all = "snake_case")]
119#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
120#[derive(gproxy_protocol_macros::DeclaredFields)]
121pub struct GrammarFormat {
122 #[serde(rename = "type")]
123 pub type_: GrammarFormatType,
124 pub grammar: Grammar,
125 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
126 pub rest: Rest,
127}
128#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
129#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
130#[derive(gproxy_protocol_macros::DeclaredFields)]
131pub enum GrammarFormatType {
132 #[serde(rename = "grammar")]
133 Grammar,
134}
135#[derive(
136 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
137)]
138#[serde(rename_all = "snake_case")]
139#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
140#[derive(gproxy_protocol_macros::DeclaredFields)]
141pub struct Grammar {
142 pub definition: String,
143 pub syntax: GrammarSyntax,
144 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
145 pub rest: Rest,
146}
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
148#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
149#[derive(gproxy_protocol_macros::DeclaredFields)]
150pub enum GrammarSyntax {
151 #[serde(rename = "lark")]
152 Lark,
153 #[serde(rename = "regex")]
154 Regex,
155}
156
157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
158#[serde(untagged)]
159#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
160#[derive(gproxy_protocol_macros::DeclaredFields)]
161pub enum ToolChoice {
162 Mode(ToolChoiceMode),
163 Function(NamedFunctionChoice),
164 Custom(NamedCustomChoice),
165 Allowed(AllowedToolChoice),
166}
167#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
168#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
169#[derive(gproxy_protocol_macros::DeclaredFields)]
170pub enum ToolChoiceMode {
171 #[serde(rename = "none")]
172 None,
173 #[serde(rename = "auto")]
174 Auto,
175 #[serde(rename = "required")]
176 Required,
177}
178#[derive(
179 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
180)]
181#[serde(rename_all = "snake_case")]
182#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
183#[derive(gproxy_protocol_macros::DeclaredFields)]
184pub struct NamedFunctionChoice {
185 #[serde(rename = "type")]
186 pub type_: NamedFunctionChoiceType,
187 pub function: NamedFunction,
188 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
189 pub rest: Rest,
190}
191#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
192#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
193#[derive(gproxy_protocol_macros::DeclaredFields)]
194pub enum NamedFunctionChoiceType {
195 #[serde(rename = "function")]
196 Function,
197}
198#[derive(
199 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
200)]
201#[serde(rename_all = "snake_case")]
202#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
203#[derive(gproxy_protocol_macros::DeclaredFields)]
204pub struct NamedFunction {
205 pub name: String,
206 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
207 pub rest: Rest,
208}
209#[derive(
210 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
211)]
212#[serde(rename_all = "snake_case")]
213#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
214#[derive(gproxy_protocol_macros::DeclaredFields)]
215pub struct NamedCustomChoice {
216 #[serde(rename = "type")]
217 pub type_: NamedCustomChoiceType,
218 pub custom: NamedCustom,
219 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
220 pub rest: Rest,
221}
222#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
223#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
224#[derive(gproxy_protocol_macros::DeclaredFields)]
225pub enum NamedCustomChoiceType {
226 #[serde(rename = "custom")]
227 Custom,
228}
229#[derive(
230 Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
231)]
232#[serde(rename_all = "snake_case")]
233#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
234#[derive(gproxy_protocol_macros::DeclaredFields)]
235pub struct NamedCustom {
236 pub name: String,
237 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
238 pub rest: Rest,
239}
240#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
241#[serde(rename_all = "snake_case")]
242#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
243#[derive(gproxy_protocol_macros::DeclaredFields)]
244pub struct AllowedToolChoice {
245 #[serde(rename = "type")]
246 pub type_: AllowedToolChoiceType,
247 pub allowed_tools: AllowedTools,
248 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
249 pub rest: Rest,
250}
251#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
252#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
253#[derive(gproxy_protocol_macros::DeclaredFields)]
254pub enum AllowedToolChoiceType {
255 #[serde(rename = "allowed_tools")]
256 AllowedTools,
257}
258#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
259#[serde(rename_all = "snake_case")]
260#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
261#[derive(gproxy_protocol_macros::DeclaredFields)]
262pub struct AllowedTools {
263 pub mode: AllowedToolsMode,
264 pub tools: Vec<Rest>,
265 #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
266 pub rest: Rest,
267}
268#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
269#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
270#[derive(gproxy_protocol_macros::DeclaredFields)]
271pub enum AllowedToolsMode {
272 #[serde(rename = "auto")]
273 Auto,
274 #[serde(rename = "required")]
275 Required,
276}