您的位置:首页 > 汽车 > 新车 > 软件工程师是做什么的_企业微信开发文档_seo优化内页排名_房地产网站模板

软件工程师是做什么的_企业微信开发文档_seo优化内页排名_房地产网站模板

2025/4/20 23:21:45 来源:https://blog.csdn.net/csdn_HPL/article/details/147191899  浏览:    关键词:软件工程师是做什么的_企业微信开发文档_seo优化内页排名_房地产网站模板
软件工程师是做什么的_企业微信开发文档_seo优化内页排名_房地产网站模板

个人学习心得,仅供参考

软件环境:

 JDK  17  你用JDK 11 无法支持SpringBoot 3SpringBoot 3 版本以上才支持spring aimavan 3.6.1

1.获取Deepseek官网的API-key

官网:https://platform.deepseek.com/api_keys

在这里插入图片描述

2.创建项目

这样创建
在这里插入图片描述
添加依赖
在这里插入图片描述

项目结构
在这里插入图片描述
下面是源码
application.properties配置文件

spring.ai.openai.api-key=  你复制的API key
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.chat.options.model=deepseek-chat
spring.ai.openai.chat.options.temperature=0.7

service类


import org.springframework.ai.chat.model.ChatResponse;
import reactor.core.publisher.Flux;public interface DeepSeekService {/* 根据消息直接输出回答 */String chat(String message);/* 根据消息直接输出回答 流式输出 */Flux<ChatResponse> chatFlux(String message);}

service实现类

import com.hpl.service.DeepSeekService;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;@Service
public class DeepSeekServiceImpl implements DeepSeekService {@Resourceprivate OpenAiChatModel  chatModel;@Overridepublic String chat(String message) {return chatModel.call(message);}@Overridepublic Flux<ChatResponse> chatFlux(String message) {Prompt prompt = new Prompt(new UserMessage(message));return chatModel.stream(prompt);}}

controller类

import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;@RestController
@RequestMapping("/ai")
public class DeepSeekController {@Resourceprivate DeepSeekService deepSeekService;@GetMapping(value = "/chat", produces = MediaType.APPLICATION_JSON_VALUE)public String chat(@RequestParam(value = "message") String message) {return deepSeekService.chat(message);}@GetMapping(value = "/chatFlux", produces = MediaType.TEXT_EVENT_STREAM_VALUE)public Flux<ChatResponse> chatFlux(@RequestParam(value = "message") String message) {return deepSeekService.chatFlux(message);}
}

然后启动SpringBoot
去postman测试

http://localhost:8080/ai/chat?message=你是谁

在这里插入图片描述

参考文档

spring-ai 官网:https://docs.spring.io/spring-ai/reference/api/chat/deepseek-chat.html
deepseek 官方文档:https://api-docs.deepseek.com/zh-cn/

版权声明:

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

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