类 DashScopeChatModel

java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.core.model.DashScopeChatModel
所有已实现的接口:
Model

public class DashScopeChatModel extends ChatModelBase
DashScope Chat Model using native HTTP API.

This implementation uses direct HTTP calls to DashScope API via OkHttp, without depending on the DashScope Java SDK.

Supports both text and vision models through automatic endpoint routing. Use EndpointType to explicitly control the endpoint selection.

Features:

  • Streaming and non-streaming modes
  • Tool calling support
  • Thinking mode support
  • Automatic message format conversion
  • Timeout and retry configuration
  • 构造器详细资料

    • DashScopeChatModel

      public DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, GenerateOptions defaultOptions, String baseUrl, Formatter<DashScopeMessage,DashScopeResponse,DashScopeRequest> formatter, HttpTransport httpTransport, String publicKeyId, String publicKey)
      Creates a new DashScope chat model instance with automatic API type detection.

      This constructor maintains backward compatibility. API type defaults to AUTO, which detects the endpoint based on model name.

      参数:
      apiKey - the API key for DashScope authentication
      modelName - the model name (e.g., "qwen-max", "qwen-vl-plus")
      stream - whether streaming should be enabled (ignored if enableThinking is true)
      enableThinking - whether thinking mode should be enabled (null for disabled)
      enableSearch - whether search enhancement should be enabled (null for disabled)
      defaultOptions - default generation options (null for defaults)
      baseUrl - custom base URL for DashScope API (null for default)
      formatter - the message formatter to use (null for default DashScope formatter)
      httpTransport - custom HTTP transport (null for default from factory)
      publicKeyId - the RSA public key ID for encryption (null to disable encryption)
      publicKey - the RSA public key for encryption (Base64-encoded, null to disable encryption)
    • DashScopeChatModel

      public DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, EndpointType endpointType, GenerateOptions defaultOptions, String baseUrl, Formatter<DashScopeMessage,DashScopeResponse,DashScopeRequest> formatter, HttpTransport httpTransport, String publicKeyId, String publicKey)
      Creates a new DashScope chat model instance with explicit API type.
      参数:
      apiKey - the API key for DashScope authentication
      modelName - the model name (e.g., "qwen-max", "qwen-vl-plus")
      stream - whether streaming should be enabled (ignored if enableThinking is true)
      enableThinking - whether thinking mode should be enabled (null for disabled)
      enableSearch - whether search enhancement should be enabled (null for disabled)
      endpointType - the endpoint type to use (null for AUTO detection)
      defaultOptions - default generation options (null for defaults)
      baseUrl - custom base URL for DashScope API (null for default)
      formatter - the message formatter to use (null for default DashScope formatter)
      httpTransport - custom HTTP transport (null for default from factory)
      publicKeyId - the RSA public key ID for encryption (null to disable encryption)
      publicKey - the RSA public key for encryption (Base64-encoded, null to disable encryption)
  • 方法详细资料

    • builder

      public static DashScopeChatModel.Builder builder()
      Creates a new builder for DashScopeChatModel.
      返回:
      a new Builder instance
    • doStream

      protected reactor.core.publisher.Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
      Stream chat completion responses from DashScope's API.

      This method automatically routes to the appropriate API based on the model name:

      • Vision models (qvq* or *-vl*) → MultiModal API
      • Text models → Text Generation API

      Supports timeout and retry configuration through GenerateOptions.

      指定者:
      doStream 在类中 ChatModelBase
      参数:
      messages - AgentScope messages to send to the model
      tools - Optional list of tool schemas
      options - Optional generation options (null to use defaults)
      返回:
      Flux stream of chat responses
    • getModelName

      public String getModelName()
      Gets the model name for logging and identification.
      返回:
      the model name