掘金 人工智能 02月08日
Spring AI 框架集成 DeepSeek 大模型了,速看~
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何使用Spring AI框架集成DeepSeek大模型,以快速开发智能应用。DeepSeek AI提供开源的DeepSeek V3模型,以其强大的推理和问题解决能力而闻名。Spring AI通过重用现有的OpenAI客户端与DeepSeek AI集成,简化了接入流程。文章详细说明了如何获取DeepSeek API密钥、配置基本URL以及选择合适的模型。此外,还提供了具体的代码示例,包括引入依赖、配置Spring AI以及实现简单的聊天功能,包括阻塞和流式两种模式。总结部分强调了集成过程的简易性,并指出DeepSeek大模型的函数调用、角色定义和结构化输出与之前的讲解内容一致。

🔑 Spring AI通过重用现有的OpenAI客户端与DeepSeek AI集成,简化了智能应用的开发流程。开发者只需获取DeepSeek API密钥,并配置基本URL即可。

🛠️ 集成DeepSeek大模型主要分为三个步骤:创建API密钥,配置DeepSeek基本URL,以及选择DeepSeek模型。文章提供了详细的配置方法和可用的模型选项。

💬 文章提供了完整的代码示例,展示了如何使用Spring AI实现与DeepSeek大模型的简单聊天功能,包括阻塞和流式两种模式,方便开发者快速上手。

DeepSeek 大模型最近是相当的火爆,关于DeepSeek的文章也是满天飞,咱也不能落后,看看 Spring AI 框架如何集成 DeepSeek 大模型开发智能应用Spring 如何集成 DeepSeek 大模型DeepSeek AI 提供开源的 DeepSeek V3 模型,该模型以其尖端的推理和解决问题的能力而闻名。Spring AI 通过重用现有的 OpenAI 客户端与 DeepSeek AI 集成。首先,您需要获取 DeepSeek API 密钥,配置基本 URL,并选择其中一个受支持的模型。接入前准备创建 API 密钥:访问此处创建 API 密钥。使用 Spring AI 项目中的 spring.ai.openai.api-key 属性对其进行配置。设置 DeepSeek 基本 URL:将 spring.ai.openai.base-url 属性设置为 api.deepseek.com。选择 DeepSeek 模型:使用属性 spring.ai.openai.chat.model=<model name> 指定模型。有关可用选项,请参阅支持的型号。Spring AI 集成 DeepSeek 大模型示例1、引入依赖<dependency> <groupId>org.springframework.ai</groupId> <artifactId>spring-ai-openai-spring-boot-starter</artifactId></dependency>2、配置spring: ai: openai: api-key: sk-xxx // 填写自己申请的key base-url: https://api.deepseek.com chat: options: model: deepseek-chat3、简单的聊天示例package com.ivy.controller;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.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import reactor.core.publisher.Flux;import java.util.Map;@RestControllerpublic class ChatController { private final OpenAiChatModel chatModel; public ChatController(OpenAiChatModel chatModel) { this.chatModel = chatModel; } @GetMapping("/ai/generate") public Map<String, String> generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) { return Map.of("generation", this.chatModel.call(message)); } @GetMapping("/ai/generateStream") public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) { Prompt prompt = new Prompt(new UserMessage(message)); return this.chatModel.stream(prompt); }}总结Spring AI 接入 DeepSeek 大模型是非常简单的,实现了阻塞和流式聊天模式。 对于 DeepSeek 大模型的函数调用,角色定义以及结构化输出等和之前文章中讲解的内容是一致的,没有什么特别的地方,这里也不再赘述了,有兴趣的可以参考本专栏的其它文章。Spring AI 集成 DeepSeek的代码示例:Github 地址

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Spring AI DeepSeek 大模型 智能应用 集成
相关文章