pub struct ModelRegistry { /* private fields */ }Expand description
All known models with their configuration.
Implementations§
Source§impl ModelRegistry
impl ModelRegistry
Sourcepub fn load(agent_dir: &Path) -> ModelRegistry
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.
Sourcepub fn enable_llama(&mut self)
pub fn enable_llama(&mut self)
Adds pi’s llama.cpp provider, as its built-in extension does.
Sourcepub fn llama_enabled(&self) -> bool
pub fn llama_enabled(&self) -> bool
Whether the llama.cpp provider is present.
Sourcepub async fn llama_server(&self) -> Option<(String, Option<String>)>
pub async fn llama_server(&self) -> Option<(String, Option<String>)>
The llama.cpp server and its key, when the provider is configured.
Sourcepub async fn catalog_targets(&self) -> Vec<Target>
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.
Sourcepub fn models_store(&self) -> Option<&ModelsStore>
pub fn models_store(&self) -> Option<&ModelsStore>
Where refreshed catalogs persist, when the registry was loaded from an agent directory.
Sourcepub fn apply_catalogs(&mut self, models: IndexMap<String, ProviderModels>)
pub fn apply_catalogs(&mut self, models: IndexMap<String, ProviderModels>)
Replaces the refreshed catalogs of the providers in models.
Sourcepub async fn provider_token(&self, provider: &str) -> Option<String>
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.
Sourcepub async fn provider_level_auth(&self, provider: &str) -> Option<Auth>
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.
Sourcepub fn builtin() -> ModelRegistry
pub fn builtin() -> ModelRegistry
The catalog alone, with no files.
Sourcepub fn classifiers(&self) -> &[ClassifierModel]
pub fn classifiers(&self) -> &[ClassifierModel]
Every classifier model, built-in and refreshed.
Sourcepub fn image_models(&self) -> &[ImageModel]
pub fn image_models(&self) -> &[ImageModel]
Every image-generation model, built-in and refreshed.
Sourcepub fn available_classifiers(&self) -> Vec<&ClassifierModel>
pub fn available_classifiers(&self) -> Vec<&ClassifierModel>
Classifier models whose providers are configured and keep them.
Sourcepub fn available_image_models(&self) -> Vec<&ImageModel>
pub fn available_image_models(&self) -> Vec<&ImageModel>
Image models whose providers are configured and keep them.
Sourcepub async fn classify(
&self,
model: &ClassifierModel,
context: &ClassifierContext,
options: ClassifyOptions,
) -> ClassifierResult
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.
Sourcepub async fn generate_images(
&self,
model: &ImageModel,
context: &ImagesContext,
options: ImagesOptions,
) -> AssistantImages
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.
Sourcepub fn register_config(&mut self, provider: &str, config: ProviderConfig)
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).
Sourcepub fn is_extension_provider(&self, provider: &str) -> bool
pub fn is_extension_provider(&self, provider: &str) -> bool
Whether an extension registered provider and has not unregistered it.
Sourcepub fn unregister_provider(&mut self, provider: &str)
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.
Sourcepub fn replace_models(
&mut self,
provider: &str,
models: Vec<ModelDefinition>,
) -> Result<(), String>
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.
Sourcepub fn register_operations(
&mut self,
provider: &str,
apis: impl IntoIterator<Item = String>,
implementation: Arc<dyn ModelOperations>,
)
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).
Sourcepub fn register_key_auth(&mut self, provider: &str, auth: Arc<dyn KeyAuth>)
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.
Sourcepub fn key_auth(&self, provider: &str) -> Option<&Arc<dyn KeyAuth>>
pub fn key_auth(&self, provider: &str) -> Option<&Arc<dyn KeyAuth>>
provider’s API-key auth from an extension, if it has one.
Sourcepub fn set_availability(&mut self, provider: &str, availability: Availability)
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.
Sourcepub fn modify_models(&mut self, provider: &str, models: Option<Vec<Model>>)
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.
Sourcepub async fn refresh_credential(&self, provider: &str) -> Option<Credential>
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.
Sourcepub fn register_provider(&mut self, provider: &str, models: Vec<Model>)
pub fn register_provider(&mut self, provider: &str, models: Vec<Model>)
Adds models from an extension provider, replacing the provider’s models.
Sourcepub fn register_oauth(&mut self, provider: &str, flow: Arc<dyn OAuthProvider>)
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.
Sourcepub fn oauth_flow(&self, provider: &str) -> Option<Arc<dyn OAuthProvider>>
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.
Sourcepub fn radius_gateway(&self, provider: &str) -> Option<String>
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.
Sourcepub fn set_runtime_key(&mut self, provider: &str, key: String)
pub fn set_runtime_key(&mut self, provider: &str, key: String)
Uses key for provider for this process, ahead of every stored credential.
Sourcepub fn read_credential(&self, provider: &str) -> Option<Credential>
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.
Sourcepub fn store(&self) -> &Arc<CredentialStore> ⓘ
pub fn store(&self) -> &Arc<CredentialStore> ⓘ
The credential store behind this registry.
Sourcepub fn has_auth(&self, provider: &str) -> bool
pub fn has_auth(&self, provider: &str) -> bool
Whether some credential is configured for provider, without running
commands.
Sourcepub fn store_error(&self, provider: &str) -> Option<String>
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.
Sourcepub fn uses_command_key(&self, provider: &str) -> bool
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.
Sourcepub fn login_status(&self, provider: &str) -> Option<String>
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.
Sourcepub fn is_using_oauth(&self, provider: &str) -> bool
pub fn is_using_oauth(&self, provider: &str) -> bool
Whether provider authenticates with a stored OAuth credential. A
runtime key takes its place.
Sourcepub fn stored_credentials(&self) -> Vec<(String, CredentialKind)>
pub fn stored_credentials(&self) -> Vec<(String, CredentialKind)>
Stored credentials by provider, in file order.
Sourcepub fn available(&self) -> Vec<&Model>
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.
Sourcepub fn available_of_all_types(&self) -> Vec<&Model>
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.
Sourcepub fn known_api_key(&self, provider: &str) -> Option<String>
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.
Sourcepub async fn auth(&self, model: &Model) -> Auth
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.
Sourcepub async fn auth_valid_for(
&self,
model: &Model,
min_validity_ms: Option<u64>,
) -> Auth
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.
Sourcepub fn provider_name(&self, provider: &str) -> String
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.
Sourcepub fn provider_config(&self, provider: &str) -> Option<&ProviderConfig>
pub fn provider_config(&self, provider: &str) -> Option<&ProviderConfig>
The models.json or extension configuration of provider.
Sourcepub fn registered_by_extension(&self, provider: &str) -> bool
pub fn registered_by_extension(&self, provider: &str) -> bool
Whether an extension registered provider.
Sourcepub fn auth_header(&self, provider: &str) -> bool
pub fn auth_header(&self, provider: &str) -> bool
Whether models.json or an extension sets authHeader for provider.
Sourcepub fn configures_api_key(&self, provider: &str) -> bool
pub fn configures_api_key(&self, provider: &str) -> bool
Whether models.json or an extension configures an apiKey for
provider, even an empty one.
Sourcepub async fn login(
&self,
provider: &str,
kind: LoginKind,
interaction: &Interaction,
options: &LoginOptions,
) -> Result<Credential, AuthError>
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.