【AI】SpringAI 第三弹:接入通用大模型平台
1.添加依赖
<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>
2.设置 yml 配置文件
在 application.yml 中添加 DeepSeek 的配置信息:
spring:ai:openai:api-key: ${你的api-key}base-url: https://dashscope.aliyuncs.com/compatible-mode/chat:options:model: deepseek-v3
其中:
-
base-url 填写百炼平台地址。
-
api-key 为准备阶段在百炼平台申请的 AK 凭证。
-
model 设置为 DeepSeek V3 模型。
百炼平台支持的 DeepSeek 模型有以下这些:
3.编写代码案例
@RestController
@RequestMapping("/oa")
public class DeepSeekController {@Autowiredprivate ChatModel chatModel;@RequestMapping("/chat")public String chat(String question) {String result = chatModel.call(question);return result;}
}
效果展示: