Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ChatCompletionFunctionCall interface #118

Merged
merged 8 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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