use serde::{Deserialize, Serialize};
use super::StopSetting;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct ModelOptions {
#[serde(skip_serializing_if = "Option::is_none")]
pub seed: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub temperature: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub top_k: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub min_p: Option<f32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub num_ctx: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub num_predict: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stop: Option<StopSetting>,
}
impl ModelOptions {
pub fn new() -> Self {
Self::default()
}
pub fn with_seed(mut self, seed: i64) -> Self {
self.seed = Some(seed);
self
}
pub fn with_temperature(mut self, temperature: f32) -> Self {
self.temperature = Some(temperature);
self
}
pub fn with_top_k(mut self, top_k: i32) -> Self {
self.top_k = Some(top_k);
self
}
pub fn with_top_p(mut self, top_p: f32) -> Self {
self.top_p = Some(top_p);
self
}
pub fn with_min_p(mut self, min_p: f32) -> Self {
self.min_p = Some(min_p);
self
}
pub fn with_num_ctx(mut self, num_ctx: i32) -> Self {
self.num_ctx = Some(num_ctx);
self
}
pub fn with_num_predict(mut self, num_predict: i32) -> Self {
self.num_predict = Some(num_predict);
self
}
pub fn with_stop(mut self, stop: impl Into<StopSetting>) -> Self {
self.stop = Some(stop.into());
self
}
pub fn is_empty(&self) -> bool {
self.seed.is_none()
&& self.temperature.is_none()
&& self.top_k.is_none()
&& self.top_p.is_none()
&& self.min_p.is_none()
&& self.num_ctx.is_none()
&& self.num_predict.is_none()
&& self.stop.is_none()
}
}