|
|
|
@ -142,19 +142,21 @@ public class CallDeepSeek {
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
System.out.println("收到结束标记 [DONE]");
|
|
|
|
|
// 收到[DONE]标记,流处理完成
|
|
|
|
|
String responseContent = fullResponse.toString();
|
|
|
|
|
System.out.println("流处理完成,总内容长度: " + responseContent.length());
|
|
|
|
|
if (saveToFile && outputPath != null) {
|
|
|
|
|
FileUtil.writeString(responseContent, new File(outputPath), "UTF-8");
|
|
|
|
|
listener.onComplete("内容已成功保存到" + outputPath);
|
|
|
|
|
} else {
|
|
|
|
|
listener.onComplete(responseContent);
|
|
|
|
|
}
|
|
|
|
|
return; // 提前结束处理
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 流结束后的处理
|
|
|
|
|
String responseContent = fullResponse.toString();
|
|
|
|
|
System.out.println("流处理完成,总内容长度: " + responseContent.length());
|
|
|
|
|
if (saveToFile && outputPath != null) {
|
|
|
|
|
FileUtil.writeString(responseContent, new File(outputPath), "UTF-8");
|
|
|
|
|
listener.onComplete("内容已成功保存到" + outputPath);
|
|
|
|
|
} else {
|
|
|
|
|
listener.onComplete(responseContent);
|
|
|
|
|
}
|
|
|
|
|
System.out.println("SSE数据流处理结束");
|
|
|
|
|
} else {
|
|
|
|
|
System.err.println("API请求失败,状态码: " + response.statusCode());
|
|
|
|
|
listener.onError("API请求失败: " + response.statusCode() + " Body: " + response.body().toString());
|
|
|
|
|