QWQ 32B
在本章节中,我们将学习如何使用 Spring AI Alibaba 接入阿里云开源 QWQ 系列模型。
QWQ 32B
基于 Qwen2.5 模型训练的 QwQ 推理模型,通过强化学习大幅度提升了模型推理能力。模型数学代码等核心指标(AIME 24/25、LiveCodeBench)以及部分通用指标(IFEval、LiveBench等)达到DeepSeek-R1 满血版水平。
Spring AI Alibaba 接入
- 引入
spring-ai-alibaba-starter-dashscope:
我们可以使用 dashscope api 适配器接入开源 Qwen 系列模型, 引入如下依赖
<dependency>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
</dependency>
-
配置 application.yml:
server:
port: 10002
spring:
application:
name: spring-ai-alibaba-qwq-chat-client-example
ai:
dashscope:
api-key: ${AI_DASHSCOPE_API_KEY}
chat:
options:
model: qwq-plus
使用 ChatModel
-
注入 ChatClient (假设类名为 QWQChatClientController)
public QWQChatClientController(ChatModel chatModel) {
this.chatModel = chatModel;
// 构造时,可以设置 ChatClient 的参数
// {@link org.springframework.ai.chat.client.ChatClient};
this.chatClient = ChatClient.builder(chatModel)
// 实现 Chat Memory 的 Advisor
// 在使用 Chat Memory 时,需要指定对话 ID,以便 Spring AI 处理上下文。
.defaultAdvisors(
new MessageChatMemoryAdvisor(new InMemoryChatMemory()),
)
// 实现 Logger 的 Advisor
.defaultAdvisors(
new SimpleLoggerAdvisor()
)
// 设置 ChatClient 中 ChatModel 的 Options 参数
.defaultOptions(
DashScopeChatOptions.builder()
.withTopP(0.7)
// Note: model must be set when use options build.
.withModel(DashScopeChatModel.DEFAULT_MODEL_NAME)
.build()
)
.build();
} -
编写 Controller 接口:
@GetMapping("/stream/chat")
public Flux<String> streamChat(HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
return chatClient.prompt(DEFAULT_PROMPT)
.stream()
.content();
}
至此,已经完成了 QWQ 32B 模型的基本接入。现在您已经可以和 QWQ 32B 模型对话了。