Skip to main content

gproxy_protocol/openai/common/tools/
choices.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::super::{AllowedToolsMode, Rest, ToolChoiceMode};
5use super::definitions::NamedTool;
6
7mod allowed;
8pub use allowed::ResponseAllowedTool;
9
10#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11#[serde(untagged)]
12#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
13pub enum ChatToolChoice {
14    Mode(ToolChoiceMode),
15    Allowed(ChatAllowedToolChoice),
16    Named(ChatNamedToolChoice),
17    Unknown(Value),
18}
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21#[serde(untagged)]
22#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
23pub enum ResponseToolChoice {
24    Mode(ToolChoiceMode),
25    Allowed(ResponseAllowedToolChoice),
26    Function(ResponseFunctionToolChoice),
27    Mcp(ResponseMcpToolChoice),
28    Custom(ResponseCustomToolChoice),
29    ApplyPatch(ResponseApplyPatchToolChoice),
30    Shell(ResponseShellToolChoice),
31    Hosted(ResponseHostedToolChoice),
32    Unknown(Value),
33}
34
35#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
36#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
37pub struct ChatAllowedToolChoice {
38    pub allowed_tools: ChatAllowedTools,
39    #[serde(rename = "type")]
40    pub type_: AllowedToolsType,
41    #[serde(default, flatten)]
42    pub rest: Rest,
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
46#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
47pub struct ChatAllowedTools {
48    pub mode: AllowedToolsMode,
49    pub tools: Vec<Rest>,
50    #[serde(default, flatten)]
51    pub rest: Rest,
52}
53
54#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
55#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
56pub struct ResponseAllowedToolChoice {
57    pub mode: AllowedToolsMode,
58    pub tools: Vec<ResponseAllowedTool>,
59    #[serde(rename = "type")]
60    pub type_: AllowedToolsType,
61    #[serde(default, flatten)]
62    pub rest: Rest,
63}
64
65strict_string_enum!(AllowedToolsType { AllowedTools => "allowed_tools" });
66
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68#[serde(untagged)]
69#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
70pub enum ChatNamedToolChoice {
71    Function(ChatNamedFunctionToolChoice),
72    Custom(ChatNamedCustomToolChoice),
73    Unknown(Value),
74}
75
76#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
77#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
78pub struct ChatNamedFunctionToolChoice {
79    #[serde(rename = "type")]
80    pub type_: FunctionToolChoiceType,
81    pub function: NamedTool,
82    #[serde(default, flatten)]
83    pub rest: Rest,
84}
85
86#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
87#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
88pub struct ChatNamedCustomToolChoice {
89    #[serde(rename = "type")]
90    pub type_: CustomToolChoiceType,
91    pub custom: NamedTool,
92    #[serde(default, flatten)]
93    pub rest: Rest,
94}
95
96#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
97#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
98pub struct ResponseHostedToolChoice {
99    #[serde(rename = "type")]
100    pub type_: ResponseHostedToolChoiceType,
101    #[serde(default, flatten)]
102    pub rest: Rest,
103}
104
105strict_string_enum!(ResponseHostedToolChoiceType {
106    FileSearch => "file_search",
107    WebSearchPreview => "web_search_preview",
108    Computer => "computer",
109    ComputerUsePreview => "computer_use_preview",
110    ComputerUse => "computer_use",
111    WebSearchPreview20250311 => "web_search_preview_2025_03_11",
112    ImageGeneration => "image_generation",
113    CodeInterpreter => "code_interpreter",
114});
115
116#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
117#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
118pub struct ResponseFunctionToolChoice {
119    #[serde(rename = "type")]
120    pub type_: FunctionToolChoiceType,
121    pub name: String,
122    #[serde(default, flatten)]
123    pub rest: Rest,
124}
125
126#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
127#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
128pub struct ResponseMcpToolChoice {
129    #[serde(rename = "type")]
130    pub type_: McpToolChoiceType,
131    pub server_label: String,
132    #[serde(skip_serializing_if = "Option::is_none")]
133    pub name: Option<String>,
134    #[serde(default, flatten)]
135    pub rest: Rest,
136}
137
138#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
139#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
140pub struct ResponseCustomToolChoice {
141    #[serde(rename = "type")]
142    pub type_: CustomToolChoiceType,
143    pub name: String,
144    #[serde(default, flatten)]
145    pub rest: Rest,
146}
147
148#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
149#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
150pub struct ResponseApplyPatchToolChoice {
151    #[serde(rename = "type")]
152    pub type_: ApplyPatchToolChoiceType,
153    #[serde(default, flatten)]
154    pub rest: Rest,
155}
156
157#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
158#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
159pub struct ResponseShellToolChoice {
160    #[serde(rename = "type")]
161    pub type_: ShellToolChoiceType,
162    #[serde(default, flatten)]
163    pub rest: Rest,
164}
165
166strict_string_enum!(FunctionToolChoiceType { Function => "function" });
167strict_string_enum!(CustomToolChoiceType { Custom => "custom" });
168strict_string_enum!(McpToolChoiceType { Mcp => "mcp" });
169strict_string_enum!(ApplyPatchToolChoiceType { ApplyPatch => "apply_patch" });
170strict_string_enum!(ShellToolChoiceType { Shell => "shell" });