Skip to main content

gproxy_protocol/openai/common/tools/
definitions.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use super::super::{CustomToolGrammarSyntax, JsonSchema, Rest};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
7#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
8pub struct FunctionDefinition {
9    pub name: String,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub description: Option<String>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    pub parameters: Option<JsonSchema>,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub strict: Option<bool>,
16    #[serde(default, flatten)]
17    pub rest: Rest,
18}
19
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
21#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
22pub struct FunctionCall {
23    pub arguments: String,
24    pub name: String,
25    #[serde(default, flatten)]
26    pub rest: Rest,
27}
28
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
30#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
31pub struct CustomToolDefinition {
32    pub name: String,
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub description: Option<String>,
35    #[serde(skip_serializing_if = "Option::is_none")]
36    pub format: Option<CustomToolInputFormat>,
37    #[serde(default, flatten)]
38    pub rest: Rest,
39}
40
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum CustomToolInputFormat {
44    Text(CustomToolTextFormat),
45    Grammar(CustomToolGrammarFormat),
46    Unknown(Value),
47}
48
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
50#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
51pub struct CustomToolTextFormat {
52    #[serde(rename = "type")]
53    pub type_: CustomToolTextFormatType,
54    #[serde(default, flatten)]
55    pub rest: Rest,
56}
57
58strict_string_enum!(CustomToolTextFormatType { Text => "text" });
59
60#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
61#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
62pub struct CustomToolGrammarFormat {
63    #[serde(rename = "type")]
64    pub type_: CustomToolGrammarFormatType,
65    pub definition: String,
66    pub syntax: CustomToolGrammarSyntax,
67    #[serde(default, flatten)]
68    pub rest: Rest,
69}
70
71strict_string_enum!(CustomToolGrammarFormatType { Grammar => "grammar" });
72
73#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
74#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
75pub struct CustomToolGrammar {
76    pub definition: String,
77    pub syntax: CustomToolGrammarSyntax,
78    #[serde(default, flatten)]
79    pub rest: Rest,
80}
81
82#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
83#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
84pub struct NamedTool {
85    pub name: String,
86    #[serde(default, flatten)]
87    pub rest: Rest,
88}