pub struct ModelRegistry { /* private fields */ }Expand description
Maps provider names (as used in node configs: model.provider) to models.
Register it with graphrt_core::Services::insert(registry).
Name resolution (see ModelRegistry::get) is exact, with two explicit
exceptions: aliases added with ModelRegistry::alias, and plugin-style
identifiers <org>/<provider>/<provider> (for example
acme/openai/openai), which resolve to <provider>. Other names, such as
acme/openai, are not guessed.
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn from_config(config: &ProvidersConfig) -> Result<Self, LlmError>
pub fn from_config(config: &ProvidersConfig) -> Result<Self, LlmError>
Build a registry from a providers config, reading secrets and ${VAR}
references from the process environment.
Sourcepub fn from_config_with_vars(
config: &ProvidersConfig,
vars: &[(String, String)],
) -> Result<Self, LlmError>
pub fn from_config_with_vars( config: &ProvidersConfig, vars: &[(String, String)], ) -> Result<Self, LlmError>
Like ModelRegistry::from_config with explicit variables.
A typesafe entry in the credentials section is not a chat model; use
ProvidersConfig::load to get its System One client as well.
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn merge(&mut self, other: ModelRegistry) -> &mut Self
pub fn merge(&mut self, other: ModelRegistry) -> &mut Self
Add every provider and alias of other. other wins every conflict: a
same-named provider is replaced, and an alias of other shadows a provider
of self with that name (so a providers file can redirect openai to a
local server). Used to layer a providers file over ModelRegistry::from_env.
Source§impl ModelRegistry
impl ModelRegistry
pub fn new() -> Self
Sourcepub fn add(
&mut self,
name: impl Into<String>,
model: Arc<dyn ChatModel>,
) -> &mut Self
pub fn add( &mut self, name: impl Into<String>, model: Arc<dyn ChatModel>, ) -> &mut Self
Register a provider, replacing any provider already registered under
name. Use ModelRegistry::try_add to reject duplicates instead.
Sourcepub fn try_add(
&mut self,
name: impl Into<String>,
model: Arc<dyn ChatModel>,
) -> Result<&mut Self, LlmError>
pub fn try_add( &mut self, name: impl Into<String>, model: Arc<dyn ChatModel>, ) -> Result<&mut Self, LlmError>
Register a provider, failing if name is already registered.
Sourcepub fn alias(
&mut self,
alias: impl Into<String>,
target: impl Into<String>,
) -> &mut Self
pub fn alias( &mut self, alias: impl Into<String>, target: impl Into<String>, ) -> &mut Self
Make alias resolve to the provider registered as target.
Sourcepub fn with(self, name: impl Into<String>, model: Arc<dyn ChatModel>) -> Self
pub fn with(self, name: impl Into<String>, model: Arc<dyn ChatModel>) -> Self
Builder-style ModelRegistry::add.
Sourcepub fn remove(&mut self, name: &str) -> bool
pub fn remove(&mut self, name: &str) -> bool
Remove a provider (and any alias with that name). Returns whether something was removed.
Sourcepub fn into_parts(
self,
) -> (IndexMap<String, Arc<dyn ChatModel>>, IndexMap<String, String>)
pub fn into_parts( self, ) -> (IndexMap<String, Arc<dyn ChatModel>>, IndexMap<String, String>)
Decompose into providers and aliases.
pub fn names(&self) -> impl Iterator<Item = &str>
pub fn is_empty(&self) -> bool
Sourcepub fn get(&self, name: &str) -> Result<Arc<dyn ChatModel>, LlmError>
pub fn get(&self, name: &str) -> Result<Arc<dyn ChatModel>, LlmError>
Resolve a provider name: an exact name, then an alias, then a
plugin-style <org>/<provider>/<provider> identifier.
Sourcepub fn from_env() -> Result<Self, LlmError>
pub fn from_env() -> Result<Self, LlmError>
Build a registry from environment variables:
| Variables | Provider name |
|---|---|
OPENAI_API_KEY, optional OPENAI_BASE_URL | openai |
ANTHROPIC_API_KEY, optional ANTHROPIC_BASE_URL | anthropic |
OLLAMA_HOST (default http://localhost:11434; always registered) | ollama |
GRAPHRT_OPENAI_COMPAT_<NAME>_BASE_URL, optional ..._API_KEY | <name> (lowercase) |
GEMINI_API_KEY or GOOGLE_API_KEY, optional GEMINI_BASE_URL | gemini |
AWS_REGION (or AWS_DEFAULT_REGION) plus AWS_BEARER_TOKEN_BEDROCK or AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY (+ AWS_SESSION_TOKEN), optional BEDROCK_ENDPOINT_URL | bedrock |