use crate::error::AmbiError;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone)]
pub struct OpenAIEngineConfig {
pub api_key: String,
pub base_url: String,
pub model_name: String,
pub temp: f32,
pub top_p: f32,
}
impl OpenAIEngineConfig {
pub fn validate(&self) -> crate::error::Result<()> {
if self.api_key.trim().is_empty() {
return Err(AmbiError::EngineError(
"OpenAI API Key cannot be empty".to_string(),
));
}
if self.temp < 0.0 || self.temp > 2.0 {
return Err(AmbiError::EngineError(
"Temperature must be between 0.0 and 2.0".to_string(),
));
}
Ok(())
}
pub fn create(api_key: String, model_name: &str) -> Self {
Self {
api_key,
base_url: "https://api.openai.com/v1".to_string(),
model_name: model_name.to_string(),
temp: 0.0,
top_p: 0.0,
}
}
pub fn base_url(mut self, base_url: String) -> Self {
self.base_url = base_url;
self
}
pub fn temp(mut self, temp: f32) -> Self {
self.temp = temp;
self
}
pub fn top_p(mut self, top_p: f32) -> Self {
self.top_p = top_p;
self
}
}