dspy_rs/core/
settings.rs

1use std::sync::{Arc, LazyLock, RwLock};
2
3use super::LM;
4use crate::adapter::Adapter;
5
6pub struct Settings {
7    pub lm: Arc<LM>,
8    pub adapter: Arc<dyn Adapter>,
9}
10
11impl Settings {
12    pub fn new(lm: LM, adapter: impl Adapter + 'static) -> Self {
13        Self {
14            lm: Arc::new(lm),
15            adapter: Arc::new(adapter),
16        }
17    }
18}
19
20pub static GLOBAL_SETTINGS: LazyLock<RwLock<Option<Settings>>> =
21    LazyLock::new(|| RwLock::new(None));
22
23pub fn get_lm() -> Arc<LM> {
24    Arc::clone(&GLOBAL_SETTINGS.read().unwrap().as_ref().unwrap().lm)
25}
26
27pub fn configure(lm: LM, adapter: impl Adapter + 'static) {
28    let settings = Settings::new(lm, adapter);
29    *GLOBAL_SETTINGS.write().unwrap() = Some(settings);
30}