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

Add parallel_tool_calls to ChatCompletionRequest #95

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}],
);
```
Expand Down
2 changes: 2 additions & 0 deletions examples/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
role: chat_completion::MessageRole::user,
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);

Expand Down
2 changes: 2 additions & 0 deletions examples/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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 {
Expand Down
6 changes: 6 additions & 0 deletions examples/function_call_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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 {
Expand Down Expand Up @@ -88,6 +90,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"What is the price of Ethereum?",
)),
name: None,
tool_calls: None,
tool_call_id: None,
},
chat_completion::ChatCompletionMessage {
role: chat_completion::MessageRole::function,
Expand All @@ -96,6 +100,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
format!("{{\"price\": {}}}", price)
}),
name: Some(String::from("get_coin_price")),
tool_calls: None,
tool_call_id: None,
},
],
);
Expand Down
2 changes: 2 additions & 0 deletions examples/vision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
},
]),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);

Expand Down
17 changes: 16 additions & 1 deletion src/v1/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct ChatCompletionRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<Tool>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parallel_tool_calls: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(serialize_with = "serialize_tool_choice")]
pub tool_choice: Option<ToolChoiceType>,
}
Expand All @@ -67,6 +69,7 @@ impl ChatCompletionRequest {
user: None,
seed: None,
tools: None,
parallel_tool_calls: None,
tool_choice: None,
}
}
Expand All @@ -87,6 +90,7 @@ impl_builder_methods!(
user: String,
seed: i64,
tools: Vec<Tool>,
parallel_tool_calls: bool,
tool_choice: ToolChoiceType
);

Expand All @@ -97,6 +101,7 @@ pub enum MessageRole {
system,
assistant,
function,
tool,
}

#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
Expand All @@ -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),
}
}
Expand Down Expand Up @@ -146,6 +157,10 @@ pub struct ChatCompletionMessage {
pub content: Content,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_calls: Option<Vec<ToolCall>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tool_call_id: Option<String>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
Loading