Configuration reading and normalization for LLMDB.
Reads from Application environment and provides normalized config maps and compiled filter patterns.
Summary
Functions
Compiles allow/deny filter patterns to regexes for performance.
Returns normalized configuration map from Application environment.
Returns the list of sources to load, in precedence order.
Functions
@spec compile_filters( allow :: :all | map(), deny :: map(), known_providers :: [atom()] | nil ) :: {%{allow: :all | map(), deny: map()}, [{:unknown, [term()]}]}
Compiles allow/deny filter patterns to regexes for performance.
Parameters
allow-:allor%{provider_atom => [pattern_strings]}deny-%{provider_atom => [pattern_strings]}known_providers- Optional list of known provider atoms for validation (defaults to all existing atoms)
Patterns support glob syntax with * wildcards via LLMDB.Merge.compile_pattern/1.
Provider keys that don't correspond to existing atoms are silently ignored.
Deny patterns always win over allow patterns.
Returns
{%{allow: compiled_patterns, deny: compiled_patterns}, unknown_providers}
Where compiled_patterns is either :all or %{provider => [%Regex{}]},
and unknown_providers is a list of provider keys that were ignored.
@spec get() :: map()
Returns normalized configuration map from Application environment.
Reads :llm_db application config and normalizes with defaults.
Configuration Format
config :llm_db,
allow: :all, # or [:openai, :anthropic] or %{openai: ["gpt-4*"]}
deny: %{}, # or [:provider] or %{provider: ["pattern"]}
prefer: [:openai, :anthropic],
custom: %{
vllm: [
name: "Local vLLM Provider",
base_url: "http://localhost:8000/v1",
models: %{
"llama-3" => %{capabilities: %{chat: true}},
"mistral-7b" => %{capabilities: %{chat: true, tools: %{enabled: true}}}
}
],
custom_provider: [
name: "My Custom Provider",
models: %{
"model-1" => %{capabilities: %{chat: true}}
}
]
}Provider keys can be atoms or strings. Patterns support glob syntax with * wildcards.
Custom providers are defined with provider ID as key, and a keyword list containing:
:name- Provider name (optional):base_url- Base URL for API (optional):models- Map of model ID to model config
Returns
A map with keys:
:compile_embed- Whether to compile-time embed snapshot (default: false):allow- Allow patterns (:allor%{provider => [patterns]}):deny- Deny patterns (%{provider => [patterns]}):prefer- List of preferred provider atoms:custom- Custom providers map (provider_id => provider_config)
Returns the list of sources to load, in precedence order.
These sources provide raw data that will be merged ON TOP of the packaged base snapshot. The packaged snapshot is always loaded first and is not included in this sources list.
Configuration
config :llm_db,
sources: [
{LLMDB.Sources.ModelsDev, %{}},
{LLMDB.Sources.Local, %{dir: "priv/llm_db"}}
]Default Behavior
If not configured, returns an empty list [], meaning only the packaged
snapshot will be used (stable, version-pinned behavior).
Returns
List of {module, opts} tuples in precedence order (first = lowest precedence).