ModelRegistry
public final class ModelRegistry
io/agentscope/core/model/ModelRegistry.java:44–428模型注册表,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 register、registerFactory、resolve、canResolve、reset、reloadProviders。
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.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
ModelFactory | 接口interface | 定义模型工厂契约的接口。 An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. |
ContextModelFactory | 接口interface | 定义上下文模型工厂契约的接口。 An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static void register(String name, Model model)static | 执行注册相关操作。 Registers a named `Model` instance. |
public static void registerFactory(String modelNameRegex, ModelFactory factory)static | 注册工厂。 Registers a factory matched against the full `modelId` string using `Pattern#matches`. |
public static void registerFactory(String modelNameRegex, ContextModelFactory factory)static | 注册工厂。 Registers a context-aware factory matched against the full `modelId` string using
`Pattern#matches`. |
public static Model resolve(String modelId)static | 设置解析。 Resolves a `Model` for the given id: named registration first, then cached
factory-created instance, then user factories (newest first), then SPI providers. |
public static Model resolve(String modelId, ModelCreationContext context)static | 执行解析相关操作。 Resolves a `Model` for the given id and creation context: named registration first,
then cache when enabled, then user factories (newest first), then SPI providers. |
public static boolean canResolve(String modelId)static | 判断是否可以解析。 Returns `true` if `#resolve(String)` can find a named model or a matching factory/
provider pattern (without creating an instance). |
public static boolean canResolve(String modelId, ModelCreationContext context)static | 判断是否可以解析。 Returns `true` if `#resolve(String, ModelCreationContext)` can find a named model
or a matching factory/provider pattern (without creating an instance). |
public static void reset()static | 清空或重置内部状态。 Clears named models, user-registered factories, the factory-resolution cache,
and cached SPI providers. |
public static void reloadProviders()static | 执行 `reloadProviders` 方法。 Clears the cached SPI providers so the next resolution can rediscover providers from the
current classloader context. |
方法详情Method Detail
register
public static void register(String name, Model model)
执行注册相关操作。
Registers a named Model instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
name | String | 名称(类型 `String`)。The name. |
model | Model | 模型实例(类型 `Model`)。The model. |
io/agentscope/core/model/ModelRegistry.java:61–65registerFactory
public static void registerFactory(String modelNameRegex, ModelFactory factory)
注册工厂。
Registers a factory matched against the full modelId string using Pattern#matches.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelNameRegex | String | 模型名称 Regex(类型 `String`)。regex with semantics of Pattern#matches(CharSequence) on the full model id |
factory | ModelFactory | 工厂(类型 `ModelFactory`)。creates a `Model` from the full model id |
io/agentscope/core/model/ModelRegistry.java:76–80registerFactory
public static void registerFactory(String modelNameRegex, ContextModelFactory factory)
注册工厂。
Registers a context-aware factory matched against the full modelId string using Pattern#matches.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelNameRegex | String | 模型名称 Regex(类型 `String`)。regex with semantics of Pattern#matches(CharSequence) on the full model id |
factory | ContextModelFactory | 工厂(类型 `ContextModelFactory`)。creates a `Model` from the full model id and creation context |
io/agentscope/core/model/ModelRegistry.java:91–96resolve
public static Model resolve(String modelId)
设置解析。
Resolves a Model for the given id: named registration first, then cached factory-created instance, then user factories (newest first), then SPI providers.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。The model id. |
ModelIllegalArgumentException可能抛出 `IllegalArgumentException`。if the id cannot be resolved or creation fails
io/agentscope/core/model/ModelRegistry.java:104–106resolve
public static Model resolve(String modelId, ModelCreationContext context)
执行解析相关操作。
Resolves a Model for the given id and creation context: named registration first, then cache when enabled, then user factories (newest first), then SPI providers.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。The model id. |
context | ModelCreationContext | 上下文(类型 `ModelCreationContext`)。The context. |
ModelIllegalArgumentException可能抛出 `IllegalArgumentException`。if the id cannot be resolved, the context cannot be safely cached, or creation fails
io/agentscope/core/model/ModelRegistry.java:118–167canResolve
public static boolean canResolve(String modelId)
判断是否可以解析。
Returns true if #resolve(String) can find a named model or a matching factory/ provider pattern (without creating an instance).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。The model id. |
booleanio/agentscope/core/model/ModelRegistry.java:173–175canResolve
public static boolean canResolve(String modelId, ModelCreationContext context)
判断是否可以解析。
Returns true if #resolve(String, ModelCreationContext) can find a named model or a matching factory/provider pattern (without creating an instance).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelId | String | 模型标识(类型 `String`)。The model id. |
context | ModelCreationContext | 上下文(类型 `ModelCreationContext`)。The context. |
booleanio/agentscope/core/model/ModelRegistry.java:181–195reset
public static void reset()
清空或重置内部状态。
Clears named models, user-registered factories, the factory-resolution cache, and cached SPI providers.
io/agentscope/core/model/ModelRegistry.java:201–206reloadProviders
public static void reloadProviders()
执行 reloadProviders 方法。
Clears the cached SPI providers so the next resolution can rediscover providers from the current classloader context.
io/agentscope/core/model/ModelRegistry.java:212–214嵌套类详情Nested Class Detail
ModelFactory
@FunctionalInterface public interface ModelFactory定义模型工厂契约的接口。位于 io.agentscope.core.model 包。核心成员包括 create。
An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.
ContextModelFactory
@FunctionalInterface public interface ContextModelFactory定义上下文模型工厂契约的接口。位于 io.agentscope.core.model 包。核心成员包括 create。
An interface in io.agentscope.core.model that defines the contract for components that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.