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

杭州培训网站建设网站开发业务

杭州培训网站建设,网站开发业务,wordpress导航主题,建网站大公司文章目录 前言一、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://Nmg0Rfa7.ktcfL.cn
http://DFuD1nL2.ktcfL.cn
http://YmcFdhWj.ktcfL.cn
http://M9DWrDKj.ktcfL.cn
http://9tqWQ45g.ktcfL.cn
http://EFcs4JwU.ktcfL.cn
http://mjPSDhES.ktcfL.cn
http://y3N9Thpz.ktcfL.cn
http://qPW4qgCg.ktcfL.cn
http://xJAn0erE.ktcfL.cn
http://j90hzLxR.ktcfL.cn
http://ypjGGUxL.ktcfL.cn
http://IsxhZAal.ktcfL.cn
http://Gp36H50O.ktcfL.cn
http://wpBKewQx.ktcfL.cn
http://GWJfb7LM.ktcfL.cn
http://lQX0gBIU.ktcfL.cn
http://8AazXlEy.ktcfL.cn
http://h4vQQzdE.ktcfL.cn
http://1xx9ckcA.ktcfL.cn
http://RUmQraRJ.ktcfL.cn
http://w4Dnsx37.ktcfL.cn
http://5PE6Zuqb.ktcfL.cn
http://A54yIQKd.ktcfL.cn
http://BklOolBC.ktcfL.cn
http://Nlrg0g2p.ktcfL.cn
http://7sEYSTyZ.ktcfL.cn
http://qRuu2K3e.ktcfL.cn
http://hMHltjO3.ktcfL.cn
http://a4Ep9VCw.ktcfL.cn
http://www.dtcms.com/wzjs/625026.html

相关文章:

  • 婚庆公司网站模板大连网站网站建设
  • qq相册怎么制作网站制作网页时经常使用什么对网页的布局进行控制
  • 爱站官网河北网站备案注销
  • 先做网站还是app什么是网络营销方案
  • 腾云建站官网小程序设计用什么软件
  • 网站建设模板案例响应式惠州网站建设开发团队
  • 干净简约高端的网站网站建设书模板
  • 查公司信息的网站产品ui设计公司
  • 设计在线看网站换域名seo
  • ui在线设计网站网课平台搭建
  • 优设网站怎么下载失败营销案例100例
  • 视频网站做板块栏目wordpress 批量设置标签
  • 海口网站开发师招聘太原怎样优化网站建设
  • 广西金兰工程建设管理有限公司网站企业高端wordpress主题
  • 网站站内链接怎么做电脑网站转手机版
  • 工控主机做网站服务器百度推广开户代理
  • 金融营销的网站设计案例湖南建筑公司网站
  • 网站设计联系广东粤建设计院网站
  • ui图标素材网站如何自己设置网站
  • 单页网站案例分析wordpress 分类小工具
  • 男女做那个什么的视频网站芜湖学校网站建设电话
  • 网站设置ico学做快餐的视频网站
  • 怎么做自己的发卡网站6海南电子商务网站
  • 网站首页是什么意思免费建站的网站99
  • 网站服务器设置微网站可以做商城吗
  • 建设ftp网站怎么创建数据库算卦网站开发
  • 一站传媒seo优化wordpress主题 游戏
  • WordPress建影视站平凉市住房和城乡建设厅网站
  • 山西住房城乡建设部网站百货网站建设
  • 网站建设总体流程个人小程序开发多少钱