当前位置: 首页 > news >正文

Spring Boot接入Deep Seek的API

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.mrgr.cn/news/90175.html

相关文章:

  • js 中文拼音排序
  • PHP中的魔术方法
  • Java 魔法:精准掌控 PDF 合同模板,指定页码与关键字替换签章日期
  • 【CubeMX+STM32】SD卡 文件系统读写 FatFs+SDIO+DMA
  • Java 大视界 -- Java 大数据在智能政务中的应用与服务创新(78)
  • DeepSeek介绍,以及本地部署和API使用
  • 模拟(典型算法思想)—— OJ例题算法解析思路
  • C++设计模式 - 模板模式
  • 模拟算法:深入探讨与C++实现
  • [创业之路-289]:《产品开发管理-方法.流程.工具 》-15- 需求管理 - 第1步:原始需求收集
  • 深入理解MySQL索引底层数据结构
  • 防火墙安全综合实验
  • Hive之[Hive]详细安装步骤
  • 绕组电感 - Ansys Maxwell 磁通链与电流
  • CAD 屏幕进度条
  • python全栈-python基础
  • pip3命令全解析:Python3包管理工具的详细使用指南
  • 05-多数元素
  • 推荐系统概述
  • 【医院管理会计专题】2.管理会计:医院运营管理的隐形引擎
  • 【故障排除】ls: command not found 终端命令失效的解决办法
  • 【JavaScript】this 指向由入门到精通
  • Aitken 逐次线性插值
  • 【C语言】#define和typedef的区别
  • 本地部署DeepSeek Nodejs版
  • 2025年1月1日起,美国禁止在食品包装中使用PFAS+PFAS标准办理讲解