类 DashScopeChatModel.Builder

java.lang.Object
io.agentscope.core.model.DashScopeChatModel.Builder
封闭类:
DashScopeChatModel

public static class DashScopeChatModel.Builder extends Object
  • 构造器详细资料

    • Builder

      public Builder()
  • 方法详细资料

    • apiKey

      public DashScopeChatModel.Builder apiKey(String apiKey)
      Sets the API key for DashScope authentication.
      参数:
      apiKey - the API key
      返回:
      this builder instance
    • modelName

      public DashScopeChatModel.Builder modelName(String 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

      public DashScopeChatModel.Builder stream(boolean 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

      public DashScopeChatModel.Builder enableThinking(Boolean 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

      public DashScopeChatModel.Builder enableSearch(Boolean 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

      public DashScopeChatModel.Builder endpointType(EndpointType endpointType)
      Sets the endpoint type to use for endpoint routing.
      参数:
      endpointType - the endpoint type to use (null for AUTO)
      返回:
      this builder instance
      另请参阅:
    • defaultOptions

      public DashScopeChatModel.Builder defaultOptions(GenerateOptions options)
      Sets the default generation options.
      参数:
      options - the default options to use (null for defaults)
      返回:
      this builder instance
    • baseUrl

      public DashScopeChatModel.Builder baseUrl(String baseUrl)
      Sets a custom base URL for DashScope API.
      参数:
      baseUrl - the base URL (null for default)
      返回:
      this builder instance
    • formatter

      Sets the message formatter to use.
      参数:
      formatter - the formatter (null for default DashScope formatter)
      返回:
      this builder instance
    • httpTransport

      public DashScopeChatModel.Builder httpTransport(HttpTransport httpTransport)
      Sets the HTTP transport to use.

      If not set, the default transport from HttpTransportFactory will 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

      public DashScopeChatModel.Builder enableEncrypt(boolean 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

      public DashScopeChatModel 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