Spring Boot接入Deep Seek的API

server/2025/2/12 10:30:30/

1,首先进入deepseek的官网:DeepSeek | 深度求索,单击右上角的API开放平台。

2,单击API keys,创建一个API,创建完成务必复制!!不然关掉之后会看不看api key!!!

DeepSeek Chat :: Spring AI Reference

创建一个SpringWeb项目,勾选AI下面的Open-Ai,创建成功后就可以进行下一步。

首先把application.property改成application.yml,将以下信息复制到yml里,记得把api-key替换成你自己的!

spring:ai:openai:api-key: api-keybase-url: https://api.deepseek.comchat:options:model: deepseek-chat

编写配置类:

@Configuration
public class ChatConfig {@Beanpublic ChatClient chatClient(OpenAiChatModel openAiChatModel) {return ChatClient.builder(openAiChatModel).build();}
}

编写controller

@RestController
@RequestMapping("/ai")
public class ChatController {private final ChatClient chatClient;public ChatController(ChatClient chatClient) {this.chatClient = chatClient;}@GetMapping("/chat")public String generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {return chatClient.prompt().user(message).call().content();}
}

启动项目,测试请求

搞定!

备注:pom.xml

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-openai-spring-boot-starter</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>${spring-ai.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><annotationProcessorPaths><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></path></annotationProcessorPaths></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build>


http://www.ppmy.cn/server/167033.html

相关文章

使用deepseek快速创作ppt

目录 1.在DeekSeek生成PPT脚本2.打开Kimi3.最终效果 DeepSeek作为目前最强大模型&#xff0c;其推理能力炸裂&#xff0c;但是DeepSeek官方没有提供生成PPT功能&#xff0c;如果让DeepSeek做PPT呢&#xff1f; 有个途径&#xff1a;在DeepSeek让其深度思考做出PPT脚本&#xf…

Kubernetes 中特权模式(Privileged Mode)容器

目录标题 Kubernetes 中的特权模式容器笔记特权模式定义特权模式的配置特权模式的影响如何检查特权模式查看 Pod 详细信息查找 Security Context 部分 特权模式的使用建议总结 容器里面ps -ef和宿主机是一样的可能的原因解决方法 Kubernetes 中的特权模式容器笔记 特权模式定义…

2024美团春招硬件开发笔试真题及答案解析

目录 一、选择题 1、在 Linux,有一个名为 file 的文件,内容如下所示: 2、在 Linux 中,关于虚拟内存相关的说法正确的是() 3、AT89S52单片机中,在外部中断响应的期间,中断请求标志位查询占用了()。 4、下列关于8051单片机的结构与功能,说法不正确的是()? 5、…

2025年日祭

本文将同步发表于洛谷&#xff08;暂无法访问&#xff09;、CSDN 与 Github 个人博客&#xff08;暂未发布&#xff09; 本蒟自2025.2.8开始半停课。 以下是题目格式&#xff1a; [题目OJ 题号] [来源&#xff08;选填&#xff09;] 名称 …… 题号 - 名称 题目&#xff1a;……

解决 idea 无法创建java8 模版

解决 idea 无法创建java8 模版 由于 Spring 官方不再维护 旧的版本了导致的 https://start.spring.io 解决方式很简单 切换到 阿里源就可以了 https://start.aliyun.com/ 项目生成 成功 总结 &#xff1a;IDEA 内置的 Spring Initializr 创建 Spring Boot 项目实际上是依赖官…

香橙派AI Pro算子开发(二)kernel直调Add算子

一、代码准备 这里的代码是从官方仓库拷贝而来&#xff0c;可以参考上一篇文章[香橙派AI Pro算子开发&#xff08;一&#xff09;]。(https://blog.csdn.net/weixin_44130162/article/details/145488713?spm1011.2415.3001.5331) git clone https://gitee.com/ascend/sample…

Vulnhub靶机渗透-DC1

文章目录 Flag1Flag2Flag3Flag4Flag5总结 └─# arp-scan -l | grep 08:00:27 >> arp-scan.txt Interface: eth0, type: EN10MB, MAC: 08:00:27:16:61:42, IPv4: 192.168.1.245 192.168.1.183 08:00:27:53:e3:e6 PCS Systemtechnik GmbH└─# nmap -Pn -A -p- 19…

从零开始认识大语言模型(LLM)

“AI小美好——聚焦科技、商业、职场。前沿资讯&#xff0c;实用干货&#xff0c;邂逅更美好的自己&#xff01;” 在当今数字化时代&#xff0c;语言不仅是人类交流的工具&#xff0c;更是信息传递的核心。随着人工智能技术的飞速发展&#xff0c;大语言模型逐渐走进了我们的…