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