use std::path::{Path, PathBuf};
use crate::error::SdkError;
#[derive(Debug, Clone)]
pub struct SdkConfig {
pub(crate) inner: lingshu_core::config::AppConfig,
}
impl SdkConfig {
pub fn load() -> Result<Self, SdkError> {
let inner = lingshu_core::config::AppConfig::load()
.map_err(|e| SdkError::Config(e.to_string()))?;
Ok(Self { inner })
}
pub fn load_from(path: impl AsRef<Path>) -> Result<Self, SdkError> {
let inner = lingshu_core::config::AppConfig::load_from(path.as_ref())
.map_err(|e| SdkError::Config(e.to_string()))?;
Ok(Self { inner })
}
pub fn load_profile(name: impl AsRef<str>) -> Result<Self, SdkError> {
let path = Self::profile_config_path(name);
Self::load_from(path)
}
pub fn profile_config_path(name: impl AsRef<str>) -> PathBuf {
lingshu_core::config::lingshu_home()
.join("profiles")
.join(name.as_ref())
.join("config.yaml")
}
pub fn default_config() -> Self {
Self {
inner: lingshu_core::config::AppConfig::default(),
}
}
pub fn save(&self) -> Result<(), SdkError> {
self.inner
.save()
.map_err(|e| SdkError::Config(e.to_string()))
}
pub fn default_model(&self) -> &str {
&self.inner.model.default_model
}
pub fn set_default_model(&mut self, model: impl Into<String>) {
self.inner.model.default_model = model.into();
}
pub fn max_iterations(&self) -> u32 {
self.inner.model.max_iterations
}
pub fn set_max_iterations(&mut self, n: u32) {
self.inner.model.max_iterations = n;
}
pub fn temperature(&self) -> Option<f32> {
self.inner.model.temperature
}
pub fn set_temperature(&mut self, t: Option<f32>) {
self.inner.model.temperature = t;
}
pub fn as_inner(&self) -> &lingshu_core::config::AppConfig {
&self.inner
}
pub fn into_inner(self) -> lingshu_core::config::AppConfig {
self.inner
}
}
impl From<lingshu_core::config::AppConfig> for SdkConfig {
fn from(inner: lingshu_core::config::AppConfig) -> Self {
Self { inner }
}
}
impl From<SdkConfig> for lingshu_core::config::AppConfig {
fn from(sdk: SdkConfig) -> Self {
sdk.inner
}
}