Class DashScopeChatModel
java.lang.Object
io.agentscope.core.model.ChatModelBase
io.agentscope.extensions.model.dashscope.DashScopeChatModel
- All Implemented Interfaces:
io.agentscope.core.model.Model
public class DashScopeChatModel
extends io.agentscope.core.model.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
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionDashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, String publicKeyId, String publicKey) Creates a new DashScope chat model instance with automatic API type detection.DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, EndpointType endpointType, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, String publicKeyId, String publicKey) Creates a new DashScope chat model instance with explicit API type.DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, EndpointType endpointType, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, String publicKeyId, String publicKey, Collection<String> multimodalModelPatterns) Creates a new DashScope chat model instance with explicit API type and additional multimodal model patterns. -
Method Summary
Modifier and TypeMethodDescriptionstatic DashScopeChatModel.Builderbuilder()Creates a new builder for DashScopeChatModel.protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse>doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.GenerateOptions options) Stream chat completion responses from DashScope's API.Gets the model name for logging and identification.booleanMethods inherited from class io.agentscope.core.model.ChatModelBase
getContextWindowSize, setContextWindowSize, setNativeStructuredOutput, setNativeStructuredOutputWithTools, stream, supportsNativeStructuredOutputWithTools
-
Constructor Details
-
DashScopeChatModel
public DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.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.
- Parameters:
apiKey- the API key for DashScope authenticationmodelName- the model name (e.g., "qwen-max", "qwen-vl-plus")stream- whether streaming should be enabledenableThinking- 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, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, String publicKeyId, String publicKey) Creates a new DashScope chat model instance with explicit API type.- Parameters:
apiKey- the API key for DashScope authenticationmodelName- the model name (e.g., "qwen-max", "qwen-vl-plus")stream- whether streaming should be enabledenableThinking- 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)
-
DashScopeChatModel
public DashScopeChatModel(String apiKey, String modelName, boolean stream, Boolean enableThinking, Boolean enableSearch, EndpointType endpointType, io.agentscope.core.model.GenerateOptions defaultOptions, String baseUrl, io.agentscope.core.formatter.Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> formatter, io.agentscope.core.model.transport.HttpTransport httpTransport, String publicKeyId, String publicKey, Collection<String> multimodalModelPatterns) Creates a new DashScope chat model instance with explicit API type and additional multimodal model patterns.- Parameters:
apiKey- the API key for DashScope authenticationmodelName- the model name (e.g., "qwen-max", "qwen-vl-plus")stream- whether streaming should be enabledenableThinking- 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)multimodalModelPatterns- case-insensitive substring patterns that extend the built-in multimodal model detection when endpointType is AUTO (null to disable)
-
-
Method Details
-
builder
Creates a new builder for DashScopeChatModel.- Returns:
- a new Builder instance
-
doStream
protected reactor.core.publisher.Flux<io.agentscope.core.model.ChatResponse> doStream(List<io.agentscope.core.message.Msg> messages, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.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.
- Specified by:
doStreamin classio.agentscope.core.model.ChatModelBase- Parameters:
messages- AgentScope messages to send to the modeltools- Optional list of tool schemasoptions- Optional generation options (null to use defaults)- Returns:
- Flux stream of chat responses
-
getModelName
Gets the model name for logging and identification.- Returns:
- the model name
-
supportsNativeStructuredOutput
public boolean supportsNativeStructuredOutput()- Specified by:
supportsNativeStructuredOutputin interfaceio.agentscope.core.model.Model- Overrides:
supportsNativeStructuredOutputin classio.agentscope.core.model.ChatModelBase
-