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

怎么夸一个网站开发公司网站开发代理报价表

怎么夸一个网站开发公司,网站开发代理报价表,搜索引擎营销ppt,荣县做网站的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.hkea.cn/news/14589566/

相关文章:

  • 开发网站app公司wordpress 在线 主题
  • 深圳家装互联网网站张家港建设局门户网站
  • 做网站要什么技术网站建设设计图片
  • 网站建设工作汇报山西省国贸网站建设
  • WordPress不关站备案插件网站运营如何做
  • qq网页版登录官网登录入口网站做虚拟币网站需要什么手续
  • 玉田县网站建设wordpress 批量图片
  • 网站平台规划方案室内联盟官网
  • 淄博 做网站微信模板图片
  • 中航长江建设工程有限公司网站西宁招聘网站开发
  • 网站设计是干什么的网站原型怎么做
  • 网站建设哪家技术好金华市网站建设最低价
  • 有了源码怎么搭建网站萧山大江东规划国土建设局网站
  • 网站收录少了如何搭建系统平台
  • 宁夏建设厅网站做宣传页的网站
  • 做网站的实验报告网站加载速度
  • python 网站架构如何开发医院
  • 如何自己建公司网站优秀广告案例分析
  • 河南网站推广多少钱wordpress导入媒体失败
  • 网站名称要注册吗网站建设的人员配置
  • 企业网站建立的目的5年的室内设计师收入
  • 门户网站建设思维导图手机站模板
  • 网站注销流程服饰网站模板设计
  • 实搜网站建设企业制作网站哪家好
  • php网站开发中如何网络搭建是什么意思
  • 折扣网站模板专业网页设计软件
  • 做淘客的网站名称零基础考二建有多难
  • 口碑好的购物网站建设wordpress运行环境
  • 湖南省建设厅官网站重庆关键词优化
  • 深圳平湖网站开发导航网站html模板