Skip to content

Commit d046af8

Browse files
author
Dongri Jin
authored
Merge pull request #34 from dongri/fix-function-call
Add function call type
2 parents 036b850 + 3a37c62 commit d046af8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

examples/function_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use openai_api_rs::v1::api::Client;
2-
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest};
2+
use openai_api_rs::v1::chat_completion::{self, ChatCompletionRequest, FunctionCallType};
33
use serde::{Deserialize, Serialize};
44
use std::collections::HashMap;
55
use std::{env, vec};
@@ -46,7 +46,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4646
required: Some(vec![String::from("coin")]),
4747
},
4848
}]),
49-
function_call: Some("auto".to_string()),
49+
function_call: Some(FunctionCallType::auto), //Some(FunctionCallType::Function { name: "test".to_string() })
5050
temperature: None,
5151
top_p: None,
5252
n: None,

src/v1/chat_completion.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,21 @@ pub const GPT4_32K: &str = "gpt-4-32k";
1313
pub const GPT4_32K_0314: &str = "gpt-4-32k-0314";
1414
pub const GPT4_0613: &str = "gpt-4-0613";
1515

16+
#[derive(Debug, Serialize)]
17+
#[allow(non_camel_case_types)]
18+
pub enum FunctionCallType {
19+
auto,
20+
function { name: String },
21+
}
22+
1623
#[derive(Debug, Serialize)]
1724
pub struct ChatCompletionRequest {
1825
pub model: String,
1926
pub messages: Vec<ChatCompletionMessage>,
2027
#[serde(skip_serializing_if = "Option::is_none")]
2128
pub functions: Option<Vec<Function>>,
2229
#[serde(skip_serializing_if = "Option::is_none")]
23-
pub function_call: Option<String>,
30+
pub function_call: Option<FunctionCallType>,
2431
#[serde(skip_serializing_if = "Option::is_none")]
2532
pub temperature: Option<f64>,
2633
#[serde(skip_serializing_if = "Option::is_none")]

0 commit comments

Comments
 (0)