您的位置:首页 > 汽车 > 新车 > 标书制作费用一般多少_哈密seo_网站内容优化怎么去优化呢_三只松鼠软文范例500字

标书制作费用一般多少_哈密seo_网站内容优化怎么去优化呢_三只松鼠软文范例500字

2025/2/22 2:38:39 来源:https://blog.csdn.net/chengpei147/article/details/145515413  浏览:    关键词:标书制作费用一般多少_哈密seo_网站内容优化怎么去优化呢_三只松鼠软文范例500字
标书制作费用一般多少_哈密seo_网站内容优化怎么去优化呢_三只松鼠软文范例500字

本篇博文会分为DeepSeek开放平台上的API,以及本地私有化部署DeepSeek R1模型两种方式来整合使用,本地化私有部署可以参考这篇博文:DeepSeek介绍及使用ollama本地化部署DeepSeek-R1大模型

Spring AI

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-starterspring-ai-ollama-spring-boot-starter

版本依赖

根据官网的描述,spring ai框架支持的SpringBoot版本应该是3.2.x 和 3.3.x
https://www.chengpei.top/upload/spring-ai-version.png
而SpringBoot 3.2.x 和 3.3.x依赖的JDK版本最低应该也是JDK17,所以这里演示整合的代码都是基于spring boot 3.3.8 以及 JDK17

整合DeepSeek API key

进入DeepSeek开放平台页面,注册账号登录后,可以创建API key,新账号有赠送的10元额度,具体价格可以参考这里:https://api-docs.deepseek.com/zh-cn/quick_start/pricing/
有了API key后我们可以开始构建工程了,基于springboot 3.3.8版本搭建一个工程,引入以下依赖:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>

增加以下配置:

spring:ai:openai:base-url: https://api.deepseek.comapi-key: sk-xxxxxxxxxxxxxxxxxchat:options:model: deepseek-chat

项目会自动装配OpenAiAutoConfiguration,就可以在需要的地方注入OpenAiChatModel
代码如下:

@Resource
private OllamaChatModel chatModel;private final List<Message> chatHistoryList = new ArrayList<>();@PostConstruct
public void init() {chatHistoryList.add(new SystemMessage("You are a helpful assistant."));
}@GetMapping("/chat")
public ChatResponse test(String message) {chatHistoryList.add(new UserMessage(message));Prompt prompt = new Prompt(chatHistoryList);ChatResponse chatResponse = chatModel.call(prompt);if (chatResponse.getResult() != null && chatResponse.getResult().getOutput() != null) {chatHistoryList.add(chatResponse.getResult().getOutput());}return chatResponse;
}

整合本地化部署的DeepSeek R1模型

本地化私有部署可以参考这篇博文:DeepSeek介绍及使用ollama本地化部署DeepSeek-R1大模型
部署完成后同样是基于springboot 3.3.8版本搭建一个工程,引入的依赖就换为:

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>

增加以下配置:

spring:ai:ollama:base-url: http://localhost:11434chat: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:11434api-key: xxxxxxxchat:options:model: deepseek-r1:1.5b

其他也就一样了,只是把地址换成了本地ollama的服务地址,api-key不需要了但是也不能不填,不填会报错,模型就配置本地有的模型即可
如果想像网站那样可以一个字一个字的输出,也可以调用chatModel.stream流式输出爱的回复

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com