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

怎么夸一个网站开发公司西宁网站建设建站

怎么夸一个网站开发公司,西宁网站建设建站,专业网站制作公司是如何处理一个优秀网站的,电子商务网站建设设计方案SSE SSE#xff08;Server-Sent Events#xff0c;服务器发送事件#xff09;是一种基于HTTP协议的通信技术#xff0c;它允许服务器持续地将数据推送给客户端#xff0c;而无需客户端发起请求。这种通信方式通常用于实时性要求较高的场景#xff0c;如实时更新、通知、或…SSE SSEServer-Sent Events服务器发送事件是一种基于HTTP协议的通信技术它允许服务器持续地将数据推送给客户端而无需客户端发起请求。这种通信方式通常用于实时性要求较高的场景如实时更新、通知、或者数据流式传输。 SSE与传统的Ajax轮询或长轮询相比具有更低的延迟、更高的效率并且更易于实现。它建立在HTTP协议之上利用HTTP/1.1的持久连接允许服务器在连接建立后持续地向客户端发送数据客户端通过监听一个HTTP连接来接收这些数据。 在Web开发中服务器通常会使用特殊的HTTP响应头如Content-Type: text/event-stream来指示客户端这是一个SSE流并且按照一定的格式发送事件数据给客户端。客户端则可以使用JavaScript中的EventSource对象来接收并处理这些事件从而实现实时的数据更新。 SseEmitter SseEmitter是Spring框架中的一个类专门用于Java。SSE代表服务器发送事件是一种使服务器能够通过HTTP向Web客户端推送数据更新的技术。SseEmitter是在Spring应用程序中实现SSE服务器支持的便捷方式。 使用SseEmitter您可以在Spring应用程序中创建一个端点客户端可以连接到该端点服务器可以通过此连接向客户端推送事件。这对于实时更新非常有用例如显示实时通知、进度更新或流式传输数据。 实现 OpenAI支持Stream流格式接收 接口连续的数据读取 官网示例 {id:chatcmpl-123,object:chat.completion.chunk,created:1694268190,model:gpt-3.5-turbo-0125, system_fingerprint: fp_44709d6fcb, choices:[{index:0,delta:{role:assistant,content:},logprobs:null,finish_reason:null}]}{id:chatcmpl-123,object:chat.completion.chunk,created:1694268190,model:gpt-3.5-turbo-0125, system_fingerprint: fp_44709d6fcb, choices:[{index:0,delta:{content:Hello},logprobs:null,finish_reason:null}]} ... {id:chatcmpl-123,object:chat.completion.chunk,created:1694268190,model:gpt-3.5-turbo-0125, system_fingerprint: fp_44709d6fcb, choices:[{index:0,delta:{},logprobs:null,finish_reason:stop}]}demo private static final String API_KEY ********************;private static final Pattern contentPattern Pattern.compile(\content\:\(.*?)\});private static final String MODEL_ENGINE gpt-3.5-turbo;public static void test() throws InterruptedException, IOException {//params 的入参封装 这里省略 参考上面图片 或去官网 需要stream形式请求HttpRequest httpRequest HttpRequest.post(https://api.openai.com/v1/chat/completions).header(Content-Type, application/json).header(Authorization, Bearer API_KEY).body(JSONUtil.toJsonStr(params));//TODO 代理 到shadowsocks httpRequest.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(127.0.0.1, 7890)));HttpResponse execute httpRequest.execute();InputStream inputStream execute.bodyStream();BufferedReader bufferedReader new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));String line;while ((line bufferedReader.readLine()) ! null) {if (StringUtils.hasLength(line)) {System.out.println(line);Matcher matcher contentPattern.matcher(line);if (matcher.find()) {String content matcher.group(1);System.out.println(content);}}} } SSE发送 demo ChatController Autowiredprivate ChatService chatService;GetMapping(/test)public SseEmitter test(String question) {SseEmitter sseEmitter new SseEmitter();chatService.question(question, sseEmitter);return sseEmitter;}ChatService private static final String API_KEY ********************;private static final Pattern contentPattern Pattern.compile(\content\:\(.*?)\});Asyncpublic void question(String question, SseEmitter sseEmitter) {try {// 构建请求参数String params {\model\:\gpt-3.5-turbo\,\messages\:[{\role\:\user\,\content\:\ question \}],\stream\:true};// 发起 HTTP 请求HttpRequest httpRequest HttpRequest.post(https://api.openai.com/v1/chat/completions).header(Content-Type, application/json).header(Authorization, Bearer API_KEY).body(JSONUtil.toJsonStr(params)).setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(127.0.0.1, 7890)));// 执行 HTTP 请求HttpResponse execute httpRequest.execute();// 处理响应流try (InputStream inputStream execute.bodyStream();BufferedReader bufferedReader new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {String line;while ((line bufferedReader.readLine()) ! null) {if (StringUtils.hasLength(line)) {// 输出响应内容System.out.println(line);// 提取内容Matcher matcher contentPattern.matcher(line);if (matcher.find()) {String content matcher.group(1);System.out.println(content);// 发送 SSE 事件 模拟延迟)Thread.sleep(1000);sseEmitter.send(SseEmitter.event().name(answer).data({ content }));}}}}} catch (IOException | InterruptedException e) {// 异常处理throw new RuntimeException(e);} finally {// 完成 SSE 连接sseEmitter.complete();}} 测试
http://www.tj-hxxt.cn/news/222433.html

相关文章:

  • 秦皇岛网站开发公司电子商务网站建设与管理目录
  • 上海人才网站建设兰州seo快速优化报价
  • 公司网站在百度搜不到推广渠道有哪些平台
  • 艺术设计专业灵感推荐网站网站推广策划包含的内容
  • 鞍山网站设计公司工商注册系统
  • 做钓鱼网站会被抓判刑吗东莞什么行业做网站的多
  • 网站建设项目的工作分解wordpress mysql 5.7
  • 云抢购网官方网站网站代理合作
  • 漂亮的网站单页网上广告设计培训
  • 事业单位 网站备案平板微信hd版
  • 石家庄网站建设公司怎么样网站开发提成
  • 低价格制作网站手机小游戏网站
  • wamp做的网站外网怎么访问wordpress玻璃透主题
  • 专业积分商城网站建设外贸网站建设服务机构
  • 网加做网站推广重庆建设工程信息网三类人员
  • 专业网站开发制作公司做应用级网站用什么语言好
  • 信阳建设企业网站山西省城乡建设厅网站
  • 手机怎么做网站卖东西模板网站修改
  • 1高端网站建设直缝钢管网站建设
  • 南昌高端网站开发费用表南京移动网站建设报价
  • 专业苏州网站建设公司汽车品牌大全汽车网
  • wordpress会员介绍页株洲seo优化官网
  • 移动互联网平台有哪些西安seo培训
  • 上海装修网站建设摄影网站的意义
  • 网站设计目前和将来的就业前景ui网页设计方法
  • 做国外的众筹网站有哪些wordpress怎么都是英文
  • 在网站做博客美仑美家具的网站谁做的
  • 门户网站是用户上网的第一入口引流推广app
  • 公司网站备案去哪里备案火车头导入wordpress
  • 福清网站建设网络推广计划