ollama_oxide/inference/
model_options.rs1use serde::{Deserialize, Serialize};
4
5use super::StopSetting;
6
7#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
22pub struct ModelOptions {
23 #[serde(skip_serializing_if = "Option::is_none")]
25 pub seed: Option<i64>,
26
27 #[serde(skip_serializing_if = "Option::is_none")]
29 pub temperature: Option<f32>,
30
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub top_k: Option<i32>,
34
35 #[serde(skip_serializing_if = "Option::is_none")]
37 pub top_p: Option<f32>,
38
39 #[serde(skip_serializing_if = "Option::is_none")]
41 pub min_p: Option<f32>,
42
43 #[serde(skip_serializing_if = "Option::is_none")]
45 pub num_ctx: Option<i32>,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub num_predict: Option<i32>,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub stop: Option<StopSetting>,
54}
55
56impl ModelOptions {
57 pub fn new() -> Self {
59 Self::default()
60 }
61
62 pub fn with_seed(mut self, seed: i64) -> Self {
64 self.seed = Some(seed);
65 self
66 }
67
68 pub fn with_temperature(mut self, temperature: f32) -> Self {
70 self.temperature = Some(temperature);
71 self
72 }
73
74 pub fn with_top_k(mut self, top_k: i32) -> Self {
76 self.top_k = Some(top_k);
77 self
78 }
79
80 pub fn with_top_p(mut self, top_p: f32) -> Self {
82 self.top_p = Some(top_p);
83 self
84 }
85
86 pub fn with_min_p(mut self, min_p: f32) -> Self {
88 self.min_p = Some(min_p);
89 self
90 }
91
92 pub fn with_num_ctx(mut self, num_ctx: i32) -> Self {
94 self.num_ctx = Some(num_ctx);
95 self
96 }
97
98 pub fn with_num_predict(mut self, num_predict: i32) -> Self {
100 self.num_predict = Some(num_predict);
101 self
102 }
103
104 pub fn with_stop(mut self, stop: impl Into<StopSetting>) -> Self {
106 self.stop = Some(stop.into());
107 self
108 }
109
110 pub fn is_empty(&self) -> bool {
112 self.seed.is_none()
113 && self.temperature.is_none()
114 && self.top_k.is_none()
115 && self.top_p.is_none()
116 && self.min_p.is_none()
117 && self.num_ctx.is_none()
118 && self.num_predict.is_none()
119 && self.stop.is_none()
120 }
121}