Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<name>DashScope Java SDK</name>
<groupId>com.alibaba</groupId>
<artifactId>dashscope-sdk-java</artifactId>
<version>2.23.4</version>
<version>2.23.5</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/alibaba/dashscope/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
package com.alibaba.dashscope;

public final class Version {
public static final String version = "2.23.4";
public static final String version = "2.23.5";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alibaba.dashscope.agentstudio.message.Message;
import com.alibaba.dashscope.common.Status;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.protocol.DashScopeHeaders;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -92,6 +93,7 @@ private static ApiException wrapFailure(Throwable t, Response response) {
return null;
}
int code = response.code();
String requestId = DashScopeHeaders.findRequestId(response.headers().toMultimap());
String body = "";
String errorCode = null;
String errorMsg = null;
Expand All @@ -100,24 +102,34 @@ private static ApiException wrapFailure(Throwable t, Response response) {
body = rb.string();
}
} catch (IOException e) {
log.debug("Failed to read SSE failure response body", e);
log.debug(
"Failed to read SSE failure response body, requestId={}",
DashScopeHeaders.requestIdOrUnknown(requestId),
e);
}
// Parse the agentstudio error envelope {type:error, error:{code,message}}
// to surface the server's actual error code instead of a generic one.
if (body != null && !body.isEmpty()) {
try {
JsonObject parsed = GSON.fromJson(body, JsonObject.class);
if (parsed != null && parsed.has("request_id")) {
requestId = parsed.get("request_id").getAsString();
}
if (parsed != null && parsed.has("error") && parsed.get("error").isJsonObject()) {
JsonObject errObj = parsed.getAsJsonObject("error");
if (errObj.has("code")) errorCode = errObj.get("code").getAsString();
if (errObj.has("message")) errorMsg = errObj.get("message").getAsString();
}
} catch (Exception e) {
log.debug("Failed to parse SSE error body as JSON", e);
log.debug(
"Failed to parse SSE error body as JSON, requestId={}",
DashScopeHeaders.requestIdOrUnknown(requestId),
e);
}
}
Status status =
Status.builder()
.requestId(requestId)
.statusCode(code)
.code(
errorCode != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public static CodeGenerationResult fromDashScopeResult(DashScopeResult dashScope
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), CodeGenerationOutput.class));
} else {
log.error(StringUtils.format("Result no output: %s", dashScopeResult));
log.error(
StringUtils.format(
"Result no output: %s, requestId=%s",
dashScopeResult, dashScopeResult.getRequestIdOrUnknown()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public static GenerationResult fromDashScopeResult(DashScopeResult dashScopeResu
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), GenerationOutput.class));
} else {
log.error(StringUtils.format("Result no output: %s", dashScopeResult));
log.error(
StringUtils.format(
"Result no output: %s, requestId=%s",
dashScopeResult, dashScopeResult.getRequestIdOrUnknown()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static ImageGenerationListResult fromDashScopeResult(DashScopeResult dash
rs.message = dashScopeResult.getMessage();
return rs;
} else {
log.error("Result no output: {}", dashScopeResult);
log.error(
"Result no output: {}, requestId={}",
dashScopeResult,
dashScopeResult.getRequestIdOrUnknown());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public static ImageGenerationResult fromDashScopeResult(DashScopeResult dashScop
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), ImageGenerationOutput.class));
} else {
log.error("Result no output: {}", dashScopeResult);
log.error(
"Result no output: {}, requestId={}",
dashScopeResult,
dashScopeResult.getRequestIdOrUnknown());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static ImageSynthesisListResult fromDashScopeResult(DashScopeResult dashS
rs.message = dashScopeResult.getMessage();
return rs;
} else {
log.error(StringUtils.format("Result no output: %s", dashScopeResult));
log.error(
StringUtils.format(
"Result no output: %s, requestId=%s",
dashScopeResult, dashScopeResult.getRequestIdOrUnknown()));
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static ImageSynthesisResult fromDashScopeResult(DashScopeResult dashScope
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), ImageSynthesisOutput.class));
} else {
log.error(StringUtils.format("Result no output: %s", dashScopeResult));
log.error(
StringUtils.format(
"Result no output: %s, requestId=%s",
dashScopeResult, dashScopeResult.getRequestIdOrUnknown()));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public Flowable<MultiModalConversationResult> streamCall(MultiModalConversationP
preprocessInput(param);
return syncApi
.streamCall(param)
.filter(MultiModalConversation::shouldEmitStreamResult)
.map(MultiModalConversationResult::fromDashScopeResult)
.map(result -> mergeSingleResponse(result, toMergeResponse))
.doOnComplete(
Expand Down Expand Up @@ -214,6 +215,9 @@ public void streamCall(
new ResultCallback<DashScopeResult>() {
@Override
public void onEvent(DashScopeResult msg) {
if (!shouldEmitStreamResult(msg)) {
return;
}
MultiModalConversationResult result =
MultiModalConversationResult.fromDashScopeResult(msg);
MultiModalConversationResult mergedResult =
Expand All @@ -239,6 +243,27 @@ public void onError(Exception e) {
});
}

/**
* The new gateway may emit usage/search/metadata SSE frames without a model output. They are
* successful auxiliary frames, not failed model results. Keep frames carrying an output or an
* explicit business error, and silently skip successful auxiliary frames.
*/
private static boolean shouldEmitStreamResult(DashScopeResult result) {
if (result.getOutput() != null) {
return true;
}
String code = result.getCode();
boolean hasError = code != null && !code.isEmpty();
if (!hasError) {
log.debug(
"Ignore streaming event without output: event={}, requestId={}, usagePresent={}",
result.getEvent(),
result.getRequestIdOrUnknown(),
result.getUsage() != null);
}
return hasError;
}

private void preprocessInput(MultiModalConversationParam param)
throws NoApiKeyException, UploadFileException {
boolean hasUpload = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public static MultiModalConversationResult fromDashScopeResult(DashScopeResult d
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), MultiModalConversationOutput.class));
} else {
log.error("Result no output: {}", dashScopeResult);
log.error(
"Result no output: {}, requestId={}",
dashScopeResult,
dashScopeResult.getRequestIdOrUnknown());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public static VideoSynthesisListResult fromDashScopeResult(DashScopeResult dashS
rs.message = dashScopeResult.getMessage();
return rs;
} else {
log.error("Result no output: {}", dashScopeResult);
log.error(
"Result no output: {}, requestId={}",
dashScopeResult,
dashScopeResult.getRequestIdOrUnknown());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public static VideoSynthesisResult fromDashScopeResult(DashScopeResult dashScope
(JsonObject) dashScopeResult.getOutput(), VideoSynthesisOutput.class);
result.setOutput(outputTemp);
} else {
log.error("Result no output: {}", dashScopeResult);
log.error(
"Result no output: {}, requestId={}",
dashScopeResult,
dashScopeResult.getRequestIdOrUnknown());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public static ApplicationResult fromDashScopeResult(DashScopeResult dashScopeRes
JsonUtils.fromJsonObject(
(JsonObject) dashScopeResult.getOutput(), ApplicationOutput.class));
} else {
log.error(StringUtils.format("Result no output: %s", dashScopeResult));
log.error(
StringUtils.format(
"Result no output: %s, requestId=%s",
dashScopeResult, dashScopeResult.getRequestIdOrUnknown()));
}

return result;
Expand Down
Loading
Loading