use super::content::present_nullable;
use crate::Rest;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum ChatTool {
Function(FunctionTool),
Custom(CustomToolDefinition),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct FunctionTool {
#[serde(rename = "type")]
pub type_: FunctionToolType,
pub function: FunctionDefinition,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum FunctionToolType {
#[serde(rename = "function")]
Function,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct CustomToolDefinition {
#[serde(rename = "type")]
pub type_: CustomToolDefinitionType,
pub custom: CustomTool,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum CustomToolDefinitionType {
#[serde(rename = "custom")]
Custom,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum ChatToolType {
#[serde(rename = "function")]
Function,
#[serde(rename = "custom")]
Custom,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct FunctionDefinition {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<Rest>,
#[serde(
default,
deserialize_with = "present_nullable",
skip_serializing_if = "Option::is_none"
)]
pub strict: Option<Option<bool>>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct CustomTool {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<CustomToolFormat>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum CustomToolFormat {
Text(TextFormat),
Grammar(GrammarFormat),
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct TextFormat {
#[serde(rename = "type")]
pub type_: TextFormatType,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum TextFormatType {
#[serde(rename = "text")]
Text,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct GrammarFormat {
#[serde(rename = "type")]
pub type_: GrammarFormatType,
pub grammar: Grammar,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum GrammarFormatType {
#[serde(rename = "grammar")]
Grammar,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct Grammar {
pub definition: String,
pub syntax: GrammarSyntax,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum GrammarSyntax {
#[serde(rename = "lark")]
Lark,
#[serde(rename = "regex")]
Regex,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum ToolChoice {
Mode(ToolChoiceMode),
Function(NamedFunctionChoice),
Custom(NamedCustomChoice),
Allowed(AllowedToolChoice),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum ToolChoiceMode {
#[serde(rename = "none")]
None,
#[serde(rename = "auto")]
Auto,
#[serde(rename = "required")]
Required,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct NamedFunctionChoice {
#[serde(rename = "type")]
pub type_: NamedFunctionChoiceType,
pub function: NamedFunction,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum NamedFunctionChoiceType {
#[serde(rename = "function")]
Function,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct NamedFunction {
pub name: String,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct NamedCustomChoice {
#[serde(rename = "type")]
pub type_: NamedCustomChoiceType,
pub custom: NamedCustom,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum NamedCustomChoiceType {
#[serde(rename = "custom")]
Custom,
}
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder,
)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct NamedCustom {
pub name: String,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct AllowedToolChoice {
#[serde(rename = "type")]
pub type_: AllowedToolChoiceType,
pub allowed_tools: AllowedTools,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum AllowedToolChoiceType {
#[serde(rename = "allowed_tools")]
AllowedTools,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
#[serde(rename_all = "snake_case")]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub struct AllowedTools {
pub mode: AllowedToolsMode,
pub tools: Vec<Rest>,
#[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub rest: Rest,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
#[derive(gproxy_protocol_macros::DeclaredFields)]
pub enum AllowedToolsMode {
#[serde(rename = "auto")]
Auto,
#[serde(rename = "required")]
Required,
}