DashScopeChatModel
public class DashScopeChatModel extends ChatModelBase
io/agentscope/extensions/model/dashscope/DashScopeChatModel.java:65–841DashScope 聊天模型,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.dashscope 包,继承自 ChatModelBase。核心成员包括 builder、doStream、getModelName、supportsNativeStructuredOutput、DashScopeChatModel。
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
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Builder | 类class | 构建器,用于构建并配置目标实例。 A class in io.agentscope.extensions.model.dashscope that talks to model services and returns generated or embedded output. |
构造器摘要Constructor Summary
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public static Builder builder()static | 创建新的构建器用于 DashScopeChatModel。 Creates a new builder for DashScopeChatModel. |
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) | 以流式方式执行并返回结果。 Stream chat completion responses from DashScope's API. |
public String getModelName() | 获取模型名称。 Gets the model name for logging and identification. |
public boolean supportsNativeStructuredOutput() | 返回支持原生结构化输出。 Returns the supports native structured output. |
构造器详情Constructor Detail
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)
初始化 DashScopeChatModel 实例。
Creates a new DashScope chat model instance with automatic API type detection.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | API 键(类型 `String`)。the API key for DashScope authentication |
modelName | String | 模型名称(类型 `String`)。the model name (e.g., "qwen-max", "qwen-vl-plus") |
stream | boolean | 流(类型 `boolean`)。whether streaming should be enabled |
enableThinking | Boolean | 启用 Thinking(类型 `Boolean`)。whether thinking mode should be enabled (null for disabled) |
enableSearch | Boolean | 启用搜索(类型 `Boolean`)。whether search enhancement should be enabled (null for disabled) |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。default generation options (null for defaults) |
baseUrl | String | 基类 URL(类型 `String`)。custom base URL for DashScope API (null for default) |
formatter | Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> | 格式化器(类型 `Formatter`)。the message formatter to use (null for default DashScope formatter) |
httpTransport | HttpTransport | HTTP 传输层(类型 `HttpTransport`)。custom HTTP transport (null for default from factory) |
publicKeyId | String | public 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption) |
publicKey | String | public 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption) |
io/agentscope/extensions/model/dashscope/DashScopeChatModel.java:98–123DashScopeChatModel
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)
初始化 DashScopeChatModel 实例。
Creates a new DashScope chat model instance with explicit API type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | API 键(类型 `String`)。the API key for DashScope authentication |
modelName | String | 模型名称(类型 `String`)。the model name (e.g., "qwen-max", "qwen-vl-plus") |
stream | boolean | 流(类型 `boolean`)。whether streaming should be enabled |
enableThinking | Boolean | 启用 Thinking(类型 `Boolean`)。whether thinking mode should be enabled (null for disabled) |
enableSearch | Boolean | 启用搜索(类型 `Boolean`)。whether search enhancement should be enabled (null for disabled) |
endpointType | EndpointType | 端点类型(类型 `EndpointType`)。the endpoint type to use (null for AUTO detection) |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。default generation options (null for defaults) |
baseUrl | String | 基类 URL(类型 `String`)。custom base URL for DashScope API (null for default) |
formatter | Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> | 格式化器(类型 `Formatter`)。the message formatter to use (null for default DashScope formatter) |
httpTransport | HttpTransport | HTTP 传输层(类型 `HttpTransport`)。custom HTTP transport (null for default from factory) |
publicKeyId | String | public 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption) |
publicKey | String | public 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption) |
io/agentscope/extensions/model/dashscope/DashScopeChatModel.java:141–168DashScopeChatModel
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, Collection<String> multimodalModelPatterns)
初始化 DashScopeChatModel 实例。
Creates a new DashScope chat model instance with explicit API type and additional multimodal model patterns.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | API 键(类型 `String`)。the API key for DashScope authentication |
modelName | String | 模型名称(类型 `String`)。the model name (e.g., "qwen-max", "qwen-vl-plus") |
stream | boolean | 流(类型 `boolean`)。whether streaming should be enabled |
enableThinking | Boolean | 启用 Thinking(类型 `Boolean`)。whether thinking mode should be enabled (null for disabled) |
enableSearch | Boolean | 启用搜索(类型 `Boolean`)。whether search enhancement should be enabled (null for disabled) |
endpointType | EndpointType | 端点类型(类型 `EndpointType`)。the endpoint type to use (null for AUTO detection) |
defaultOptions | GenerateOptions | 默认选项(类型 `GenerateOptions`)。default generation options (null for defaults) |
baseUrl | String | 基类 URL(类型 `String`)。custom base URL for DashScope API (null for default) |
formatter | Formatter<DashScopeMessage, DashScopeResponse, DashScopeRequest> | 格式化器(类型 `Formatter`)。the message formatter to use (null for default DashScope formatter) |
httpTransport | HttpTransport | HTTP 传输层(类型 `HttpTransport`)。custom HTTP transport (null for default from factory) |
publicKeyId | String | public 键标识(类型 `String`)。the RSA public key ID for encryption (null to disable encryption) |
publicKey | String | public 键(类型 `String`)。the RSA public key for encryption (Base64-encoded, null to disable encryption) |
multimodalModelPatterns | Collection<String> | 多模态模型 Patterns(类型 `Collection`)。case-insensitive substring patterns that extend the built-in multimodal model detection when endpointType is AUTO (null to disable) |
io/agentscope/extensions/model/dashscope/DashScopeChatModel.java:189–226方法详情Method Detail
builder
public static Builder builder()
创建新的构建器用于 DashScopeChatModel。
Creates a new builder for DashScopeChatModel.
Builderio/agentscope/extensions/model/dashscope/DashScopeChatModel.java:233–235doStream
protected Flux<ChatResponse> doStream(List<Msg> messages, List<ToolSchema> tools, GenerateOptions options)
以流式方式执行并返回结果。
Stream chat completion responses from DashScope's API.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
messages | List<Msg> | 消息列表(类型 `List`)。AgentScope messages to send to the model |
tools | List<ToolSchema> | 工具模式的可选列出。Optional list of tool schemas |
options | GenerateOptions | 选项(类型 `GenerateOptions`)。Optional generation options (null to use defaults) |
Flux<ChatResponse>io/agentscope/extensions/model/dashscope/DashScopeChatModel.java:253–271getModelName
public String getModelName()
获取模型名称。
Gets the model name for logging and identification.
Stringio/agentscope/extensions/model/dashscope/DashScopeChatModel.java:427–430supportsNativeStructuredOutput
public boolean supportsNativeStructuredOutput()
返回支持原生结构化输出。
Returns the supports native structured output.
booleanio/agentscope/extensions/model/dashscope/DashScopeChatModel.java:432–438嵌套类详情Nested Class Detail
Builder
public static class Builder构建器,用于构建并配置目标实例。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 apiKey、modelName、stream、enableThinking、enableSearch、endpointType。
A class in io.agentscope.extensions.model.dashscope that talks to model services and returns generated or embedded output. Declared in io.agentscope.extensions.model.dashscope.