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

网站建设汇报评估品牌咨询

网站建设汇报评估,品牌咨询,iframe网站后台模板,孝感织云网站建设文章目录 前言一、Spring AI 集成 DeepSeek1. 开发AI程序2. DeepSeek 大模型3. 集成 DeepSeek 大模型1. 接入前准备2. 引入依赖3. 工程配置4. 调用示例5. 小结 4. 集成第三方平台(已集成 DeepSeek 大模型)1. 接入前准备2. POM依赖3. 工程配置4. 调用示例…

文章目录

  • 前言
  • 一、Spring AI 集成 DeepSeek
    • 1. 开发AI程序
    • 2. DeepSeek 大模型
    • 3. 集成 DeepSeek 大模型
      • 1. 接入前准备
      • 2. 引入依赖
      • 3. 工程配置
      • 4. 调用示例
      • 5. 小结
    • 4. 集成第三方平台(已集成 DeepSeek 大模型)
      • 1. 接入前准备
      • 2. POM依赖
      • 3. 工程配置
      • 4. 调用示例
      • 5. 调用测试
      • 6. 小结
    • 5. 集成 DeepSeek4j 1.4版本
      • 1. 为什么需要 DeepSeek4j?
      • 2. 依赖
      • 3. 配置
      • 4. 示例


前言

拥抱AI

DeepSeek 是深度求索公司发布的大模型,是国产之光。大家应该学会如何使用 DeepSeek 大模型,本文主要探讨,如何开发基于 DeepSeek 大模型的智能应用。


一、Spring AI 集成 DeepSeek

接下来深入了解如何使用 Spring Boot 和 DeepSeek 开发 AI 程序。

1. 开发AI程序

  在当今数字化时代,人工智能(AI)已成为推动技术进步和创新的核心力量。从智能语音助手到图像识别系统,从个性化推荐引擎到自动化流程,AI 的应用无处不在,正深刻地改变着我们的生活和工作方式。

  与此同时,软件开发领域也在不断演进,以适应快速变化的技术需求和业务场景。Spring Boot 作为 Java 生态系统中最受欢迎的框架之一,以其 “约定优于配置” 的理念和丰富的功能,为开发者提供了一种高效、便捷的方式来构建企业级应用程序。

  DeepSeek 则是 AI 领域的一颗新星,致力于开发先进的大语言模型(LLM)和相关技术 。它的出现为 AI 技术的发展注入了新的活力,其模型在性能和成本效益方面展现出了卓越的优势,在多项测试中表现出色,甚至超越了一些行业领先的模型,且设计成本相对较低。

  Spring Boot 的强大功能和便捷性,使得开发者能够快速搭建稳定的后端服务,而 DeepSeek 的先进大语言模型则为应用赋予了强大的智能交互和处理能力。通过将 DeepSeek 的 AI 能力集成到 Spring Boot 应用中,我们可以轻松实现智能聊天机器人、智能文档处理、智能代码生成等各种创新应用,为用户提供更加智能化、个性化的服务体验。

2. DeepSeek 大模型

DeepSeek 推出两款模型:

  • DeepSeek V 系列,对于V系列主要 对话,模型名称:deepseek-chat
  • DeepSeek R 系统,对于R系统主要 推理, 模型名称:deepseek-reasoner

DeepSeek 官方更新日志,可以看到模型发布和演化的过程。

https://api-docs.deepseek.com/zh-cn/updates

3. 集成 DeepSeek 大模型

  DeepSeek AI提供开源的 DeepSeek V3 模型,该模型以其尖端的推理和解决问题的能力而闻名。

  Spring AI 通过重用现有的 OpenAI 客户端与 DeepSeek AI 集成。首先,需要获取 DeepSeek API 密钥,配置基本 URL,并选择其中一个受支持的模型。

SpringAI集成DS

1. 接入前准备

  • 创建 API 密钥:
    访问此处:https://api-docs.deepseek.com/zh-cn/,创建 API 密钥。
    使用 Spring AI 项目中的 spring.ai.openai.api-key 属性对其进行配置。

  • 设置 DeepSeek 基本 URL:
    将 spring.ai.openai.base-url 属性设置为 api.deepseek.com。

  • 选择 DeepSeek 模型:
    使用属性 spring.ai.openai.chat.model= 指定模型。有关可用选项,请参阅支持的型号。

2. 引入依赖

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

3. 工程配置

spring:ai:
- openai:
-   api-key: sk-xxx   # 填写自己申请的key
-   base-url: https://api.deepseek.com
-   chat:
- - options:
- -   model: deepseek-chat

4. 调用示例

package com.demo.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;@RestController
public 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);
- }
}

5. 小结

  Spring AI 接入 DeepSeek 大模型是非常简单的,实现了阻塞和流式聊天模式。
  对于 DeepSeek 大模型的函数调用,角色定义以及结构化输出等是一致的。

4. 集成第三方平台(已集成 DeepSeek 大模型)

1. 接入前准备

硅基流动平台,注册地址 如下:

https://cloud.siliconflow.cn/i/pCa1dBVX

  1. 选择一个对话功能的免费模型,如果你想用其他,生图,视频,语音相关,里面也可以自行选择。

硅基流动平台
2. 硅基流动官网注册后后,点击API密钥菜单,生成密钥,点击复制。

创建API密钥

2. POM依赖

- <properties>
- - <java.version>17</java.version>
- - <spring-ai.version>1.0.0-M5</spring-ai.version>
- - <maven.compiler.source>17</maven.compiler.source>
- - <maven.compiler.target>17</maven.compiler.target>
- </properties>
- <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>
- </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>

3. 工程配置

spring:ai:
- openai:
-   api-key: # 这里是你自己的api key
-   base-url: https://api.siliconflow.cn
-   chat:
- - options:
- -   model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B

4. 调用示例

package com.demo.controller;import groovy.util.logging.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;@RestController
@CrossOrigin(origins = "*")
@Slf4j
public class ChatBotController {- private final ChatClient chatClient;- public ChatBotController(ChatClient.Builder builder) {
- - this.chatClient = builder.defaultSystem("你是一个天气预报员,当有人输入日期的时候,你输出北京的天气预报信息," +
- - - - "生成结果在html页面中以markdown的格式输出,最后输出结尾的时候始终以下面的语句结尾:感谢您的咨询,我是舆情君。").build();
- }- @GetMapping(value = "ai/chat/{message}")
- public String chat(@PathVariable("message") String message) {
- - return chatClient.prompt()
- - - - .user(message)
- - - - .call()
- - - - .content();
- }
}

5. 调用测试

启动项目,地址栏输入:http://localhost:8080/ai/chat/2025年2月18日

6. 小结

以上是简单的演示,项目中可以直接写程序,通过大模型的能力,直接以json的格式输出,系统执行之后,直接插入数据库,也可以做到数据采集,助力企业的项目。

5. 集成 DeepSeek4j 1.4版本

1. 为什么需要 DeepSeek4j?

DeepSeek4J 是专为 Java 生态打造的 DeepSeek 模型集成框架。其 API 设计简洁优雅,仅需一行代码,即可完成 DeepSeek 的接入。

现有框架的局限性

  • 思维链内容丢失:R1 最核心的推理过程完全被忽略。
  • 响应模式不兼容:无法处理“思考在前、结论在后”的输出模式。
  • 参数限制:temperature、top_p 等关键参数设置失效。
  • 流式处理不完善:用户体验欠佳。

解决方案
面向 DeepSeek 的开箱即用方案——DeepSeek4j。

  • 增强支持 DeepSeek 独有的思维链和账单特性。
  • 增加 Project Reactor 的全面响应式支持。
  • 提供集成 Spring Boot Starter,支持自动配置。

2. 依赖

3. 配置

4. 示例


本文的引用仅限自我学习如有侵权,请联系作者删除。
参考知识
如何用Spring AI 结合 DeepSeek开发你的第一个AI程序?
Spring 宣布接入 DeepSeek!!
DeepSeek4J 再更新!Java 项目一行代码集成 DeepSeek !!


http://www.dtcms.com/a/523169.html

相关文章:

  • 注册了网站怎么建设网站改版升级总结
  • 网站服务器租用阿里云一年多少钱啊金融企业类网站模板免费下载
  • 像网站的ppt怎么做的安徽电子健康卡小程序
  • 网站是自己做还是让别人仿wordpress怎么使用cdn加载图片
  • 免费搭建网站哪个好攸县网站开发
  • 深圳网站建设深圳怎么用mvc架构做网站
  • 怎样做外贸网站临安规划建设局网站
  • 公司网站建设方案pptwordpress伪春菜
  • 购物网站常用的多组图左右轮播的js图片特效代码做网站需要的大图
  • 无为建设局网站传媒公司logo设计创意
  • 简单网站建设视频教程下载建设一个网站 最好是官网那种
  • 做网站沧州惠城网站建设有哪些
  • 鹤岗市城乡建设局网站上海多语种建站
  • 学校网站建设介绍wordpress利用DW编辑
  • 无锡企业免费建站邯郸网站关键字优化
  • 上海网站推广汉狮2022双11各大电商平台销售数据
  • 网站建设亿金手指花总12网站备案通讯地址
  • 给自己公司做网站运营百度软件商店下载安装
  • 建设通网站vip大连网站建设领超最好
  • 韩路做的网站是什么名字同城做推广哪个网站好
  • 帮别人做彩票网站莱芜警方网站官网
  • 只做外贸的公司网站长春网站建设5219
  • 建筑公司做网站买空间多大合适我做中医培训去哪个网站找学员
  • 怀化网站制作建设推广方案怎么写
  • 如何做电视剧的短视频网站wordpress 首页域名
  • 福建联泰建设集团网站网站怎么让百度收录
  • 网站建设公司专业网站研发开发做慧聪网价格网站价格
  • 萍乡做网站哪家好wordpress重复安装
  • 网络科技公司 网站建设今天重大新闻头条新闻
  • 南宁网站开发外包性价比个人建立网站后怎么盈利