DashScopeHttpClient
public class DashScopeHttpClient
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:65–985用于DashScope API的HTTP 客户端。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 isEncryptionEnabled、call、stream、selectEndpoint、isMultimodalModel、requiresMultimodalApi。
HTTP client for DashScope API.
This client handles communication with DashScope's text-generation and multimodal-generation APIs using the native DashScope protocol.
Features:
-
Automatic API endpoint routing based on model name
-
Synchronous and streaming request support
-
SSE stream parsing
-
JSON serialization/deserialization
API endpoints:
-
Text generation: /api/v1/services/aigc/text-generation/generation
-
Multimodal generation: /api/v1/services/aigc/multimodal-generation/generation
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
PublicKeyResult | 记录record | 承载 Public 键结果数据的记录类型。 Result of fetching a public key from DashScope API. |
Builder | 类class | DashScopeHttpClient的构建器。 Builder for DashScopeHttpClient. |
DashScopeHttpException | 类class | DashScope HTTP 异常,表示执行过程中的错误。 Exception thrown when DashScope HTTP operations fail. |
字段摘要Field Summary
| 字段Field | 类型Type | 说明Description |
|---|---|---|
DEFAULT_BASE_URLstaticfinal | String | 用于DashScope API的默认基类 URL。 Default base URL for DashScope API. |
TEXT_GENERATION_ENDPOINTstaticfinal | String | 文本 GENERATION 端点字段。 Text generation API endpoint. |
MULTIMODAL_GENERATION_ENDPOINTstaticfinal | String | 多模态 GENERATION 端点字段。 Multimodal generation API endpoint. |
PUBLIC_KEYS_ENDPOINTstaticfinal | String | PUBLIC 密钥端点字段。 Public keys API endpoint. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey) | 创建新的DashScopeHttpClient。 Create a new DashScopeHttpClient. |
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey, Collection<String> userMultimodalPatterns) | 初始化 `DashScopeHttpClient` 实例。 Create a new DashScopeHttpClient with user-supplied multimodal model patterns. |
public DashScopeHttpClient(String apiKey, String baseUrl) | 创建新的DashScopeHttpClient。 Create a new DashScopeHttpClient. |
public DashScopeHttpClient(String apiKey, String baseUrl, String publicKeyId, String publicKey) | 创建新的DashScopeHttpClient 使用默认传输层来自工厂。 Create a new DashScopeHttpClient with default transport from factory. |
public DashScopeHttpClient(String apiKey) | 创建新的DashScopeHttpClient 使用默认传输层和基类 URL。 Create a new DashScopeHttpClient with default transport and base URL. |
方法摘要Method Summary
字段详情Field Detail
DEFAULT_BASE_URL
public static final String DEFAULT_BASE_URL
用于DashScope API的默认基类 URL。
Default base URL for DashScope API.
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:70TEXT_GENERATION_ENDPOINT
public static final String TEXT_GENERATION_ENDPOINT
文本 GENERATION 端点字段。声明为 public static final String TEXT_GENERATION_ENDPOINT。
Text generation API endpoint.
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:73–74MULTIMODAL_GENERATION_ENDPOINT
public static final String MULTIMODAL_GENERATION_ENDPOINT
多模态 GENERATION 端点字段。声明为 public static final String MULTIMODAL_GENERATION_ENDPOINT。
Multimodal generation API endpoint.
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:77–78PUBLIC_KEYS_ENDPOINT
public static final String PUBLIC_KEYS_ENDPOINT
PUBLIC 密钥端点字段。声明为 public static final String PUBLIC_KEYS_ENDPOINT。
Public keys API endpoint.
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:81构造器详情Constructor Detail
DashScopeHttpClient
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey)
创建新的DashScopeHttpClient。
Create a new DashScopeHttpClient.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
transport | HttpTransport | HTTP 传输层到使用。the HTTP transport to use |
apiKey | String | DashScope API 密钥。the DashScope API key |
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
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/DashScopeHttpClient.java:99–106DashScopeHttpClient
public DashScopeHttpClient(HttpTransport transport, String apiKey, String baseUrl, String publicKeyId, String publicKey, Collection<String> userMultimodalPatterns)
初始化 DashScopeHttpClient 实例。
Create a new DashScopeHttpClient with user-supplied multimodal model patterns.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
transport | HttpTransport | HTTP 传输层到使用。the HTTP transport to use |
apiKey | String | DashScope API 密钥。the DashScope API key |
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
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) |
userMultimodalPatterns | Collection<String> | 用户多模态 Patterns(类型 `Collection`)。case-insensitive substring patterns that extend the built-in multimodal model detection (null or empty to disable) |
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:119–135DashScopeHttpClient
public DashScopeHttpClient(String apiKey, String baseUrl)
创建新的DashScopeHttpClient。
Create a new DashScopeHttpClient.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | DashScope API 密钥。the DashScope API key |
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:153–155DashScopeHttpClient
public DashScopeHttpClient(String apiKey, String baseUrl, String publicKeyId, String publicKey)
创建新的DashScopeHttpClient 使用默认传输层来自工厂。
Create a new DashScopeHttpClient with default transport from factory.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | DashScope API 密钥。the DashScope API key |
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
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/DashScopeHttpClient.java:168–171DashScopeHttpClient
public DashScopeHttpClient(String apiKey)
创建新的DashScopeHttpClient 使用默认传输层和基类 URL。
Create a new DashScopeHttpClient with default transport and base URL.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | DashScope API 密钥。the DashScope API key |
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:178–180方法详情Method Detail
isEncryptionEnabled
public boolean isEncryptionEnabled()
判断是否 isEncryptionEnabled。
Check if encryption is enabled.
booleanio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:187–192call
public DashScopeResponse call(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams)
向智能体发送输入并返回最终回复。
Make a synchronous API call with additional HTTP parameters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | DashScopeRequest | DashScope 请求。the DashScope request |
additionalHeaders | Map<String, String> | additional 请求头(类型 `Map`)。additional HTTP headers to merge (may be null) |
additionalBodyParams | Map<String, Object> | additional 正文参数(类型 `Map`)。additional body parameters to merge (may be null) |
additionalQueryParams | Map<String, String> | additional 查询参数(类型 `Map`)。additional query parameters to append (may be null) |
DashScopeResponseDashScopeHttpException可能抛出 `DashScopeHttpException`。if the request fails
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:204–266stream
public Flux<DashScopeResponse> stream(DashScopeRequest request, Map<String, String> additionalHeaders, Map<String, Object> additionalBodyParams, Map<String, String> additionalQueryParams)
执行流相关操作。
Make a streaming API call with additional HTTP parameters.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | DashScopeRequest | DashScope 请求。the DashScope request |
additionalHeaders | Map<String, String> | additional 请求头(类型 `Map`)。additional HTTP headers to merge (may be null) |
additionalBodyParams | Map<String, Object> | additional 正文参数(类型 `Map`)。additional body parameters to merge (may be null) |
additionalQueryParams | Map<String, String> | additional 查询参数(类型 `Map`)。additional query parameters to append (may be null) |
Flux<DashScopeResponse>io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:277–349selectEndpoint
public String selectEndpoint(String modelName)
设置选择端点。
Select the appropriate API endpoint based on model name.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称。the model name |
Stringio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:359–361selectEndpoint
public String selectEndpoint(String modelName, EndpointType endpointType)
执行选择端点相关操作。
Select the appropriate API endpoint based on model name and endpoint type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称。the model name |
endpointType | EndpointType | 端点类型(类型 `EndpointType`)。the endpoint type to use (AUTO for automatic detection) |
Stringio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:383–402isMultimodalModel
public static boolean isMultimodalModel(String modelName)
判断是否多模态模型。
Check if a model is a multimodal model that requires the multimodal-generation API.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称。the model name |
booleanio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:432–453requiresMultimodalApi
public boolean requiresMultimodalApi(String modelName)
设置该参数。
Check if a model requires the multimodal API.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称。the model name |
booleanio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:463–465requiresMultimodalApi
public boolean requiresMultimodalApi(String modelName, EndpointType endpointType)
执行 requiresMultimodalApi 方法。
Check if a model requires the multimodal API based on the specified endpoint type.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
modelName | String | 模型名称。the model name |
endpointType | EndpointType | 端点类型到使用。the endpoint type to use |
booleanio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:474–483fetchPublicKey
public static PublicKeyResult fetchPublicKey(String apiKey, String baseUrl, HttpTransport transport)
执行 fetchPublicKey 方法。
Fetch the latest RSA public key from DashScope API.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
apiKey | String | DashScope API 密钥。the DashScope API key |
baseUrl | String | 基类 URL(类型 `String`)。the base URL (null for default) |
transport | HttpTransport | HTTP 传输层到使用。the HTTP transport to use |
PublicKeyResultDashScopeHttpException可能抛出 `DashScopeHttpException`。if the request fails
io/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:521–569getBaseUrl
public String getBaseUrl()
获取基类 URL。
Get the base URL.
Stringio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:803–805builder
public static Builder builder()
创建用于DashScopeHttpClient的构建器。
Create a new builder for DashScopeHttpClient.
Builderio/agentscope/extensions/model/dashscope/DashScopeHttpClient.java:812–814嵌套类详情Nested Class Detail
PublicKeyResult
public record PublicKeyResult(String publicKeyId, String publicKey)承载 Public 键结果数据的记录类型。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 publicKeyId、publicKey。
Result of fetching a public key from DashScope API.
Builder
public static class BuilderDashScopeHttpClient的构建器。位于 io.agentscope.extensions.model.dashscope 包。核心成员包括 transport、apiKey、baseUrl、publicKeyId、publicKey、multimodalModelPatterns。
Builder for DashScopeHttpClient.
DashScopeHttpException
public static class DashScopeHttpException extends RuntimeExceptionDashScope HTTP 异常,表示执行过程中的错误。位于 io.agentscope.extensions.model.dashscope 包,继承自 RuntimeException。核心成员包括 getStatusCode、getErrorCode、getResponseBody、DashScopeHttpException。
Exception thrown when DashScope HTTP operations fail.