From bfedc7f3cd3cef9b26e06b7fa95804c31d7532fe Mon Sep 17 00:00:00 2001 From: Hytracen Date: Sat, 30 Dec 2023 01:57:45 +0800 Subject: [PATCH] Impl Default trait for JSONSchemaDefine In most cases, only a few properties of JSONSchemaDefine are used, and it seems cumbersome to explicitly declare other properties. --- examples/function_call.rs | 5 +---- examples/function_call_role.rs | 5 +---- src/v1/chat_completion.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/function_call.rs b/examples/function_call.rs index 7cba333..367fb1e 100644 --- a/examples/function_call.rs +++ b/examples/function_call.rs @@ -23,10 +23,7 @@ fn main() -> Result<(), Box> { Box::new(chat_completion::JSONSchemaDefine { schema_type: Some(chat_completion::JSONSchemaType::String), description: Some("The cryptocurrency to get the price of".to_string()), - enum_values: None, - properties: None, - required: None, - items: None, + ..Default::default() }), ); diff --git a/examples/function_call_role.rs b/examples/function_call_role.rs index a842814..0e486c1 100644 --- a/examples/function_call_role.rs +++ b/examples/function_call_role.rs @@ -23,10 +23,7 @@ fn main() -> Result<(), Box> { Box::new(chat_completion::JSONSchemaDefine { schema_type: Some(chat_completion::JSONSchemaType::String), description: Some("The cryptocurrency to get the price of".to_string()), - enum_values: None, - properties: None, - required: None, - items: None, + ..Default::default() }), ); diff --git a/src/v1/chat_completion.rs b/src/v1/chat_completion.rs index 139e35b..a5a6aed 100644 --- a/src/v1/chat_completion.rs +++ b/src/v1/chat_completion.rs @@ -197,6 +197,19 @@ pub struct JSONSchemaDefine { pub items: Option>, } +impl Default for JSONSchemaDefine { + fn default() -> Self { + Self { + schema_type: None, + description: None, + enum_values: None, + properties: None, + required: None, + items: None, + } + } +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct FunctionParameters { #[serde(rename = "type")]