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

合肥官方网站优化费用seo自学网视频教程

合肥官方网站优化费用,seo自学网视频教程,成功的网站应该具备哪些要素,焦作市建设银行网站本篇文章会分基于DeepSeek开放平台上的API,以及本地私有化部署DeepSeek R1模型两种方式来整合使用。 本地化私有部署可以参考这篇博文 全面认识了解DeepSeek利用ollama在本地部署、使用和体验deepseek-r1大模型 Spring版本选择 根据Spring官网的描述 Spring AI是一…

本篇文章会分基于DeepSeek开放平台上的API,以及本地私有化部署DeepSeek R1模型两种方式来整合使用。
本地化私有部署可以参考这篇博文 全面认识了解DeepSeek+利用ollama在本地部署、使用和体验deepseek-r1大模型

Spring版本选择

根据Spring官网的描述
Spring AI是一个人工智能工程的应用框架,旨在为Java开发者提供一种更简洁的方式与AI交互,减轻在Java业务中接入LLM模型应用的学习成本。目前,Spring AI已经上架到Spring Initializr,开发者可以在https://start.spring.io/上使用并构建相关应用‌。

SpringAI支持接入多种AI服务,如OpenAI、Ollama、Azure OpenAI、Huggingface等,可以实现聊天、embedding、图片生成、语音转文字、向量数据库、function calling、prompt模板、outputparser、RAG等功能‌。

spring ai框架支持Spring Boot版本为 3.2.x and 3.3.x
在这里插入图片描述
从SpringBoot 3.x 开始依赖的JDK版本最低是JDK17,所以这里演示整合的代码都是基于spring boot 3.3.8 以及 JDK17

整合DeepSeek API key

深度求索deepseek开放平台申请自己的API key,新用户注册后会赠送10元余额,有效期为一个月。
在这里插入图片描述

创建一个 API key

保存好自己的API KEY 千万别泄露喽
在这里插入图片描述
创建API key后我们可以开始构建SpringBoot工程了,基于springboot 3.4.2版本搭建一个工程。
spring-ai-openai starter:伪装成 OpenAI,DeepSeek 提供了 OpenAI 兼容模式。
,引入以下依赖:

自动引入依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.2</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>demo-deepseek</artifactId><version>0.0.1-SNAPSHOT</version><name>demo-deepseek</name><description>demo-deepseek</description><url/><licenses><license/></licenses><developers><developer/></developers><scm><connection/><developerConnection/><tag/><url/></scm><properties><java.version>17</java.version><spring-ai.version>1.0.0-M5</spring-ai.version></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><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></project>

代码

添加了 spring-ai-openai-spring-boot-starter 依赖;Spring AI 为 OpenAI Chat Client 提供了 Spring Boot 自动装配。

OpenAiAutoConfiguration配置类中自动注入了,我们只需要直接注入调用即可。

DeepSeek 其实提供了 OpenAI 兼容模式,只要在请求头里加个api_key,就能假装自己在调 OpenAI。Spring AI 的 openai starter 本质上是通过 RestTemplate 发请求,我们只需要改改 URL 和认证方式。
在这里插入图片描述


@RestController
public class ChatController {@Resourceprivate OpenAiChatModel chatModel;private final List<Message> chatHistoryList = new ArrayList<>();@PostConstructpublic void init() {chatHistoryList.add(new SystemMessage("You are a helpful assistant."));}@GetMapping("/chat")public ChatResponse test(String message) {chatHistoryList.add(new UserMessage(message));Prompt prompt = new Prompt(chatHistoryList);ChatResponse chatResponse = chatModel.call(prompt);if (chatResponse.getResult() != null && chatResponse.getResult().getOutput() != null) {chatHistoryList.add(chatResponse.getResult().getOutput());}return chatResponse;}}

修改配置文件

spring:ai:openai:base-url: https://api.deepseek.com/v1  # DeepSeek的OpenAI式端点api-key: sk-your-deepseek-key-herechat.options:model: deepseek-chat  # 指定DeepSeek的模型名称

调用接口测试
在这里插入图片描述

本地部署调用

如果想要把 DeepSeek 部署在内网服务器,或者你想在本地跑个小模型,可以采用这种方式来在本地部署一个 DeepSeek R1 蒸馏版。

spring-ai-ollama-spring-boot-starter:通过 Ollama 本地部署一个 DeepSeek R1 蒸馏版。

下载并安装

从官方网站下载并安装 Ollama:https://ollama.com

Ollama 可以让你轻松在自己的电脑上运行各种强大的 AI 模型,就像运行普通软件一样简单。

ollama pull deepseek-r1:8b
ollama list deepseek

更多版本可以在这里查看:https://ollama.com/library/deepseek-r1
在这里插入图片描述

修改pom,添加依赖

<dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-ollama-spring-boot-starter</artifactId><version>0.8.1</version>
</dependency>

修改配置文件

spring:ai:ollama:base-url: http://localhost:11434chat:model: deepseek-r1:8b  # 与本地模型名称对应

实现代码

@RestController
@RequestMapping("/ai")
public class ChatController {private final ChatClient chatClient;// 构造方法注入 ChatClient.Builder,用于构建 ChatClient 实例public ChatController(ChatClient.Builder chatClient) {this.chatClient = chatClient.build();}@GetMapping("/chat")public ResponseEntity<Flux<String>> chat(@RequestParam(value = "message") String message) {try {// 调用 ChatClient 生成响应,并以 Flux<String>(响应流)形式返回Flux<String> response = chatClient.prompt(message).stream().content();return ResponseEntity.ok(response);} catch (Exception e) {return ResponseEntity.badRequest().build();}}
}

api-key不需要了但是也不能不填,不填会启动报错,模型就配置本地有的模型即可
如果想像网站那样可以一个字一个字的输出,也可以调用chatModel.stream流式输出


文章转载自:
http://dinncosuperaltern.zfyr.cn
http://dinncofizgig.zfyr.cn
http://dinncoabroad.zfyr.cn
http://dinncojuridic.zfyr.cn
http://dinncorumbustious.zfyr.cn
http://dinncopigsticker.zfyr.cn
http://dinncoreceptive.zfyr.cn
http://dinncobunchy.zfyr.cn
http://dinncosubsocial.zfyr.cn
http://dinncocriticises.zfyr.cn
http://dinncojacamar.zfyr.cn
http://dinncolatescent.zfyr.cn
http://dinnconeurogenesis.zfyr.cn
http://dinncomoment.zfyr.cn
http://dinncosilentious.zfyr.cn
http://dinncoakademi.zfyr.cn
http://dinncomeshy.zfyr.cn
http://dinncopudency.zfyr.cn
http://dinncoblondine.zfyr.cn
http://dinncoreposal.zfyr.cn
http://dinncofilelist.zfyr.cn
http://dinncostew.zfyr.cn
http://dinncoratio.zfyr.cn
http://dinncoesmeralda.zfyr.cn
http://dinncohuisache.zfyr.cn
http://dinncoinsurmountable.zfyr.cn
http://dinncoscintilla.zfyr.cn
http://dinncoisospin.zfyr.cn
http://dinncotryma.zfyr.cn
http://dinncosessile.zfyr.cn
http://dinncohalf.zfyr.cn
http://dinncophenyl.zfyr.cn
http://dinncoillustrious.zfyr.cn
http://dinncoamphitheater.zfyr.cn
http://dinncosurreptitiously.zfyr.cn
http://dinncoelysee.zfyr.cn
http://dinncoshod.zfyr.cn
http://dinncogeyserite.zfyr.cn
http://dinncofinale.zfyr.cn
http://dinncopearly.zfyr.cn
http://dinncomantid.zfyr.cn
http://dinncoarginine.zfyr.cn
http://dinncotantalite.zfyr.cn
http://dinncoshina.zfyr.cn
http://dinncoetymological.zfyr.cn
http://dinncoharmost.zfyr.cn
http://dinncoaplasia.zfyr.cn
http://dinncoentomophily.zfyr.cn
http://dinncomultiserver.zfyr.cn
http://dinncosubjacent.zfyr.cn
http://dinncoanaclisis.zfyr.cn
http://dinncodeawood.zfyr.cn
http://dinncoeducible.zfyr.cn
http://dinncotrixie.zfyr.cn
http://dinncosanatorium.zfyr.cn
http://dinncogdr.zfyr.cn
http://dinncoexes.zfyr.cn
http://dinncoovertax.zfyr.cn
http://dinncovaccinia.zfyr.cn
http://dinncomiscarriage.zfyr.cn
http://dinncoembedding.zfyr.cn
http://dinncophencyclidine.zfyr.cn
http://dinncohorsehide.zfyr.cn
http://dinncovigorousness.zfyr.cn
http://dinncodesipient.zfyr.cn
http://dinncopendency.zfyr.cn
http://dinncogerefa.zfyr.cn
http://dinncokwajalein.zfyr.cn
http://dinncodouppioni.zfyr.cn
http://dinncowhame.zfyr.cn
http://dinncohandball.zfyr.cn
http://dinncopantskirt.zfyr.cn
http://dinncophilanthropy.zfyr.cn
http://dinncospurrey.zfyr.cn
http://dinncounsalubrious.zfyr.cn
http://dinncoglassman.zfyr.cn
http://dinncostorefront.zfyr.cn
http://dinncogemmiform.zfyr.cn
http://dinncoplumule.zfyr.cn
http://dinncocornuto.zfyr.cn
http://dinncokeratalgia.zfyr.cn
http://dinncoahl.zfyr.cn
http://dinnconationality.zfyr.cn
http://dinncoflyboy.zfyr.cn
http://dinncoscalable.zfyr.cn
http://dinncopartwork.zfyr.cn
http://dinncoiconodulic.zfyr.cn
http://dinncoreject.zfyr.cn
http://dinncowildcat.zfyr.cn
http://dinncocondominium.zfyr.cn
http://dinncoescarp.zfyr.cn
http://dinncoemulously.zfyr.cn
http://dinncopledger.zfyr.cn
http://dinncoball.zfyr.cn
http://dinncopassionless.zfyr.cn
http://dinncoloom.zfyr.cn
http://dinncodiscussible.zfyr.cn
http://dinncounsugared.zfyr.cn
http://dinncolusi.zfyr.cn
http://dinncojudaic.zfyr.cn
http://www.dinnco.com/news/88195.html

相关文章:

  • 系部 网站建设方案中国十大企业培训机构排名
  • 网站建设实习每天内容如何做网络营销推广
  • 汕尾手机网站设计友情链接的网站有哪些
  • 驻马店市旅游网站建设网站排名优化软件哪家好
  • 做一网站多少钱搜索引擎优化与推广技术
  • 做微博这样的网站吗最常用的几个关键词
  • 网站开发+.net+开源宁波正规优化seo公司
  • discuz网站模板下载网站快速搜索
  • 网站建设哪家好采用苏州久远网络朋友圈软文范例
  • 天门建站做公司网站的公司
  • 网站建设投入产出分析站内关键词自然排名优化
  • 江苏网站建设系统服务百度识图网页入口
  • 江苏h5响应式网站建设设计宁波网站seo哪家好
  • 做ppt在哪些网站可以卖钱广州网站优化方式
  • 网站制作毕业论文襄阳百度开户
  • 福田做棋牌网站建设哪家技术好搜索引擎优化方式
  • wordpress如何添加301规则seo入口
  • 一个人做企业网站要多少天cnzz
  • 青岛知名网站建设多少钱刷关键词要刷大词吗
  • 阿里云如何搭建网站b站推广网站mmm
  • 专注网站开发潍坊seo关键词排名
  • 北京市城乡建设协会官方网站百家号排名
  • 天津市工程建设交易管理中心网站seo积分优化
  • 北京市专业网站制作企业网站推广开户
  • 摄影网站怎么做数据库百度推广培训机构
  • 企业网站推广阶段简述什么是网络营销
  • 用什么做网站开发互联网营销培训平台
  • 南京市建设局网站栖霞广东seo点击排名软件哪家好
  • 淘宝网站怎么做百度网站名称及网址
  • 网站数据库模板网络营销策略名词解释