1use serde::{Deserialize, Serialize};
4
5use crate::tool::ToolDefinition;
6
7#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct ChatRequest {
10 pub model: String,
11 pub messages: Vec<crate::Message>,
12 pub tools: Option<Vec<ToolDefinition>>,
13 pub temperature: Option<f64>,
14 pub max_tokens: Option<u32>,
15 pub top_p: Option<f64>,
16 pub seed: Option<u64>,
17 pub tool_choice: Option<ToolChoice>,
18 pub stop_sequences: Option<Vec<String>>,
19 pub prefill: Option<String>,
20 #[serde(skip_serializing_if = "Option::is_none")]
26 pub reasoning: Option<ReasoningConfig>,
27 #[serde(skip_serializing_if = "Option::is_none")]
41 pub max_reasoning_tokens: Option<u32>,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 pub extra: Option<serde_json::Map<String, serde_json::Value>>,
45}
46
47impl ChatRequest {
50 pub fn user_prompt(prompt: impl Into<String>) -> Self {
52 Self {
53 messages: vec![crate::Message::User {
54 content: crate::text_block(prompt),
55 }],
56 ..Default::default()
57 }
58 }
59
60 pub fn with_temperature(mut self, temp: f64) -> Self {
61 self.temperature = Some(temp);
62 self
63 }
64
65 pub fn with_max_tokens(mut self, max: u32) -> Self {
66 self.max_tokens = Some(max);
67 self
68 }
69
70 pub fn with_top_p(mut self, top_p: f64) -> Self {
71 self.top_p = Some(top_p);
72 self
73 }
74
75 pub fn with_seed(mut self, seed: u64) -> Self {
76 self.seed = Some(seed);
77 self
78 }
79
80 pub fn with_model(mut self, model: String) -> Self {
81 self.model = model;
82 self
83 }
84
85 pub fn with_tools(mut self, tools: Vec<ToolDefinition>) -> Self {
86 self.tools = Some(tools);
87 self
88 }
89
90 pub fn with_system_prompt(mut self, prompt: String) -> Self {
92 self.messages.insert(
93 0,
94 crate::Message::System {
95 content: crate::text_block(prompt),
96 },
97 );
98 self
99 }
100
101 pub fn with_reasoning(mut self, reasoning: ReasoningConfig) -> Self {
103 self.reasoning = Some(reasoning);
104 self
105 }
106
107 pub fn with_max_reasoning_tokens(mut self, max: u32) -> Self {
109 self.max_reasoning_tokens = Some(max);
110 self
111 }
112
113 pub fn with_extra(mut self, extra: serde_json::Map<String, serde_json::Value>) -> Self {
115 self.extra = Some(extra);
116 self
117 }
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub enum ToolChoice {
123 Tool { name: String },
124 Any,
125}
126
127#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
143pub enum ReasoningConfig {
144 Disabled,
146 Low,
148 Medium,
150 High,
152}
153
154impl ReasoningConfig {
155 pub fn is_disabled(self) -> bool {
157 matches!(self, Self::Disabled)
158 }
159}