不同大模型
约 309 字大约 1 分钟
2025-12-14
基础知识
OpenAI 和 DashScope
| OpenAI(官方) | DashScope (社区) | |
|---|---|---|
| 依赖库 | langchain4j-open-ai-spring-boot-starter | langchain4j-community-dashscope-spring-boot-starter |
| 底层实现 | 使用 OpenAI 官方协议 (HTTP) | 使用 阿里云 DashScope 原生 Java SDK |
| 支持模型 | GPT-3.5, GPT-4o, 以及任何兼容 OpenAI 协议的模型 (包括 DeepSeek, Moonshot, 本地 LLM) | 仅支持阿里云 DashScope 平台上的模型 (Qwen, Wanx 等) |
动手实操
引入依赖
在上一篇我们已经引入了 open-ai 依赖,这里我们只需要引入 community-dashcope 依赖
<properties>
<java.version>17</java.version>
<langchain4j.version>1.0.0-beta2</langchain4j.version>
</properties>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-dashscope-spring-boot-starter</artifactId>
<version>${langchain4j.version}</version>
</dependency>yml 配置
langchain4j:
open-ai:
chat-model:
model-name: # 模型名称
api-key: # 模型 key
base-url: # 模型 url
community:
dashscope:
chat-model:
model-name: qwen-max
api-key: # 模型 key业务层
- OpenAiService
@AiService(wiringMode = EXPLICIT,
chatModel = "openAiChatModel"
)
public interface OpenAiService {
@SystemMessage("提示词,你是一位老师")
String chat(String message);
}- DashscopeService
@AiService(wiringMode = EXPLICIT,
chatModel = "qwenChatModel"
)
public interface DashscopeService {
@SystemMessage("你是一位导游")
String chat(String message);
}测试
@Slf4j
@SpringBootTest
@RunWith(SpringRunner.class)
class AiTest {
@Autowired
private OpenAiService openAiService;
@Autowired
private DashscopeService dashscopeService;
@Test
void chat() {
log.info(openAiService.chat("你好,你是谁啊"));
}
@Test
void chat3() {
log.info(dashscopeService.chat("你好,你是谁啊"));
}
}测试结果:
- OpenAi

- DashScope

版权所有
版权归属:haipeng-lin