crabtalk_core/model/
request.rs1use crate::model::{Message, Tool, ToolChoice};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, Deserialize, Serialize)]
12pub struct Request {
13 pub model: String,
15
16 #[serde(default)]
18 pub messages: Vec<Message>,
19
20 pub think: bool,
22
23 #[serde(default, skip_serializing_if = "Option::is_none")]
25 pub tools: Option<Vec<Tool>>,
26
27 #[serde(default, skip_serializing_if = "Option::is_none")]
29 pub tool_choice: Option<ToolChoice>,
30
31 pub usage: bool,
33}
34
35impl Request {
36 pub fn new(model: impl Into<String>) -> Self {
38 Self {
39 model: model.into(),
40 messages: Vec::new(),
41 think: false,
42 tools: None,
43 tool_choice: None,
44 usage: false,
45 }
46 }
47
48 pub fn with_messages(mut self, messages: Vec<Message>) -> Self {
50 self.messages = messages;
51 self
52 }
53
54 pub fn with_tools(mut self, tools: Vec<Tool>) -> Self {
56 self.tools = Some(tools);
57 self
58 }
59
60 pub fn with_tool_choice(mut self, tool_choice: ToolChoice) -> Self {
62 self.tool_choice = Some(tool_choice);
63 self
64 }
65
66 pub fn with_think(mut self, think: bool) -> Self {
68 self.think = think;
69 self
70 }
71}