Skip to content

Commit

Permalink
Merge pull request #34 from dongri/fix-function-call
Browse files Browse the repository at this point in the history
Add function call type
  • Loading branch information
Dongri Jin authored Oct 5, 2023
2 parents 036b850 + 3a37c62 commit d046af8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions examples/function_call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use openai_api_rs::v1::api::Client;
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest, FunctionCallType};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{env, vec};
Expand Down Expand Up @@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
required: Some(vec![String::from("coin")]),
},
}]),
function_call: Some("auto".to_string()),
function_call: Some(FunctionCallType::auto), //Some(FunctionCallType::Function { name: "test".to_string() })
temperature: None,
top_p: None,
n: None,
Expand Down
9 changes: 8 additions & 1 deletion src/v1/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,21 @@ pub const GPT4_32K: &str = "gpt-4-32k";
pub const GPT4_32K_0314: &str = "gpt-4-32k-0314";
pub const GPT4_0613: &str = "gpt-4-0613";

#[derive(Debug, Serialize)]
#[allow(non_camel_case_types)]
pub enum FunctionCallType {
auto,
function { name: String },
}

#[derive(Debug, Serialize)]
pub struct ChatCompletionRequest {
pub model: String,
pub messages: Vec<ChatCompletionMessage>,
#[serde(skip_serializing_if = "Option::is_none")]
pub functions: Option<Vec<Function>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub function_call: Option<String>,
pub function_call: Option<FunctionCallType>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down

0 comments on commit d046af8

Please sign in to comment.