ModelCreationContext
public final class ModelCreationContext
io/agentscope/core/model/ModelCreationContext.java:43–290模型 Creation 上下文,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.core.model 包。核心成员包括 empty、builder、toBuilder、getApiKey、getBaseUrl、getEndpointPath。
Provider-neutral model creation context used by ModelRegistry and model provider SPI
implementations.
This type has two layers:
-
Standard fields such as
apiKey,baseUrl,endpointPath,stream, andenableThinking. These are common enough to be understood by multiple providers and can safely participate in automatic cache identity whenCachePolicy#ENABLEDis selected. -
Provider-specific options (
#option(String)) and typed components (#component(Class)). These allow extension modules to consume advanced builder settings such as formatters, HTTP transports, credentials, proxies, and default generation options without adding provider types to core.
Options and components are intentionally opaque to core. ModelRegistry never deep
hashes them or uses their hashCode() values for cache identity. When they are present and
caching is enabled, callers must provide an explicit Builder#cacheId(String).
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 A class in io.agentscope.core.model that talks to model services and returns generated or embedded output. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static ModelCreationContext empty()static | 返回 `empty` 结果。 Returns the empty. |
public static Builder builder()static | 返回构建器实例。 Returns the builder. |
public Builder toBuilder() | 返回可变构建器已初始化来自此上下文。 Returns a mutable builder initialized from this context. |
public String getApiKey() | 获取API 键。 API key or token to pass to a provider. |
public String getBaseUrl() | 获取基类 URL。 Provider base URL override, for self-hosted or compatible API endpoints. |
public String getEndpointPath() | 获取端点路径。 Provider endpoint path override, mainly for OpenAI-compatible APIs. |
public Boolean getStream() | 获取流。 Whether the created model should use streaming by default. |
public Boolean getEnableThinking() | 获取 `getEnableThinking`。 Whether provider thinking/reasoning mode should be enabled. |
public CachePolicy getCachePolicy() | 用于`ModelRegistry#resolve(String, ModelCreationContext)`的缓存策略。 Cache policy for `ModelRegistry#resolve(String, ModelCreationContext)`. |
public String getCacheId() | 获取缓存标识。 Explicit cache identity used when `#getCachePolicy()` is `CachePolicy#ENABLED`. |
public Map<String, Object> getOptions() | 获取选项。 Provider-specific scalar or value options keyed by extension-defined names. |
public Object option(String key) | 设置选项。 Returns a provider-specific option value, or `null`. |
public T T option(String key, Class<T> type) | 执行选项相关操作。 Returns a provider-specific option cast to the requested type, or `null`. |
public Map<Class<?>, Object> getComponents() | 获取 `getComponents`。 Provider-specific component objects keyed by type. |
public T T component(Class<T> type) | 设置该参数。 Returns a provider-specific component by type, or `null`. |
public boolean isEmpty() | 判断是否 `isEmpty`。 Returns whether this context has no effective settings. |
public boolean hasOpaqueCacheInputs() | 判断是否具有 `hasOpaqueCacheInputs`。 Returns whether the context contains values that core cannot fingerprint safely. |
public String toString() | 返回 `toString` 结果。 Returns the to string. |
方法详情Method Detail
empty
public static ModelCreationContext empty()
返回 empty 结果。
Returns the empty.
ModelCreationContextio/agentscope/core/model/ModelCreationContext.java:69–71builder
public static Builder builder()
返回构建器实例。
Returns the builder.
Builderio/agentscope/core/model/ModelCreationContext.java:73–75toBuilder
public Builder toBuilder()
返回可变构建器已初始化来自此上下文。
Returns a mutable builder initialized from this context.
Builderio/agentscope/core/model/ModelCreationContext.java:83–85getApiKey
public String getApiKey()
获取API 键。
API key or token to pass to a provider.
Stringio/agentscope/core/model/ModelCreationContext.java:88–90getBaseUrl
public String getBaseUrl()
获取基类 URL。
Provider base URL override, for self-hosted or compatible API endpoints.
Stringio/agentscope/core/model/ModelCreationContext.java:93–95getEndpointPath
public String getEndpointPath()
获取端点路径。
Provider endpoint path override, mainly for OpenAI-compatible APIs.
Stringio/agentscope/core/model/ModelCreationContext.java:98–100getStream
public Boolean getStream()
获取流。
Whether the created model should use streaming by default.
Booleanio/agentscope/core/model/ModelCreationContext.java:103–105getEnableThinking
public Boolean getEnableThinking()
获取 getEnableThinking。
Whether provider thinking/reasoning mode should be enabled.
Booleanio/agentscope/core/model/ModelCreationContext.java:108–110getCachePolicy
public CachePolicy getCachePolicy()
用于ModelRegistry#resolve(String, ModelCreationContext)的缓存策略。
Cache policy for ModelRegistry#resolve(String, ModelCreationContext).
CachePolicyio/agentscope/core/model/ModelCreationContext.java:113–115getCacheId
public String getCacheId()
获取缓存标识。
Explicit cache identity used when #getCachePolicy() is CachePolicy#ENABLED.
Stringio/agentscope/core/model/ModelCreationContext.java:118–120getOptions
public Map<String, Object> getOptions()
获取选项。
Provider-specific scalar or value options keyed by extension-defined names.
Map<String, Object>io/agentscope/core/model/ModelCreationContext.java:123–125option
public Object option(String key)
设置选项。
Returns a provider-specific option value, or null.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Objectio/agentscope/core/model/ModelCreationContext.java:128–130option
public T T option(String key, Class<T> type)
执行选项相关操作。
Returns a provider-specific option cast to the requested type, or null.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
type | Class<T> | 类型(类型 `Class`)。The type. |
Tio/agentscope/core/model/ModelCreationContext.java:133–136getComponents
public Map<Class<?>, Object> getComponents()
获取 getComponents。
Provider-specific component objects keyed by type.
Map<Class<?>, Object>io/agentscope/core/model/ModelCreationContext.java:139–141component
public T T component(Class<T> type)
设置该参数。
Returns a provider-specific component by type, or null.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
type | Class<T> | 类型(类型 `Class`)。The type. |
Tio/agentscope/core/model/ModelCreationContext.java:144–147isEmpty
public boolean isEmpty()
判断是否 isEmpty。
Returns whether this context has no effective settings.
booleanio/agentscope/core/model/ModelCreationContext.java:154–164hasOpaqueCacheInputs
public boolean hasOpaqueCacheInputs()
判断是否具有 hasOpaqueCacheInputs。
Returns whether the context contains values that core cannot fingerprint safely.
booleanio/agentscope/core/model/ModelCreationContext.java:167–169toString
public String toString()
返回 toString 结果。
Returns the to string.
Stringio/agentscope/core/model/ModelCreationContext.java:171–196嵌套类详情Nested Class Detail
Builder
public static final class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.core.model 包。核心成员包括 apiKey、baseUrl、endpointPath、stream、enableThinking、cachePolicy。
A class in io.agentscope.core.model that talks to model services and returns generated or embedded output. Declared in io.agentscope.core.model.