类 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 built-in
providers.
Built-in providers read API keys from standard environment variables when auto-creating
models: OPENAI_API_KEY, DASHSCOPE_API_KEY, GEMINI_API_KEY,
ANTHROPIC_API_KEY (optional for Anthropic SDK), OLLAMA_BASE_URL (optional, defaults to
http://localhost:11434).
-
嵌套类概要
嵌套类 -
方法概要
修饰符和类型方法说明static booleancanResolve(String modelId) Returnstrueifresolve(String)can find a named model or a matching factory pattern (without creating an instance).static voidRegisters a namedModelinstance.static voidregisterFactory(String modelNameRegex, ModelRegistry.ModelFactory factory) Registers a factory matched against the fullmodelIdstring usingPattern.matches(java.lang.String, java.lang.CharSequence).static voidreset()Clears named models, user-registered factories, and the factory-resolution cache.static ModelResolves aModelfor the given id: named registration first, then cached factory-created instance, then user factories (newest first), then built-in factories.
-
方法详细资料
-
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 built-in providers.- 参数:
modelNameRegex- regex with semantics of Pattern#matches(CharSequence) on the full model idfactory- creates aModelfrom the full model id
-
resolve
Resolves aModelfor the given id: named registration first, then cached factory-created instance, then user factories (newest first), then built-in factories.- 抛出:
IllegalArgumentException- if the id cannot be resolved or creation fails
-
canResolve
Returnstrueifresolve(String)can find a named model or a matching factory pattern (without creating an instance). -
reset
public static void reset()Clears named models, user-registered factories, and the factory-resolution cache. Built-in provider rules are preserved. Intended for tests.
-