use serde::{Deserialize, Serialize};
use super::{FormatSetting, KeepAliveSetting, ModelOptions, ThinkSetting};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GenerateRequest {
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub prompt: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub suffix: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub images: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub format: Option<FormatSetting>,
#[serde(skip_serializing_if = "Option::is_none")]
pub system: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stream: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub think: Option<ThinkSetting>,
#[serde(skip_serializing_if = "Option::is_none")]
pub raw: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub keep_alive: Option<KeepAliveSetting>,
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<ModelOptions>,
#[serde(skip_serializing_if = "Option::is_none")]
pub logprobs: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub top_logprobs: Option<i32>,
}
impl GenerateRequest {
pub fn new(model: impl Into<String>, prompt: impl Into<String>) -> Self {
Self {
model: model.into(),
prompt: Some(prompt.into()),
suffix: None,
images: None,
format: None,
system: None,
stream: Some(false), think: None,
raw: None,
keep_alive: None,
options: None,
logprobs: None,
top_logprobs: None,
}
}
pub fn with_suffix(mut self, suffix: impl Into<String>) -> Self {
self.suffix = Some(suffix.into());
self
}
pub fn with_image(mut self, image: impl Into<String>) -> Self {
self.images.get_or_insert_with(Vec::new).push(image.into());
self
}
pub fn with_images<I, S>(mut self, images: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.images = Some(images.into_iter().map(|s| s.into()).collect());
self
}
pub fn with_format(mut self, format: impl Into<FormatSetting>) -> Self {
self.format = Some(format.into());
self
}
pub fn with_system(mut self, system: impl Into<String>) -> Self {
self.system = Some(system.into());
self
}
pub fn with_think(mut self, think: impl Into<ThinkSetting>) -> Self {
self.think = Some(think.into());
self
}
pub fn with_raw(mut self, raw: bool) -> Self {
self.raw = Some(raw);
self
}
pub fn with_keep_alive(mut self, keep_alive: impl Into<KeepAliveSetting>) -> Self {
self.keep_alive = Some(keep_alive.into());
self
}
pub fn with_options(mut self, options: ModelOptions) -> Self {
self.options = Some(options);
self
}
pub fn with_logprobs(mut self, logprobs: bool) -> Self {
self.logprobs = Some(logprobs);
self
}
pub fn with_top_logprobs(mut self, n: i32) -> Self {
self.top_logprobs = Some(n);
self
}
}