use serde::{Deserialize, Serialize};
pub const GROQ_API_BASE: &str = "https://api.groq.com/openai/v1";
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GroqConfig {
pub api_key: String,
pub model: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub base_url: Option<String>,
#[serde(default)]
pub reasoning_enabled: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_tokens: Option<u32>,
}
impl Default for GroqConfig {
fn default() -> Self {
Self {
api_key: String::new(),
model: "llama-3.3-70b-versatile".to_string(),
base_url: None,
reasoning_enabled: false,
max_tokens: None,
}
}
}
impl GroqConfig {
pub fn new(api_key: impl Into<String>, model: impl Into<String>) -> Self {
Self { api_key: api_key.into(), model: model.into(), ..Default::default() }
}
pub fn llama70b(api_key: impl Into<String>) -> Self {
Self::new(api_key, "llama-3.3-70b-versatile")
}
pub fn llama8b(api_key: impl Into<String>) -> Self {
Self::new(api_key, "llama-3.1-8b-instant")
}
pub fn mixtral(api_key: impl Into<String>) -> Self {
Self::new(api_key, "mixtral-8x7b-32768")
}
pub fn gemma(api_key: impl Into<String>) -> Self {
Self::new(api_key, "gemma2-9b-it")
}
pub fn with_reasoning(mut self, enabled: bool) -> Self {
self.reasoning_enabled = enabled;
self
}
pub fn with_max_tokens(mut self, max_tokens: u32) -> Self {
self.max_tokens = Some(max_tokens);
self
}
pub fn with_base_url(mut self, base_url: impl Into<String>) -> Self {
self.base_url = Some(base_url.into());
self
}
pub fn effective_base_url(&self) -> &str {
self.base_url.as_deref().unwrap_or(GROQ_API_BASE)
}
}