llm/builder/
llm_builder.rs1use secrecy::SecretString;
2
3use crate::chat::ReasoningEffort;
4
5use super::{backend::LLMBackend, state::BuilderState};
6
7pub struct LLMBuilder {
9 pub(super) state: BuilderState,
10}
11
12impl Default for LLMBuilder {
13 fn default() -> Self {
14 Self {
15 state: BuilderState::new(),
16 }
17 }
18}
19
20impl LLMBuilder {
21 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn backend(mut self, backend: LLMBackend) -> Self {
28 self.state.backend = Some(backend);
29 self
30 }
31
32 pub fn api_key(mut self, key: impl Into<String>) -> Self {
34 self.state.api_key = Some(SecretString::new(key.into()));
35 self
36 }
37
38 pub fn base_url(mut self, url: impl Into<String>) -> Self {
40 self.state.base_url = Some(url.into());
41 self
42 }
43
44 pub fn model(mut self, model: impl Into<String>) -> Self {
46 self.state.model = Some(model.into());
47 self
48 }
49
50 pub fn max_tokens(mut self, max_tokens: u32) -> Self {
52 self.state.max_tokens = Some(max_tokens);
53 self
54 }
55
56 pub fn temperature(mut self, temperature: f32) -> Self {
58 self.state.temperature = Some(temperature);
59 self
60 }
61
62 pub fn system(mut self, system: impl Into<String>) -> Self {
64 self.state.system = Some(system.into());
65 self
66 }
67
68 pub fn reasoning_effort(mut self, reasoning_effort: ReasoningEffort) -> Self {
70 self.state.reasoning_effort = Some(reasoning_effort.to_string());
71 self
72 }
73
74 pub fn reasoning(mut self, reasoning: bool) -> Self {
76 self.state.reasoning = Some(reasoning);
77 self
78 }
79
80 pub fn reasoning_budget_tokens(mut self, reasoning_budget_tokens: u32) -> Self {
82 self.state.reasoning_budget_tokens = Some(reasoning_budget_tokens);
83 self
84 }
85
86 pub fn timeout_seconds(mut self, timeout_seconds: u64) -> Self {
88 self.state.timeout_seconds = Some(timeout_seconds);
89 self
90 }
91
92 pub fn stream(self, _stream: bool) -> Self {
94 self
95 }
96
97 pub fn normalize_response(mut self, normalize_response: bool) -> Self {
99 self.state.normalize_response = Some(normalize_response);
100 self
101 }
102
103 pub fn top_p(mut self, top_p: f32) -> Self {
105 self.state.top_p = Some(top_p);
106 self
107 }
108
109 pub fn top_k(mut self, top_k: u32) -> Self {
111 self.state.top_k = Some(top_k);
112 self
113 }
114}