网站主机与服务器广州越秀区发布

news/2025/9/28 17:10:57/文章来源:
网站主机与服务器,广州越秀区发布,宁波静态网站建设,域名注册服务的公司网站20分钟上手DeepSeek开发#xff1a;SpringBoot Vue2快速构建AI对话系统 前言 在生成式AI技术蓬勃发展的今天#xff0c;大语言模型已成为企业智能化转型和个人效率提升的核心驱动力。作为国产大模型的优秀代表#xff0c;DeepSeek凭借其卓越的中文语义理解能力和开发者友…20分钟上手DeepSeek开发SpringBoot Vue2快速构建AI对话系统 前言 在生成式AI技术蓬勃发展的今天大语言模型已成为企业智能化转型和个人效率提升的核心驱动力。作为国产大模型的优秀代表DeepSeek凭借其卓越的中文语义理解能力和开发者友好的API生态正在成为构建本土化AI应用的首选平台。本文将以Spring Boot3Vue2全栈技术为基础手把手带你打造一个具备以下特性的AI对话系统 实时流式对话交互体验支持Markdown代码块/表格的专业级内容渲染前端安全防护与响应式界面设计高扩展性的API接入架构。 为什么选择DeepSeek 中文语境专家针对中文语法特点优化歧义识别准确率提升40%极速响应国内服务器部署平均API延迟800ms成本可控免费试用阶梯定价模式个人项目月均成本低至5元流式输出支持chunked数据传输避免用户长时间等待。 技术架构解析 后端技术栈 SpringBoot 3.x快速构建RESTful APIWebFlux响应式流处理框架QPS可达3000Lombok通过注解简化POJO模型。 前端技术栈 Vue2.xWebSocket双向实时通信支持XSS防御DOMPurify过滤恶意脚本。 环境准备 JDK 17Node.js 12Maven 3.9Ollama。 后端项目初始化 pom依赖 ?xml version1.0 encodingUTF-8? modelVersion4.0.0/modelVersion parentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.3.8/versionrelativePath/!-- lookup parent from repository -- /parent groupIdcn.com.codingce/groupId artifactIddeepseek/artifactId version0.0.1-SNAPSHOT/version namedeepseek/name url/ licenseslicense/ /licenses developersdeveloper/ /developers scmconnection/developerConnection/tag/url/ /scm propertiesjava.version17/java.versionspring-ai.version1.0.0-M5/spring-ai.version /properties dependenciesdependencygroupIdorg.springframework.ai/groupIdartifactIdspring-ai-ollama-spring-boot-starter/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactId/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-websocket/artifactId/dependencydependencygroupIdorg.springframework.ai/groupIdartifactIdspring-ai-bom/artifactIdversion${spring-ai.version}/versiontypepom/typescopeimport/scope/dependency /dependencies buildpluginspluginartifactIdspring-boot-maven-plugin/artifactId/plugin/plugins /build /projectyml配置文件 server:port: 8080 spring:ai:ollama:base-url: http://localhost:11434chat:model: deepseek-r1:8bapplication:name: codingce-deepspeekwebflux:base-path: /codec:max-in-memory-size: 10MB logging:level:cn.com.codingce.deepseek: DEBUGorg.springframework.web: INFO核心服务实现 DeepSeekService 是一个核心服务类主要负责处理与 Ollama 的通信和数据处理。整个服务采用响应式编程模式Flux实现非阻塞式处理提高系统性能。同时通过日志记录确保服务的可靠性和稳定性。 package cn.com.codingce.deepseek.service;import cn.com.codingce.deepseek.model.Message; import cn.com.codingce.deepseek.model.MessageType; import cn.com.codingce.deepseek.model.OllamaResponse; import cn.com.codingce.deepseek.model.StreamResponse; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.ai.ollama.OllamaClient; import org.springframework.ai.ollama.OllamaException; import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono;import java.io.IOException; import java.util.ArrayList; import java.util.List;Service AllArgsConstructor Slf4j public class DeepSeekService {private final OllamaClient ollamaClient;private final ObjectMapper objectMapper;public FluxMessage generateResponse(String prompt) {return Flux.create(sink - {ListString messages new ArrayList();messages.add(prompt);try {ollamaClient.chat(deepseek-r1:8b, messages, response - {try {OllamaResponse ollamaResponse objectMapper.readValue(response, OllamaResponse.class);String content ollamaResponse.getContent();if (content ! null !content.isEmpty()) {sink.next(new Message(MessageType.ASSISTANT, content));}} catch (IOException e) {log.error(Error processing Ollama response, e);sink.error(e);}}, error - {log.error(Error from Ollama, error);sink.error(new RuntimeException(Error from Ollama, error));}, () - {log.info(Ollama chat completed);sink.complete();});} catch (OllamaException e) {log.error(Error initiating Ollama chat, e);sink.error(e);}});} }WebSocket控制器 WebSocketController 是一个 WebSocket 控制器用于处理前端与后端之间的实时通信。它支持消息的接收和发送并将用户的消息传递给 DeepSeekService然后将 AI 的响应实时推送给前端。 package cn.com.codingce.deepseek.controller;import cn.com.codingce.deepseek.model.Message; import cn.com.codingce.deepseek.service.DeepSeekService; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.stereotype.Controller; import reactor.core.publisher.FluxSink;import java.util.concurrent.ConcurrentHashMap;Controller public class WebSocketController {private final DeepSeekService deepSeekService;private final ConcurrentHashMapString, FluxSinkMessage sinks new ConcurrentHashMap();public WebSocketController(DeepSeekService deepSeekService) {this.deepSeekService deepSeekService;}MessageMapping(/chat)public void receiveMessage(String sessionId, String message) {sinks.putIfAbsent(sessionId, Flux.sink());FluxSinkMessage sink sinks.get(sessionId);deepSeekService.generateResponse(message).subscribe(sink::next, sink::error, sink::complete);}SendTo(/topic/messages/{sessionId})public FluxMessage sendMessage(String sessionId) {return Flux.create(sinks.get(sessionId));} }前端项目初始化 项目结构 前端项目基于 Vue2 构建主要包含以下目录结构 src/ ├── assets/ ├── components/ │ └── ChatWindow.vue ├── App.vue ├── main.js安装依赖 在项目根目录下运行以下命令安装依赖 npm install主组件 App.vue 是主组件用于加载聊天窗口组件。 templatediv idappChatWindow //div /templatescript import ChatWindow from ./components/ChatWindow.vue;export default {name: App,components: {ChatWindow} }; /scriptstyle #app {font-family: Avenir, Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px; } /style聊天窗口组件 ChatWindow.vue 是聊天窗口组件负责显示消息和处理用户输入。 templatediv classchat-windowdiv classmessagesdiv v-formessage in messages :keymessage.id classmessagediv :class[message-content, { assistant: message.type assistant }]div v-htmlmessage.content/div/div/div/divinput v-modelinputMessage keyup.entersendMessage placeholderType a message... //div /templatescript import { WebSocketSubject } from rxjs/webSocket; import DOMPurify from dompurify;export default {name: ChatWindow,data() {return {messages: [],inputMessage: ,sessionId: Date.now().toString(),ws: null};},mounted() {this.connectWebSocket();},methods: {connectWebSocket() {this.ws new WebSocketSubject(ws://localhost:8080/ws/chat/${this.sessionId});this.ws.subscribe((message) {const sanitizedMessage DOMPurify.sanitize(message.content);this.messages.push({ ...message, content: sanitizedMessage });},(error) console.error(WebSocket error:, error),() console.log(WebSocket closed));},sendMessage() {if (this.inputMessage.trim()) {this.ws.next(this.inputMessage);this.messages.push({ id: Date.now(), type: user, content: this.inputMessage });this.inputMessage ;}}},beforeDestroy() {if (this.ws) {this.ws.complete();}} }; /scriptstyle scoped .chat-window {width: 100%;max-width: 600px;margin: 0 auto;border: 1px solid #ccc;padding: 10px;border-radius: 5px; }.messages {height: 400px;overflow-y: scroll;margin-bottom: 10px; }.message {margin-bottom: 10px; }.message-content {padding: 5px;border-radius: 5px; }.message-content.assistant {background-color: #f0f0f0; }input {width: 100%;padding: 10px;box-sizing: border-box; } /style运行项目 启动后端 在后端项目启动 Spring Boot 应用 启动前端 在前端项目根目录下运行以下命令启动 Vue 项目 npm run serve打开浏览器访问 http://localhost:8080即可看到聊天窗口。输入消息后即可与 AI 进行实时对话。 希望这篇文章能帮助你快速上手 DeepSeek 开发开启你的 AI 应用构建之旅

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/920876.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

手机版传奇发布网站做一个个人网站的步骤

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 Linux 的字符串截取很有用。有八种方法。 假设有变量 varhttp://www.aaa.com/123.htm 1. # 号截取,删除左边字符,…

用dw自己做网站360网站建设的目标是什么

课程总计41课时,从什么是事务讲起,直到分布式事务解决方案,很的0基础基础与提升系列课程。对于难以理解的知识点,全部用画图实战的方式讲解。彻底明白事务的四个特性:原子性、一致性、隔离性、持久性,用场景…

常州个人网站建设网易企业邮箱价格表

文章目录 cpolar内网穿透工具 cpolar内网穿透工具 科学技术的发展日新月异,电子设备在人们的生活中已成为不可或缺的工具,甚至在很多情况下,各类型的电子设备已经成为工作的核心,虽然移动设备越来越小巧,功能也越来越…

2025 年最新编织袋生产厂家权威推荐排行榜:聚焦 TOP5 优质企业,助力企业精准甄选可靠合作伙伴牛皮纸/塑料/PP彩膜/化工/化肥编织袋厂家推荐

在工业、农业、食品等领域的生产流转中,编织袋作为关键包装载体,其品质、供应稳定性及定制能力直接关系到企业运营效率与产品安全。当前市场上编织袋生产厂家数量繁杂,部分企业存在质量管理缺失、产品承重不足、密封…

做装修的人到什么网站找工作怎样是做网站

docker学习第四天 docker学习第四天1. 回顾1.1. 容器的网络类型1.2. 容器的本质1.3. 数据的持久化1.4. 看有哪些卷1.5. 看卷的详细信息 2. 如何做多台宿主机里的多个容器之间的数据共享2.1. 概念2.2. 搭NFS服务器实现多个容器之间的数据共享的详细步骤2.3. 如果是多台机器&…

P11854 [CSP-J2022 山东] 宴会

P11854 [CSP-J2022 山东] 宴会 题解题目传送门 当时这个题是我考试题,考试的时候感性理解出来的三分做法。 首先咱感性理解一下,当\(x_0\)位于左边无穷远处时,答案是个很大的数。 然后随着\(x_0\)从左向右移动,答案…

2025 年试验机厂家权威推荐榜:TOP5 优质厂家综合实力解析,助力科研与工业客户精准选型电子万能材料/橡胶拉力/塑料拉力/扬州拉力试验机厂家推荐

在材料检测领域,试验机是保障科研数据精准性与工业质量管控效率的核心设备,其品质直接关系到实验进度推进与生产线稳定运行。当前市场上试验机供应商资质差异显著,部分厂商存在产品适配性差、技术支撑不足、售后响应…

# PostgreSQL高可用架构深度解析:从单机到分布式的演进之路

# PostgreSQL高可用架构深度解析:从单机到分布式的演进之路Posted on 2025-09-28 17:00 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:# PostgreSQL高可用架构深度解析:从单机到分布式的演进之路PostgreSQ…

洛阳做网站公司有哪些搭建一个网站多少钱

文章目录 前言一、问题重述二、主函数总结 前言 第十五蓝桥杯国赛落幕已有十天,是时候总结一下,这个专栏也将结束。虽然并没有取得预期的结果,但故事结尾并不总是美满的。下面是赛前练习的第十二届国赛的代码。 一、问题重述 二、主函数 完整…

跟Manus聊聊Bean生命周期设计哲学[From Manus]

跟Manus聊聊Bean生命周期设计哲学[From Manus]Posted on 2025-09-28 17:00 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:跟Manus聊聊Bean生命周期设计哲学[From Manus]Mind RoadmapBean生命周期设计哲学 “零…

Software Crisis and Complexity

Software Crisis and ComplexityPosted on 2025-09-28 17:00 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:Software Crisis and Complexity软件危机与复杂性:工程思维的诞生背景 核心要点 第一次软件危机(1…

Foojay 播客 #71:与 James Gosling 一起庆祝 Java 诞生 30 周年

Foojay 播客 #71:与 James Gosling 一起庆祝 Java 诞生 30 周年Posted on 2025-09-28 17:00 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:Foojay 播客 #71:与 James Gosling 一起庆祝 Java 诞生 30 周年htt…

# Stack Overflow 2011-2019开发者调查报告:技术生态演进史

# Stack Overflow 2011-2019开发者调查报告:技术生态演进史Posted on 2025-09-28 17:00 吾以观复 阅读(0) 评论(0) 收藏 举报关联知识库:# Stack Overflow 2011-2019开发者调查报告:技术生态演进史Stack Ove…

中国建设行业峰会官方网站改图网站

一、引言 在信息爆炸的时代,网络上蕴含着海量的数据。如果我们想要获取特定的信息,手动从网页上复制粘贴显然效率极低。这时,Web 爬虫就派上了用场。Web 爬虫是一种自动获取网页内容的程序,它可以模拟人类在浏览器中的操作,快速地抓取网页上的数据。本文将带领大家使用 Py…

langgraphjs-gen-ui-examples

langgraphjs-gen-ui-examples https://github.com/langchain-ai/langgraphjs-gen-ui-examplesLangGraph Generative UI ExamplesThis repository contains a series of agents intended to be used with the Agent Cha…

2025 年节能咨询公司最新权威推荐排行榜:覆盖工业 / 建筑 / 数据中心等领域 TOP5 优质企业综合测评与选型指南发电厂/燃气/全域增效/服务器节能公司推荐

在 “双碳” 目标深化推进的当下,企业对节能咨询服务的需求日益迫切,但市场现状却让企业面临诸多困扰。部分服务商技术单一,仅能解决局部能耗问题,无法实现全流程节能优化;有些服务商过度宣传,实际节能效果与承诺…

微算法科技(NASDAQ MLGO)探索全同态加密与安全多方计算融合,开启区块链隐私执行新时代

随着区块链应用场景不断拓展,跨分片复杂合约的隐私保护需求日益凸显。传统区块链技术在处理此类合约时,难以兼顾数据隐私与功能实现。交易数据和合约执行细节常以明文形式存储和处理,易导致敏感信息泄露。微算法科技…

杭州仪器网站制作海外运营是做什么的

戳蓝字“CSDN云计算”关注我们哦!2019年7月9日,IBM史上最大的一笔收购案终于尘埃落定,IBM以每股现金190.0美元,完成对红帽所有已发行和流通在外普通股的收购交易,总股本价值约340亿美元。至此,红帽这家全球…

国产SUB-1G芯片DP4363F支持119-1050mhz超低功耗 - 动能世纪

DP4363是一款高性能、低电流的收发器,覆盖了从119MHZ到1050MHz的频段。它是系列完整发射器、接收器和收发器产品中的组成部分,适用于各种广泛的应用场景。该设备具有卓越的灵敏度,达到-126dBm,同时实现了极低的运行…