Skip to main content

BamlRegistry

Trait BamlRegistry 

Source
pub trait BamlRegistry: Sized {
    // Required methods
    fn new() -> Self;
    fn add_llm_client(
        &mut self,
        name: &str,
        provider_type: &str,
        options: HashMap<String, Value>,
    );
    fn set_primary_client(&mut self, name: &str);
}
Expand description

Trait abstracting BAML’s generated ClientRegistry.

Each BAML project generates its own ClientRegistry type, but the API is identical. Implement this trait on a newtype wrapper around your project’s ClientRegistry.

struct MyRegistry(baml_client::ClientRegistry);

impl BamlRegistry for MyRegistry {
    fn new() -> Self { Self(baml_client::ClientRegistry::new()) }
    fn add_llm_client(&mut self, name: &str, provider_type: &str, options: HashMap<String, serde_json::Value>) {
        self.0.add_llm_client(name, provider_type, options);
    }
    fn set_primary_client(&mut self, name: &str) { self.0.set_primary_client(name); }
    fn into_inner(self) -> baml_client::ClientRegistry { self.0 }
}

Required Methods§

Source

fn new() -> Self

Source

fn add_llm_client( &mut self, name: &str, provider_type: &str, options: HashMap<String, Value>, )

Source

fn set_primary_client(&mut self, name: &str)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§