Skip to content

Commit

Permalink
add tool role for ChatCompletionMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
hanselke committed Jul 17, 2024
1 parent 7e10e3a commit 4a11c78
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ let req = ChatCompletionRequest::new(
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);
```
Expand Down
1 change: 1 addition & 0 deletions examples/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
content: chat_completion::Content::Text(String::from("What is bitcoin?")),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);

Expand Down
1 change: 1 addition & 0 deletions examples/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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
5 changes: 5 additions & 0 deletions examples/function_call_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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 @@ -89,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 @@ -97,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
1 change: 1 addition & 0 deletions examples/vision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
]),
name: None,
tool_calls: None,
tool_call_id: None,
}],
);

Expand Down
3 changes: 3 additions & 0 deletions src/v1/chat_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub enum MessageRole {
system,
assistant,
function,
tool,
}

#[derive(Debug, Deserialize, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -158,6 +159,8 @@ pub struct ChatCompletionMessage {
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

0 comments on commit 4a11c78

Please sign in to comment.