Skip to main content

ModelRegistry

Struct ModelRegistry 

Source
pub struct ModelRegistry { /* private fields */ }
Expand description

All known models with their configuration.

Implementations§

Source§

impl ModelRegistry

Source

pub fn load(agent_dir: &Path) -> ModelRegistry

Loads the catalog with models.json and auth.json from agent_dir. It ignores a broken models.json and reports it through ModelRegistry::error.

Source

pub fn enable_llama(&mut self)

Adds pi’s llama.cpp provider, as its built-in extension does.

Source

pub fn llama_enabled(&self) -> bool

Whether the llama.cpp provider is present.

Source

pub async fn llama_server(&self) -> Option<(String, Option<String>)>

The llama.cpp server and its key, when the provider is configured.

Source

pub async fn catalog_targets(&self) -> Vec<Target>

What a catalog refresh needs: each refreshable provider, whether it is configured, and its token for gateways that require one.

Source

pub fn models_store(&self) -> Option<&ModelsStore>

Where refreshed catalogs persist, when the registry was loaded from an agent directory.

Source

pub fn apply_catalogs(&mut self, models: IndexMap<String, ProviderModels>)

Replaces the refreshed catalogs of the providers in models.

Source

pub async fn provider_token(&self, provider: &str) -> Option<String>

A token for provider-level calls such as catalog refreshes: the API key or bearer token a request would send, refreshed first when it is an expiring OAuth token.

Source

pub async fn provider_level_auth(&self, provider: &str) -> Option<Auth>

Credentials for provider as a whole, with its models.json headers but no model’s, as pi’s getAuth(providerId). None for a provider the registry does not know.

Source

pub fn builtin() -> ModelRegistry

The catalog alone, with no files.

Source

pub fn error(&self) -> Option<&str>

Why models.json could not be applied, if it could not.

Source

pub fn models(&self) -> &[Model]

Every chat model.

Source

pub fn find(&self, provider: &str, id: &str) -> Option<&Model>

A model by provider and id.

Source

pub fn classifiers(&self) -> &[ClassifierModel]

Every classifier model, built-in and refreshed.

Source

pub fn image_models(&self) -> &[ImageModel]

Every image-generation model, built-in and refreshed.

Source

pub fn available_classifiers(&self) -> Vec<&ClassifierModel>

Classifier models whose providers are configured and keep them.

Source

pub fn available_image_models(&self) -> Vec<&ImageModel>

Image models whose providers are configured and keep them.

Source

pub async fn classify( &self, model: &ClassifierModel, context: &ClassifierContext, options: ClassifyOptions, ) -> ClassifierResult

Classifies context with model, resolving the provider’s credentials (pi’s Models.classify). Failures are in the result.

Source

pub async fn generate_images( &self, model: &ImageModel, context: &ImagesContext, options: ImagesOptions, ) -> AssistantImages

Generates images with model, resolving the provider’s credentials (pi’s Models.generateImages). Failures are in the result.

Source

pub fn register_config(&mut self, provider: &str, config: ProviderConfig)

Adds a provider an extension configures, as a models.json entry that replaces any of the same name (pi’s registerProvider).

Source

pub fn is_extension_provider(&self, provider: &str) -> bool

Whether an extension registered provider and has not unregistered it.

Source

pub fn unregister_provider(&mut self, provider: &str)

Removes the provider an extension registered as provider, with its sign-ins, availability and implementations, and restores the built-in or models.json provider it replaced (pi’s unregisterProvider). Does nothing for a provider no extension registered.

Source

pub fn replace_models( &mut self, provider: &str, models: Vec<ModelDefinition>, ) -> Result<(), String>

Replaces the models an extension provider configures with ones its refreshModels returned. Fails, changing nothing, when a model lacks an API or base URL, as pi validates a refreshed list before using it.

Source

pub fn register_operations( &mut self, provider: &str, apis: impl IntoIterator<Item = String>, implementation: Arc<dyn ModelOperations>, )

Uses implementation for provider’s classifier and image models of apis (pi’s classifiers and images of an extension’s provider).

Source

pub fn register_key_auth(&mut self, provider: &str, auth: Arc<dyn KeyAuth>)

Resolves provider’s API key with auth instead of the environment, and signs in with its login. The provider is not configured without a stored credential until ModelRegistry::set_availability finds a key.

Source

pub fn key_auth(&self, provider: &str) -> Option<&Arc<dyn KeyAuth>>

provider’s API-key auth from an extension, if it has one.

Source

pub fn set_availability(&mut self, provider: &str, availability: Availability)

Applies what extension provider provider makes available for the stored credential: where its key auth finds a key, and the models its filters keep.

Source

pub fn modify_models(&mut self, provider: &str, models: Option<Vec<Model>>)

Uses models as provider’s chat models, as an extension’s legacy oauth.modifyModels made them for its signed-in account. None restores the provider’s own.

Source

pub async fn refresh_credential(&self, provider: &str) -> Option<Credential>

The credential a catalog refresh of provider passes to the network, as pi’s resolveRefreshCredential: a stored OAuth credential, refreshed when it has expired, else the API key a request would use.

Source

pub fn register_provider(&mut self, provider: &str, models: Vec<Model>)

Adds models from an extension provider, replacing the provider’s models.

Source

pub fn register_oauth(&mut self, provider: &str, flow: Arc<dyn OAuthProvider>)

Uses flow for provider’s sign-in and refresh, replacing the built-in.

Source

pub fn oauth_flow(&self, provider: &str) -> Option<Arc<dyn OAuthProvider>>

The sign-in for provider: a registered one, a models.json Radius gateway’s, else yapi’s built-in.

Source

pub fn radius_gateway(&self, provider: &str) -> Option<String>

The gateway of a models.json provider with "oauth": "radius": its base URL without a trailing /v1.

Source

pub fn set_runtime_key(&mut self, provider: &str, key: String)

Uses key for provider for this process, ahead of every stored credential.

Source

pub fn read_credential(&self, provider: &str) -> Option<Credential>

provider’s credential as pi’s RuntimeCredentials.read gives it to providers: a runtime key as an API key credential, else the stored one.

Source

pub fn store(&self) -> &Arc<CredentialStore> ⓘ

The credential store behind this registry.

Source

pub fn has_auth(&self, provider: &str) -> bool

Whether some credential is configured for provider, without running commands.

Source

pub fn store_error(&self, provider: &str) -> Option<String>

pi’s failure for provider while auth.json cannot be read: requests that would consult it fail instead of using other credentials.

Source

pub fn uses_command_key(&self, provider: &str) -> bool

Whether provider’s credential comes from a !command, whose output decides whether there is a key at all.

Source

pub fn login_status(&self, provider: &str) -> Option<String>

How provider is configured, as pi’s getProviderAuthStatus labels it in /login: runtime, stored, models_json_command, models_json_key, fallback (an extension’s key), or the environment variables the key comes from. None when it is not configured.

Source

pub fn is_using_oauth(&self, provider: &str) -> bool

Whether provider authenticates with a stored OAuth credential. A runtime key takes its place.

Source

pub fn stored_credentials(&self) -> Vec<(String, CredentialKind)>

Stored credentials by provider, in file order.

Source

pub fn available(&self) -> Vec<&Model>

Models with credentials, as pi’s getAvailable. A GitHub Copilot sign-in limits its models to those the account enables, and an extension provider’s filterModels to those it keeps.

Source

pub fn available_of_all_types(&self) -> Vec<&Model>

Chat models with credentials as pi’s getAvailableOfType("chat") lists them, where a provider’s filterAllModels decides over its filterModels.

Source

pub fn known_api_key(&self, provider: &str) -> Option<String>

The API key a request to provider would use, when it is known without running a command or signing in: a runtime key, a stored or configured template value, or the environment.

Source

pub async fn auth(&self, model: &Model) -> Auth

Credentials for a request to model, with its configured headers. A stored OAuth token about to expire is refreshed first.

Source

pub async fn auth_valid_for( &self, model: &Model, min_validity_ms: Option<u64>, ) -> Auth

ModelRegistry::auth with pi’s minOAuthValidityMs: a stored OAuth token valid for less than five minutes or min_validity_ms is refreshed first, and with min_validity_ms a refreshed token valid for less than that is an error.

Source

pub fn provider_name(&self, provider: &str) -> String

The display name of a provider: its models.json or extension name, else the built-in name, else the name of its registered sign-in, else its id.

Source

pub fn provider_config(&self, provider: &str) -> Option<&ProviderConfig>

The models.json or extension configuration of provider.

Source

pub fn registered_by_extension(&self, provider: &str) -> bool

Whether an extension registered provider.

Source

pub fn auth_header(&self, provider: &str) -> bool

Whether models.json or an extension sets authHeader for provider.

Source

pub fn configures_api_key(&self, provider: &str) -> bool

Whether models.json or an extension configures an apiKey for provider, even an empty one.

Source

pub async fn login( &self, provider: &str, kind: LoginKind, interaction: &Interaction, options: &LoginOptions, ) -> Result<Credential, AuthError>

Runs a sign-in and stores the credential. An API key login asks for the key, with an extension provider’s own login when it has one, and an OAuth login runs the provider’s flow.

Source

pub async fn logout(&self, provider: &str) -> Result<(), AuthError>

Removes provider’s stored credential.

Source

pub fn auth_path(&self) -> Option<&Path>

Where auth.json lives.

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> Same for T

Source§

type Output = T

Should always be Self
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