类 ModelRegistry
java.lang.Object
io.agentscope.core.model.ModelRegistry
Registry for resolving
Model instances from string identifiers (named instances or
provider:model patterns). User-registered factories take precedence over providers
loaded from the ModelProvider SPI.
Provider extension modules read API keys from their own standard environment variables when auto-creating models.
-
嵌套类概要
嵌套类修饰符和类型类说明static interfacestatic interface -
方法概要
修饰符和类型方法说明static booleancanResolve(String modelId) Returnstrueifresolve(String)can find a named model or a matching factory/ provider pattern (without creating an instance).static booleancanResolve(String modelId, ModelCreationContext context) Returnstrueifresolve(String, ModelCreationContext)can find a named model or a matching factory/provider pattern (without creating an instance).static voidRegisters a namedModelinstance.static voidregisterFactory(String modelNameRegex, ModelRegistry.ContextModelFactory factory) Registers a context-aware factory matched against the fullmodelIdstring usingPattern.matches(java.lang.String, java.lang.CharSequence).static voidregisterFactory(String modelNameRegex, ModelRegistry.ModelFactory factory) Registers a factory matched against the fullmodelIdstring usingPattern.matches(java.lang.String, java.lang.CharSequence).static voidClears the cached SPI providers so the next resolution can rediscover providers from the current classloader context.static voidreset()Clears named models, user-registered factories, the factory-resolution cache, and cached SPI providers.static ModelResolves aModelfor the given id: named registration first, then cached factory-created instance, then user factories (newest first), then SPI providers.static Modelresolve(String modelId, ModelCreationContext context) Resolves aModelfor the given id and creation context: named registration first, then cache when enabled, then user factories (newest first), then SPI providers.
-
方法详细资料
-
register
Registers a namedModelinstance.resolve(String)returns this instance for an exactnamematch (no caching of factory-created instances applies). -
registerFactory
Registers a factory matched against the fullmodelIdstring usingPattern.matches(java.lang.String, java.lang.CharSequence). Newly registered factories are consulted before older user registrations and before SPI providers.- 参数:
modelNameRegex- regex with semantics of Pattern#matches(CharSequence) on the full model idfactory- creates aModelfrom the full model id
-
registerFactory
public static void registerFactory(String modelNameRegex, ModelRegistry.ContextModelFactory factory) Registers a context-aware factory matched against the fullmodelIdstring usingPattern.matches(java.lang.String, java.lang.CharSequence). Newly registered factories are consulted before older user registrations and before SPI providers.- 参数:
modelNameRegex- regex with semantics of Pattern#matches(CharSequence) on the full model idfactory- creates aModelfrom the full model id and creation context
-
resolve
Resolves aModelfor the given id: named registration first, then cached factory-created instance, then user factories (newest first), then SPI providers.- 抛出:
IllegalArgumentException- if the id cannot be resolved or creation fails
-
resolve
Resolves aModelfor the given id and creation context: named registration first, then cache when enabled, then user factories (newest first), then SPI providers.Non-empty context resolution is not cached unless the context uses
CachePolicy.ENABLED.- 抛出:
IllegalArgumentException- if the id cannot be resolved, the context cannot be safely cached, or creation fails
-
canResolve
Returnstrueifresolve(String)can find a named model or a matching factory/ provider pattern (without creating an instance). -
canResolve
Returnstrueifresolve(String, ModelCreationContext)can find a named model or a matching factory/provider pattern (without creating an instance). -
reset
public static void reset()Clears named models, user-registered factories, the factory-resolution cache, and cached SPI providers. Intended for tests. -
reloadProviders
public static void reloadProviders()Clears the cached SPI providers so the next resolution can rediscover providers from the current classloader context.
-