swiftide_core/chat_completion/
chat_completion_response.rs1use derive_builder::Builder;
2
3use super::tools::ToolCall;
4
5#[derive(Clone, Builder, Debug)]
6#[builder(setter(strip_option, into), build_fn(error = anyhow::Error))]
7pub struct ChatCompletionResponse {
8 pub message: Option<String>,
9
10 #[builder(default)]
11 pub tool_calls: Option<Vec<ToolCall>>,
12}
13
14impl ChatCompletionResponse {
15 pub fn builder() -> ChatCompletionResponseBuilder {
16 ChatCompletionResponseBuilder::default()
17 }
18
19 pub fn message(&self) -> Option<&str> {
20 self.message.as_deref()
21 }
22
23 pub fn tool_calls(&self) -> Option<&[ToolCall]> {
24 self.tool_calls.as_deref()
25 }
26}
27
28impl ChatCompletionResponseBuilder {
29 pub fn maybe_message<T: Into<Option<String>>>(&mut self, message: T) -> &mut Self {
30 self.message = Some(message.into());
31 self
32 }
33
34 pub fn maybe_tool_calls<T: Into<Option<Vec<ToolCall>>>>(&mut self, tool_calls: T) -> &mut Self {
35 self.tool_calls = Some(tool_calls.into());
36 self
37 }
38}