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

中国建设银行预约网站朋友圈广告30元 1000次

中国建设银行预约网站,朋友圈广告30元 1000次,本科学计算机是做网站吗,b2c网站建设策略文章目录 一、大模型服务平台[百炼](https://help.aliyun.com/zh/model-studio/getting-started)二、Java sdk调用与eventStream三、百炼平台其它 一、大模型服务平台百炼 百炼是阿里新出的一个大模型服务平台,聚合了多个千问大模型及其它一些大模型的调用&#xf…

文章目录

  • 一、大模型服务平台[百炼](https://help.aliyun.com/zh/model-studio/getting-started)
  • 二、Java sdk调用与eventStream
  • 三、百炼平台其它

一、大模型服务平台百炼

百炼是阿里新出的一个大模型服务平台,聚合了多个千问大模型及其它一些大模型的调用,暴露了一个同一的http请求入口,调用接口需要申请一个apikey,不需apisecret用于计费,有免费额度,较小的模型很便宜,各语言可以直接拼接请求参数发起http调用,主流开发语言python,Java等还提供了SDK使用起来更方便。

二、Java sdk调用与eventStream

package com.example.demo.qianwen;import java.util.Arrays;
import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationParam;
import com.alibaba.dashscope.common.Message;
import com.alibaba.dashscope.common.Role;
import lombok.SneakyThrows;public class Main {@SneakyThrowspublic static void main(String[] args) {Generation gen = new Generation();Message systemMsg = Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();Message userMsg = Message.builder().role(Role.USER.getValue()).content("Java udp代码案例?").build();GenerationParam param = GenerationParam.builder().model("qwen-turbo").apiKey("sk-f6a3b3**************") // 替换自己的.messages(Arrays.asList(systemMsg, userMsg)).resultFormat(GenerationParam.ResultFormat.MESSAGE).temperature(0.8f).incrementalOutput(true).build();// String content = gen.call(param).getOutput().getChoices().get(0).getMessage().getContent();gen.streamCall(param).blockingSubscribe(generationResult -> {System.out.println(generationResult.getOutput().getText());});}
}

这里获取模型推理结果有两种方式:call一次性获取全部结果与sreamCall流式获取数据。后者是比较常用的,因为模型推理往往需要数秒设置更长时间,推理出一点数据就先给用户展示,避免干等。这里持续往前端推送数据比不是websocket,而是利用了HTTP自带的一种更轻量的特性eventStream,用法比较类似websocket。如上代码只需要在streamCall回调函数中改为使用httpserverlet response对象将数据发送到前端即可(注意添加一个响应头Content-Type: text/event-stream;charset=UTF-8)
`1在这里插入图片描述
springboot web支持了http这种特性,往前端send数据调用SseEmitter 的方法即可,它会帮我们加上必要的响应头,如上代码streamCall回调函数中改为SseEmitter的send方法即可。

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;@RestController
public class SseController {private static final Map<Long, SseEmitter> emitters = new ConcurrentHashMap<>();private static final AtomicInteger eventId = new AtomicInteger(0);@GetMapping("/sse/events")public SseEmitter getEvents() {SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);Long id = System.currentTimeMillis();emitters.put(id, emitter);// 发送初始事件sendToClient(emitter, "Welcome to the SSE example!");// 设置超时处理emitter.onTimeout(() -> emitters.remove(id));// 设置错误处理emitter.onCompletion(() -> emitters.remove(id));return emitter;}public void sendToClient(SseEmitter emitter, String message) {try {emitter.send(SseEmitter.event().id(String.valueOf(eventId.incrementAndGet())).name("sse").data(message));} catch (Exception e) {emitters.values().removeIf(ee -> ee.equals(emitter));}}
}

前端处理示例

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>SSE Example</title>
</head>
<body><h1>Server-Sent Events Demo</h1><ul id="events-list"></ul><script>// 创建EventSource实例const source = new EventSource('/sse/events');// 当接收到新的事件时source.onmessage = function(event) {// 解析接收到的数据const data = JSON.parse(event.data);// 在页面上显示数据displayEvent(data);};// 当发生错误时source.onerror = function(event) {console.error('Error occurred:', event);// 如果连接丢失,可以尝试重新连接// source.close(); // 关闭连接};// 显示事件数据function displayEvent(data) {const list = document.getElementById('events-list');const item = document.createElement('li');item.textContent = data.message;list.appendChild(item);}</script>
</body>
</html>

三、百炼平台其它

百炼平台文档非常齐全,这里主要再总结一下
//TODO

http://www.tj-hxxt.cn/news/30714.html

相关文章:

  • 打开网站代码三十个知识点带你学党章
  • 网站设计的基本原则百度关键词自然排名优化公司
  • 虚拟钱包对接网站开发视频教程网上营销网站
  • 手机网站一年维护费推广业务平台
  • 汉沽做网站青岛网站建设优化
  • 山东网站建设好不好湖南网站建设效果
  • 做 直销网站 公司排名优化公司哪家靠谱
  • 怎么在word里做网站google 网站推广
  • 西安门户网站建设公司哪家好网络营销环境分析包括哪些内容
  • 网站的基本要素基本seo技术在线咨询
  • 彩虹网站建设在线seo短视频
  • 做发型的网站合肥网络seo推广服务
  • 做网站的项目职责怎么写百度网址大全网址导航
  • 专做运动装的网站提高网站收录的方法
  • 高端企业网站建设搜索app下载
  • 南昌电子商务网站建设网站链接查询
  • java开发网站跟php开发网站区别网络推广吧
  • 白城网站开发真实有效的优化排名
  • 做论坛网站多少钱webview播放视频
  • 在哪个网站可以自助建站精准大数据获客系统
  • 汕头个人建站模板正规seo关键词排名网络公司
  • 免费微信微网站模板下载不了沈阳关键词优化报价
  • 微信服务商平台官网seo做得比较好的公司
  • 百度一下建设部网站seo关键词排名网络公司
  • 邮箱域名与网站域名会冲突吗搜索引擎网页
  • 东莞网站建设的价格今日军事头条
  • 英文网站营销百度竞价推广开户
  • 做网站运营有前途吗青岛关键词排名系统
  • 成都网站建设公司高新成都互联网公司排名
  • 网站做赌博做任务百度热门搜索排行榜