类 DashScopeChatModel.Builder
- 封闭类:
DashScopeChatModel
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明Sets the API key for DashScope authentication.Sets a custom base URL for DashScope API.build()Builds the DashScopeChatModel instance.defaultOptions(GenerateOptions options) Sets the default generation options.enableEncrypt(boolean enableEncrypt) Sets whether encryption should be enabled.enableSearch(Boolean enableSearch) Sets whether search enhancement should be enabled.enableThinking(Boolean enableThinking) Sets whether thinking mode should be enabled.endpointType(EndpointType endpointType) Sets the endpoint type to use for endpoint routing.Sets the message formatter to use.httpTransport(HttpTransport httpTransport) Sets the HTTP transport to use.Sets the model name to use.stream(boolean stream) Sets whether streaming should be enabled.
-
构造器详细资料
-
Builder
public Builder()
-
-
方法详细资料
-
apiKey
Sets the API key for DashScope authentication.- 参数:
apiKey- the API key- 返回:
- this builder instance
-
modelName
Sets the model name to use.The model name determines which API is used when endpointType is AUTO.
- 参数:
modelName- the model name (e.g., "qwen-max", "qwen-vl-plus")- 返回:
- this builder instance
- 另请参阅:
-
stream
Sets whether streaming should be enabled.This setting is ignored if enableThinking is set to true, as thinking mode automatically enables streaming.
- 参数:
stream- true to enable streaming, false for non-streaming- 返回:
- this builder instance
-
enableThinking
Sets whether thinking mode should be enabled.When enabled, this automatically enables streaming and may override the stream setting. Thinking mode allows the model to show its reasoning process.
- 参数:
enableThinking- true to enable thinking mode, false to disable, null for default- 返回:
- this builder instance
-
enableSearch
Sets whether search enhancement should be enabled.When enabled, the model can access internet search to provide more up-to-date and accurate responses.
- 参数:
enableSearch- true to enable search mode, false to disable, null for default (disabled)- 返回:
- this builder instance
-
endpointType
Sets the endpoint type to use for endpoint routing.- 参数:
endpointType- the endpoint type to use (null for AUTO)- 返回:
- this builder instance
- 另请参阅:
-
defaultOptions
Sets the default generation options.- 参数:
options- the default options to use (null for defaults)- 返回:
- this builder instance
-
baseUrl
Sets a custom base URL for DashScope API.- 参数:
baseUrl- the base URL (null for default)- 返回:
- this builder instance
-
formatter
public DashScopeChatModel.Builder formatter(Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter) Sets the message formatter to use.- 参数:
formatter- the formatter (null for default DashScope formatter)- 返回:
- this builder instance
-
httpTransport
Sets the HTTP transport to use.If not set, the default transport from
HttpTransportFactorywill be used. This allows sharing a single transport instance across multiple models for better resource management.Example:
HttpTransport custom = OkHttpTransport.builder() .config(HttpTransportConfig.builder() .connectTimeout(Duration.ofSeconds(30)) .build()) .build(); DashScopeChatModel model = DashScopeChatModel.builder() .apiKey("xxx") .modelName("qwen-plus") .httpTransport(custom) .build();- 参数:
httpTransport- the HTTP transport (null for default from factory)- 返回:
- this builder instance
-
enableEncrypt
Sets whether encryption should be enabled.When enabled, the model will automatically fetch the latest RSA public key from DashScope API and use it to encrypt requests and responses using AES-GCM with RSA key exchange, following Aliyun's encryption protocol. This enables secure access to Aliyun models while complying with enterprise security policies (e.g., TLS encryption, token-based authentication).
If fetching the public key fails during build(), an exception will be thrown to prevent creating a model with incorrect encryption configuration.
Example:
DashScopeChatModel model = DashScopeChatModel.builder() .apiKey("sk-xxx") .modelName("qwen-max") .enableEncrypt(true) .build();- 参数:
enableEncrypt- true to enable encryption (will fetch public key automatically), false to disable encryption- 返回:
- this builder instance
-
build
Builds the DashScopeChatModel instance.This method ensures that the defaultOptions always has proper executionConfig applied.
If encryption is enabled, this method will automatically fetch the public key from DashScope API. If the fetch fails, an exception will be thrown.
- 返回:
- configured DashScopeChatModel instance
- 抛出:
DashScopeHttpClient.DashScopeHttpException- if encryption is enabled and public key fetching fails
-