Lightweight, deterministic enrichment of model data.
This module performs simple derivations and defaults, such as:
- Deriving model family from model ID
- Setting provider_model_id to id if not present
- Ensuring capability defaults are applied (handled by Zoi schemas)
Summary
Functions
Derives the family name from a model ID using prefix logic.
Enriches a single model map with derived and default values.
Enriches a list of model maps.
Propagates cost from canonical models to their dated variants.
Functions
Derives the family name from a model ID using prefix logic.
Extracts family from model ID by splitting on "-" and taking all but the last segment. Returns nil if the family cannot be reasonably derived.
Examples
iex> LLMDB.Enrich.derive_family("gpt-4o-mini")
"gpt-4o"
iex> LLMDB.Enrich.derive_family("claude-3-opus")
"claude-3"
iex> LLMDB.Enrich.derive_family("gemini-1.5-pro")
"gemini-1.5"
iex> LLMDB.Enrich.derive_family("single")
nil
iex> LLMDB.Enrich.derive_family("two-parts")
"two"
Enriches a single model map with derived and default values.
Sets the following fields if not already present:
family: Derived from model IDprovider_model_id: Set to model ID
Note: Capability defaults are handled automatically by Zoi schema validation.
Examples
iex> LLMDB.Enrich.enrich_model(%{id: "gpt-4o-mini", provider: :openai})
%{id: "gpt-4o-mini", provider: :openai, family: "gpt-4o", provider_model_id: "gpt-4o-mini"}
iex> LLMDB.Enrich.enrich_model(%{id: "claude-3-opus", provider: :anthropic, family: "claude-3-custom"})
%{id: "claude-3-opus", provider: :anthropic, family: "claude-3-custom", provider_model_id: "claude-3-opus"}
iex> LLMDB.Enrich.enrich_model(%{id: "model", provider: :openai, provider_model_id: "custom-id"})
%{id: "model", provider: :openai, provider_model_id: "custom-id"}
Enriches a list of model maps.
Applies enrich_model/1 to each model in the list.
Examples
iex> LLMDB.Enrich.enrich_models([
...> %{id: "gpt-4o", provider: :openai},
...> %{id: "claude-3-opus", provider: :anthropic}
...> ])
[
%{id: "gpt-4o", provider: :openai, family: "gpt", provider_model_id: "gpt-4o"},
%{id: "claude-3-opus", provider: :anthropic, family: "claude-3", provider_model_id: "claude-3-opus"}
]
Propagates cost from canonical models to their dated variants.
For models with a date suffix (e.g., gpt-4o-mini-2024-07-18), if the model
has no cost, looks up the canonical model (e.g., gpt-4o-mini) from the same
provider and copies its cost.
Models that already have a cost are left unchanged.
Examples
iex> models = [
...> %{id: "gpt-4o-mini", provider: :openai, cost: %{input: 0.15, output: 0.6}},
...> %{id: "gpt-4o-mini-2024-07-18", provider: :openai}
...> ]
iex> [_, dated] = LLMDB.Enrich.inherit_canonical_costs(models)
iex> dated.cost
%{input: 0.15, output: 0.6}