use std::time::Duration;
use crate::provider::config::ProviderConfig;
use super::types::OllamaThink;
const DEFAULT_BASE_URL: &str = "http://localhost:11434";
pub(super) const DEFAULT_TIMEOUT_SECS: u64 = 120;
#[derive(Debug, Clone)]
pub struct OllamaProviderConfig {
pub base_url: String,
pub model: String,
pub timeout: Duration,
pub keep_alive: Option<String>,
pub think: Option<OllamaThink>,
pub extra_options: Option<serde_json::Map<String, serde_json::Value>>,
}
impl OllamaProviderConfig {
pub fn new(model: impl Into<String>) -> Self {
Self {
base_url: DEFAULT_BASE_URL.to_string(),
model: model.into(),
timeout: Duration::from_secs(DEFAULT_TIMEOUT_SECS),
keep_alive: None,
think: None,
extra_options: None,
}
}
pub fn with_base_url(mut self, url: impl Into<String>) -> Self {
self.base_url = url.into();
self
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.timeout = timeout;
self
}
pub fn with_keep_alive(mut self, keep_alive: impl Into<String>) -> Self {
self.keep_alive = Some(keep_alive.into());
self
}
pub fn with_think(mut self, think: OllamaThink) -> Self {
self.think = Some(think);
self
}
pub fn with_extra_options(
mut self,
options: serde_json::Map<String, serde_json::Value>,
) -> Self {
self.extra_options = Some(options);
self
}
pub(super) fn chat_url(&self) -> String {
format!("{}/api/chat", self.base_url.trim_end_matches('/'))
}
pub(super) fn tags_url(&self) -> String {
format!("{}/api/tags", self.base_url.trim_end_matches('/'))
}
}
impl ProviderConfig for OllamaProviderConfig {
fn base_url(&self) -> &str {
&self.base_url
}
fn model(&self) -> &str {
&self.model
}
fn api_key(&self) -> Option<&str> {
None
}
fn timeout(&self) -> Duration {
self.timeout
}
}