diff --git a/README.md b/README.md index c0e6809..fb08872 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ let req = ChatCompletionRequest::new( role: chat_completion::MessageRole::user, content: chat_completion::Content::Text(String::from("What is bitcoin?")), name: None, + tool_calls: None, + tool_call_id: None, }], ); ``` diff --git a/examples/chat_completion.rs b/examples/chat_completion.rs index d53134f..7a31241 100644 --- a/examples/chat_completion.rs +++ b/examples/chat_completion.rs @@ -13,6 +13,8 @@ async fn main() -> Result<(), Box> { role: chat_completion::MessageRole::user, content: chat_completion::Content::Text(String::from("What is bitcoin?")), name: None, + tool_calls: None, + tool_call_id: None, }], ); diff --git a/examples/function_call.rs b/examples/function_call.rs index 27c6375..ddf1d3d 100644 --- a/examples/function_call.rs +++ b/examples/function_call.rs @@ -34,6 +34,8 @@ async fn main() -> Result<(), Box> { role: chat_completion::MessageRole::user, content: chat_completion::Content::Text(String::from("What is the price of Ethereum?")), name: None, + tool_calls: None, + tool_call_id: None, }], ) .tools(vec![chat_completion::Tool { diff --git a/examples/function_call_role.rs b/examples/function_call_role.rs index dcdf7ad..38463a5 100644 --- a/examples/function_call_role.rs +++ b/examples/function_call_role.rs @@ -34,6 +34,8 @@ async fn main() -> Result<(), Box> { role: chat_completion::MessageRole::user, content: chat_completion::Content::Text(String::from("What is the price of Ethereum?")), name: None, + tool_calls: None, + tool_call_id: None, }], ) .tools(vec![chat_completion::Tool { @@ -88,6 +90,8 @@ async fn main() -> Result<(), Box> { "What is the price of Ethereum?", )), name: None, + tool_calls: None, + tool_call_id: None, }, chat_completion::ChatCompletionMessage { role: chat_completion::MessageRole::function, @@ -96,6 +100,8 @@ async fn main() -> Result<(), Box> { format!("{{\"price\": {}}}", price) }), name: Some(String::from("get_coin_price")), + tool_calls: None, + tool_call_id: None, }, ], ); diff --git a/examples/vision.rs b/examples/vision.rs index b62a653..57397ae 100644 --- a/examples/vision.rs +++ b/examples/vision.rs @@ -28,6 +28,8 @@ async fn main() -> Result<(), Box> { }, ]), name: None, + tool_calls: None, + tool_call_id: None, }], ); diff --git a/src/v1/chat_completion.rs b/src/v1/chat_completion.rs index 0a551ae..28284be 100644 --- a/src/v1/chat_completion.rs +++ b/src/v1/chat_completion.rs @@ -45,6 +45,8 @@ pub struct ChatCompletionRequest { #[serde(skip_serializing_if = "Option::is_none")] pub tools: Option>, #[serde(skip_serializing_if = "Option::is_none")] + pub parallel_tool_calls: Option, + #[serde(skip_serializing_if = "Option::is_none")] #[serde(serialize_with = "serialize_tool_choice")] pub tool_choice: Option, } @@ -67,6 +69,7 @@ impl ChatCompletionRequest { user: None, seed: None, tools: None, + parallel_tool_calls: None, tool_choice: None, } } @@ -87,6 +90,7 @@ impl_builder_methods!( user: String, seed: i64, tools: Vec, + parallel_tool_calls: bool, tool_choice: ToolChoiceType ); @@ -97,6 +101,7 @@ pub enum MessageRole { system, assistant, function, + tool, } #[derive(Debug, Deserialize, Clone, PartialEq, Eq)] @@ -111,7 +116,13 @@ impl serde::Serialize for Content { S: serde::Serializer, { match *self { - Content::Text(ref text) => serializer.serialize_str(text), + Content::Text(ref text) => { + if text.is_empty() { + serializer.serialize_none() + } else { + serializer.serialize_str(text) + } + } Content::ImageUrl(ref image_url) => image_url.serialize(serializer), } } @@ -146,6 +157,10 @@ pub struct ChatCompletionMessage { pub content: Content, #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub tool_calls: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub tool_call_id: Option, } #[derive(Debug, Deserialize, Serialize)]