LemonAi. ProviderRegistry
(lemon_ai v0.1.0)
View Source
Registry for LLM provider implementations.
Providers are registered by their API identifier and can be looked up
at runtime. This module uses :persistent_term for crash-resilient
storage - the registry survives process restarts without re-registration.
Design
Unlike a GenServer-based registry, this implementation stores provider
mappings in :persistent_term, which:
- Survives process crashes and restarts
- Provides O(1) read access with no message passing
- Is optimized for read-heavy, write-rarely patterns (perfect for registries)
Usage
# Registration (typically during application startup)
LemonAi.ProviderRegistry.register(:anthropic_messages, LemonAi.Providers.Anthropic)
# Lookup (fast, no GenServer call)
{:ok, module} = LemonAi.ProviderRegistry.get(:anthropic_messages)
Summary
Functions
Clear all providers. Primarily useful for testing.
Get the provider module for an API.
Get the provider module for an API, raising if not found.
Initialize the registry with default providers.
Check if the registry has been initialized.
List all registered API identifiers.
Register a provider module for an API.
Check if a provider is registered for an API.
Unregister a provider. Primarily useful for testing.
Functions
@spec clear() :: :ok
Clear all providers. Primarily useful for testing.
Get the provider module for an API.
This is a fast O(1) read operation with no message passing.
Get the provider module for an API, raising if not found.
@spec init() :: :ok
Initialize the registry with default providers.
Called during application startup. Safe to call multiple times.
@spec initialized?() :: boolean()
Check if the registry has been initialized.
@spec list() :: [atom()]
List all registered API identifiers.
Register a provider module for an API.
This is a write operation that updates :persistent_term. While safe,
it should be called sparingly (ideally only during application startup)
as :persistent_term writes trigger a global GC of the term.
Check if a provider is registered for an API.
@spec unregister(atom()) :: :ok
Unregister a provider. Primarily useful for testing.