Skip to content

Commit

Permalink
Better ChatCompletionFunctionCall interface (#118)
Browse files Browse the repository at this point in the history
* 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 <himanshun.iitkgp@gmail.com>
  • Loading branch information
m1guelpf and 64bit committed Oct 30, 2023
1 parent 61bcb40 commit 2895102
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 5 additions & 4 deletions async-openai/src/types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<serde_json::Value> for ChatCompletionFunctionCall {
fn from(value: serde_json::Value) -> Self {
ChatCompletionFunctionCall::Object(value)
}
}

Expand Down
11 changes: 7 additions & 4 deletions async-openai/src/types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ pub enum Stop {
StringArray(Vec<String>), // 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)]
Expand Down

0 comments on commit 2895102

Please sign in to comment.