旧版 2.x¶
什么移到了哪里¶
为了让既有 2.x 代码在 3.0 artifact 上继续编译,完整 2.x 表面以冻结 facade 的形式保留在
com.alibaba.dashscope.legacy_2x.* 下。只需在 import 中插入 legacy_2x 段:
// 2.x(2.x artifact 上)
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.exception.ApiException;
// 3.0 artifact,legacy facade
import com.alibaba.dashscope.legacy_2x.aigc.generation.Generation;
import com.alibaba.dashscope.legacy_2x.common.Message;
import com.alibaba.dashscope.legacy_2x.exception.ApiException;
facade 保留历史行为:checked 的 ApiException / NoApiKeyException / InputRequiredException、
ResultCallback 流式、基于 Flowable 的 streamCall,以及按能力的入口对象
(new Generation()、new ImageSynthesis()……)。
每个 legacy 类型都带有类型级 @Deprecated;用 -Xlint:deprecation 编译可查看详情与建议的
3.0 替代物。
不在废弃之列¶
- AgentStudio 移到了
com.alibaba.dashscope.applications.agentstudio.*(不在legacy_2x之下),仍在活跃开发;也可通过client.agentStudio()访问。 shared(com.alibaba.dashscope.shared.*)持有两代共用的中立常量。assistants.*/threads.*暂无 3.0 等价物 —— 在替代物发布前保留legacy_2ximport。
参考与示例¶
- 冻结 facade 的 Javadoc: legacy_2x 各包 (包含在自动生成的 API 参考中)。
- 归档的可运行 2.x 示例: examples/legacy_2x/。
- 根 README 保留了 legacy 附录,收录原始 2.x 快速上手文档。
迁移¶
从 2.x 迁移页提供完整入口对照表与前后对比示例。影响大多数代码的两处变化:
- checked 异常 → unchecked 的 DashScopeException 族
(或用
raiseOnError(false)获得结果式错误); - 按能力的对象 → 一个置于 try-with-resources 中的
DashScopeClient。