springboot+langchain4j 实战 Day12 实现流式对话 + 打字机效果的前端聊天页面

📅 2026/6/26 13:03:53
springboot+langchain4j 实战 Day12 实现流式对话 + 打字机效果的前端聊天页面
Day 12 — SSE 流式对话完成内容目标实现流式对话 打字机效果的前端聊天页面替代 curl 调试实现成果可视化。后端改动ChatModelConfig.java— 新增StreamingChatLanguageModelBean使用OpenAiStreamingChatModel硅基流动兼容 OpenAI streaming 协议超时 120s流式需要更长等待SSEController1.java— 从 Day1 迁移适配 Day12 包结构GET /stream/chat?messagexxx返回text/event-stream逐 token 推送SseEmitter 超时 2 分钟application.yml— 端口 8088、去 Jasypt、明文 API Keypom.xml— 去 Jasypt 依赖、修正包名版本号前端 (static/index.html)纯原生 HTML/CSS/JS零依赖暗色主题Tailwind 色板风格双模式切换⚡ 流式EventSource → SSE → 逐 token 追加 闪烁光标打字机效果 Agentfetch /agent/chat → JSON 一次性返回输入框 Enter 发送响应式自适应验证结果Agent 端点curl http://localhost:8088/agent/chat?messagehi→{code:200,data:Hello!...}✅SSE 端点curl http://localhost:8088/stream/chat?message你好→ 逐 token 流式输出 ✅前端页面http://localhost:8088/index.html正常加载 ✅Agent 端点SSE 端点:居然乱码了换成postman前端页面流式输出测试踩坑密钥不能加密不然报错访问方式启动项目后浏览器打开http://localhost:8088/index.html