From 289510264ee510adf8bef75e4ce05b9f4b034d00 Mon Sep 17 00:00:00 2001 From: Miguel Piedrafita Date: Mon, 30 Oct 2023 05:45:49 +0000 Subject: [PATCH] Better ChatCompletionFunctionCall interface (#118) * Better ChatCompletionFunctionCall interface * clean up * cleanup * Update async-openai/src/types/impls.rs * Update async-openai/src/types/types.rs * Update async-openai/src/types/impls.rs * Update async-openai/src/types/types.rs * Update async-openai/src/types/impls.rs --------- Co-authored-by: Himanshu Neema --- async-openai/src/types/impls.rs | 9 +++++---- async-openai/src/types/types.rs | 11 +++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/async-openai/src/types/impls.rs b/async-openai/src/types/impls.rs index 631e5fe5..57f060ac 100644 --- a/async-openai/src/types/impls.rs +++ b/async-openai/src/types/impls.rs @@ -351,13 +351,14 @@ impl_from_for_array_of_integer_array!(u16, Prompt); impl From<&str> for ChatCompletionFunctionCall { fn from(value: &str) -> Self { - ChatCompletionFunctionCall::String(value.to_string()) + match value { + "none" => Self::None, + "auto" => Self::Auto, + _ => Self::Function { name: value.to_string() }, + } } } -impl From for ChatCompletionFunctionCall { - fn from(value: serde_json::Value) -> Self { - ChatCompletionFunctionCall::Object(value) } } diff --git a/async-openai/src/types/types.rs b/async-openai/src/types/types.rs index 28a719d9..f01aed1f 100644 --- a/async-openai/src/types/types.rs +++ b/async-openai/src/types/types.rs @@ -37,11 +37,14 @@ pub enum Stop { StringArray(Vec), // minItems: 1; maxItems: 4 } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] -#[serde(untagged)] +#[derive(Debug, Clone, PartialEq)] pub enum ChatCompletionFunctionCall { - String(String), - Object(serde_json::Value), + /// The model does not call a function, and responds to the end-user. + None, + /// The model can pick between an end-user or calling a function. + Auto, + /// Forces the model to call the specified function. + Function { name : String }, } #[derive(Clone, Serialize, Default, Debug, Builder, PartialEq)]