本篇博文会分为DeepSeek开放平台上的API,以及本地私有化部署DeepSeek R1模型两种方式来整合使用,本地化私有部署可以参考这篇博文:DeepSeek介绍及使用ollama本地化部署DeepSeek-R1大模型
Spring AI 是由 Spring(一个广泛使用的开源框架)推出的一个新项目,旨在将 人工智能(AI) 集成到 Spring 应用程序中。Spring 是一个支持 Java 开发的框架,而 Spring AI 使得 Java 开发人员能够更容易地构建、管理和集成人工智能模型和机器学习功能。
我们这里直接使用Spring官方提供的相关依赖来整合,官网地址:https://docs.spring.io/spring-ai/reference/api/chat/deepseek-chat.html
本篇博文主要就是采用的spring ai提供的两个starter依赖进行配置整合,分别是spring-ai-openai-spring-boot-starter和spring-ai-ollama-spring-boot-starter
org.springframework.ai
spring-ai-openai-spring-boot-starter
增加以下配置:
spring: ai:
openai: base-url: https://api.deepseek.com api-key: sk-xxxxxxxxxxxxxxxxx chat: options: model: deepseek-chat
项目会自动装配OpenAiAutoConfiguration,就可以在需要的地方注入OpenAiChatModel
代码如下:
@Resource private OllamaChatModel chatModel;
private final List
@PostConstruct public void init() {
chatHistoryList.add(new SystemMessage("You are a helpful assistant."));
}
@GetMapping(“/chat”) public ChatResponse test(String message)
return chatResponse;
}
org.springframework.ai
spring-ai-ollama-spring-boot-starter
增加以下配置:
spring: ai:
ollama: base-url: http://localhost:11434 chat: model: deepseek-r1:1.5b
项目会自动装配OllamaAutoConfiguration,就可以在需要的地方注入ollamaChatModel
代码跟使用spring-ai-openai-spring-boot-starter几乎一样,只是注入的ChatModel类换成了OllamaChatModel
而且实测本地化部署也可以使用spring-ai-openai-spring-boot-starter,修改配置文件如下:
spring: ai:
openai: base-url: http://localhost:11434 api-key: xxxxxxx chat: options: model: deepseek-r1:1.5b
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/273572.html