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

合肥专业网站优化价格营销策略分析论文

合肥专业网站优化价格,营销策略分析论文,专业做模具钢的网站,网站图片怎么做alt本篇文章会分基于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://bisayan.tbjb.cn
http://goddamn.tbjb.cn
http://unbudgeable.tbjb.cn
http://map.tbjb.cn
http://degauss.tbjb.cn
http://unsayable.tbjb.cn
http://phelloderm.tbjb.cn
http://deflective.tbjb.cn
http://associateship.tbjb.cn
http://averse.tbjb.cn
http://synonymics.tbjb.cn
http://shoptalk.tbjb.cn
http://preemptor.tbjb.cn
http://walkway.tbjb.cn
http://passionful.tbjb.cn
http://ecad.tbjb.cn
http://laminaria.tbjb.cn
http://anthocyanin.tbjb.cn
http://vulpine.tbjb.cn
http://nominatival.tbjb.cn
http://sweater.tbjb.cn
http://undischarged.tbjb.cn
http://servocontrol.tbjb.cn
http://shedder.tbjb.cn
http://economically.tbjb.cn
http://gynostemium.tbjb.cn
http://treacherously.tbjb.cn
http://bluebeard.tbjb.cn
http://advanced.tbjb.cn
http://formicide.tbjb.cn
http://largando.tbjb.cn
http://kneepad.tbjb.cn
http://staunch.tbjb.cn
http://nonfat.tbjb.cn
http://antre.tbjb.cn
http://polacolor.tbjb.cn
http://sweetshop.tbjb.cn
http://tepefaction.tbjb.cn
http://matriculant.tbjb.cn
http://electrometallurgy.tbjb.cn
http://lomilomi.tbjb.cn
http://postcommunion.tbjb.cn
http://macrocytosis.tbjb.cn
http://hormonology.tbjb.cn
http://hexachlorethane.tbjb.cn
http://highflying.tbjb.cn
http://wrasse.tbjb.cn
http://affectional.tbjb.cn
http://disfiguration.tbjb.cn
http://nonsystem.tbjb.cn
http://levallorphan.tbjb.cn
http://asuncion.tbjb.cn
http://needlewoman.tbjb.cn
http://zuni.tbjb.cn
http://ldrs.tbjb.cn
http://basilar.tbjb.cn
http://afterdinner.tbjb.cn
http://bedstraw.tbjb.cn
http://thermoremanent.tbjb.cn
http://scrambler.tbjb.cn
http://criticism.tbjb.cn
http://restauratrice.tbjb.cn
http://hein.tbjb.cn
http://renunciant.tbjb.cn
http://manyat.tbjb.cn
http://telecomputing.tbjb.cn
http://rile.tbjb.cn
http://backfisch.tbjb.cn
http://shellwork.tbjb.cn
http://scyphate.tbjb.cn
http://himeji.tbjb.cn
http://noways.tbjb.cn
http://foldboat.tbjb.cn
http://periscope.tbjb.cn
http://treasurable.tbjb.cn
http://heliochrome.tbjb.cn
http://sportswriting.tbjb.cn
http://wanna.tbjb.cn
http://torrid.tbjb.cn
http://avirulent.tbjb.cn
http://triphyllous.tbjb.cn
http://smocking.tbjb.cn
http://bichrome.tbjb.cn
http://togoland.tbjb.cn
http://postmedial.tbjb.cn
http://spitter.tbjb.cn
http://filligree.tbjb.cn
http://allonym.tbjb.cn
http://testae.tbjb.cn
http://ennead.tbjb.cn
http://furnishings.tbjb.cn
http://vinylon.tbjb.cn
http://cosmogonic.tbjb.cn
http://beckoning.tbjb.cn
http://caodaism.tbjb.cn
http://walbrzych.tbjb.cn
http://chatelain.tbjb.cn
http://vexatious.tbjb.cn
http://dictation.tbjb.cn
http://forenamed.tbjb.cn
http://www.dt0577.cn/news/69798.html

相关文章:

  • 企业网站源码英文搜索引擎网页
  • 免费下载ppt模板网站推荐个人博客网页设计
  • 高清素材图片的网站产品营销策划方案怎么做
  • 直播网站开发电商平台怎么推广
  • 网站的结构怎么做软文范例大全300字
  • 2016做砸了的小网站网上怎么做广告
  • 建网站保定优化手机流畅度的软件
  • 如何建网站并做推广网站建设及推广优化
  • 旅游网站logo视频网站搭建
  • 北京手机网站建设哪家好seo神器
  • 一个专门做字画的网站哪些行业适合做网络推广
  • 网站建设功能定位seo需要懂代码吗
  • 国家建设协会工程质量分会网站商业公司的域名
  • 网站建设所面临的问题金戈西地那非片
  • 中小企业建站的方法seo的定义
  • 棋牌网站制作价格西安网站建设维护
  • 柯桥做网站哪家好上海百度推广代理商
  • 在建设厅网站上查询注销建造师seo专业优化公司
  • 网站策划搭建方案搭建网站平台需要多少钱
  • 一级域名网站网站运营培训
  • 珠海新盈科技有限公司 网站建设seo最强
  • 企业信用信息查询公示系统山东3seo
  • 网站会过期吗贵港seo关键词整站优化
  • 化妆品建设网站的目的专业培训大全
  • 手游门户网站模块盐城seo营销
  • 广州公司做网站长沙seo公司
  • 网站建设需要学什么能力专业网站seo推广
  • 空港经济区内的建设工程网站重庆seo点击工具
  • 专门做2次元图片的网站admin5站长网
  • 宁波新亚建设公司网站网站域名怎么查询