use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct CompletionRequest {
pub rendered_prompt: String,
pub output_schema: Option<Value>,
pub execution_hints: ExecutionHints,
}
impl CompletionRequest {
pub fn new(rendered_prompt: impl Into<String>) -> Self {
Self {
rendered_prompt: rendered_prompt.into(),
output_schema: None,
execution_hints: ExecutionHints::default(),
}
}
pub fn with_output_schema(mut self, schema: Value) -> Self {
self.output_schema = Some(schema);
self
}
pub fn with_execution_hints(mut self, hints: ExecutionHints) -> Self {
self.execution_hints = hints;
self
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExecutionHints {
pub max_tokens: Option<u32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
}
impl ExecutionHints {
pub fn new() -> Self {
Self {
max_tokens: None,
temperature: None,
top_p: None,
}
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = Some(max_tokens);
self
}
pub fn with_temperature(mut self, temperature: f32) -> Self {
self.temperature = Some(temperature);
self
}
pub fn with_top_p(mut self, top_p: f32) -> Self {
self.top_p = Some(top_p);
self
}
pub fn is_empty(&self) -> bool {
self.max_tokens.is_none() && self.temperature.is_none() && self.top_p.is_none()
}
}