Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
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

Source

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.

Source

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

Source

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

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

pub fn alias( &mut self, alias: impl Into<String>, target: impl Into<String>, ) -> &mut Self

Make alias resolve to the provider registered as target.

Source

pub fn with(self, name: impl Into<String>, model: Arc<dyn ChatModel>) -> Self

Builder-style ModelRegistry::add.

Source

pub fn remove(&mut self, name: &str) -> bool

Remove a provider (and any alias with that name). Returns whether something was removed.

Source

pub fn into_parts( self, ) -> (IndexMap<String, Arc<dyn ChatModel>>, IndexMap<String, String>)

Decompose into providers and aliases.

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Source

pub fn is_empty(&self) -> bool

Source

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.

Source

pub fn from_env() -> Result<Self, LlmError>

Build a registry from environment variables:

VariablesProvider name
OPENAI_API_KEY, optional OPENAI_BASE_URLopenai
ANTHROPIC_API_KEY, optional ANTHROPIC_BASE_URLanthropic
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_URLgemini
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_URLbedrock
Source

pub fn from_vars(vars: &[(String, String)]) -> Result<Self, LlmError>

Like ModelRegistry::from_env but reads from the given variables.

Trait Implementations§

Source§

impl Clone for ModelRegistry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more