整体思路是:

1创建ram用户,授权

2上传文件获取FileSession

3调用智能体对话,传入FileSession

接下来每个步骤的细节:
1官方不推荐使用超级管理员用户获得accessKeyId和accessKeySecret,所以登录超级管理员账号创建ram用户,给这个用户授权想用的权限即可
创建ram用户 可以使用官方概览这里有个快速开始,我这里只是想开发人员使用key,所以选择了“创建程序用户”
在这里插入图片描述
在这里插入图片描述
最重要的需要授权
点击上个页面上的授权,搜素AliyunBailianFullAccess或AliyunBailianControlFullAccess。然后第二步授予workspace权限授予工作空间权限!这个不要忘否则调用的时候会报“401”

在这里插入图片描述
在这里插入图片描述
2上传文件主要有三个步骤,官方文档快速开始里面有在线调试和sdk开始。看官网就行。
上传文档参数说明
在这里插入图片描述

api接口调用在线调试
在这里插入图片描述
注意这个上传文档可以使用oss,但是需要是公开的,于是我使用本地文档上传,通用写法。我使用的是java,传入ossId为文档id,也可以直接换成本地绝对路径,就不需要从ossId转localFilePath了,其中的params 放入按照前面获取到的数据放入即可,如

` private static Map<String, String> params = new HashMap<>();static {params.put("accessKeyId", " ");params.put("accessKeySecret", " ");params.put("workspaceId", "  ");params.put("apiKey", "sk- ");params.put("appId", " ");`
    public String getFileSession(Long ossId) throws IOException {String localFilePath = "";if (null!=ossId) {Path downloadedPath = null;try {downloadedPath = this.getTempFullFilePath(ossId);if (!StrUtil.isBlankIfStr(downloadedPath)) {String strPath = downloadedPath.toAbsolutePath().toString();localFilePath = strPath;} else {return null;}//上传bailian文件init(localFilePath);/* 1.上传文件 *//** 1.1.申请文档上传租约 **/StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder().accessKeyId(params.get("accessKeyId")).accessKeySecret(params.get("accessKeySecret")).build());AsyncClient client = AsyncClient.builder().credentialsProvider(provider)configuration rewrite, can set Endpoint, Http request parameters, etc..overrideConfiguration(ClientOverrideConfiguration.create().setEndpointOverride("bailian.cn-beijing.aliyuncs.com")).build();ApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = ApplyFileUploadLeaseRequest.builder().categoryType(params.get("CategoryType")).categoryId(params.get("CategoryId") ).fileName(params.get("fileName")).md5(params.get("fileMd5")).sizeInBytes(params.get("fileLength")).workspaceId(params.get("workspaceId"))// Request-level configuration rewrite, can set Http request parameters, etc.// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())).build();// Asynchronously get the return value of the API requestCompletableFuture<ApplyFileUploadLeaseResponse> response = client.applyFileUploadLease(applyFileUploadLeaseRequest);// Synchronously get the return value of the API requestApplyFileUploadLeaseResponse resp = response.get();System.out.println("- 申请文档上传租约结果: " + new Gson().toJson(resp));ApplyFileUploadLeaseResponseBody.Param param = resp.getBody().getData().getParam();/** 1.2.上传文档至阿里云百炼的临时存储 **/HttpURLConnection connection = null;try {URL url = new URL(param.getUrl());connection = (HttpURLConnection) url.openConnection();connection.setRequestMethod("PUT");connection.setDoOutput(true);JSONObject headers = JSONObject.parseObject(JSONObject.toJSONString(param.getHeaders()));connection.setRequestProperty("X-bailian-extra", headers.getString("X-bailian-extra"));connection.setRequestProperty("Content-Type", headers.getString("Content-Type"));try (DataOutputStream outStream = new DataOutputStream(connection.getOutputStream());FileInputStream fileInputStream = new FileInputStream(params.get("filePath"))) {byte[] buffer = new byte[4096];int bytesRead;while ((bytesRead = fileInputStream.read(buffer)) != -1) {outStream.write(buffer, 0, bytesRead);}outStream.flush();}// 检查响应int responseCode = connection.getResponseCode();if (responseCode == HttpURLConnection.HTTP_OK) {// 文档上传成功处理System.out.println("- 上传文件成功");} else {// 文档上传失败处理System.out.println("Failed to upload the file. ResponseCode: " + responseCode);}} catch (Exception e) {e.printStackTrace();} finally {if (connection != null) {connection.disconnect();}}/** 1.3.将文档添加至阿里云百炼的数据管理 **/AddFileRequest addFileRequest = AddFileRequest.builder().categoryType("SESSION_FILE").leaseId(resp.getBody().getData().getFileUploadLeaseId()).parser("DASHSCOPE_DOCMIND").categoryId("default").workspaceId(params.get("workspaceId"))// Request-level configuration rewrite, can set Http request parameters, etc.// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())).build();// Asynchronously get the return value of the API requestCompletableFuture<AddFileResponse> addFileresponse = client.addFile(addFileRequest);// Synchronously get the return value of the API requestAddFileResponse addFileresp = addFileresponse.get();System.out.println("- 将文档添加至阿里云百炼的数据管理结果: " + new Gson().toJson(addFileresp));// Finally, close the clientString fileId = addFileresp.getBody().getData().getFileId();System.out.println("- fileId: " + fileId);/** 1.4.查看文件是否解析 **/DescribeFileRequest describeFileRequest = DescribeFileRequest.builder().workspaceId(params.get("workspaceId")).fileId(fileId).build();// Asynchronously get the return value of the API requestString status = null;while (status == null || !status.equals("FILE_IS_READY")) {CompletableFuture<DescribeFileResponse> describeResponse = client.describeFile(describeFileRequest);// Synchronously get the return value of the API requestDescribeFileResponse describeResp = describeResponse.get();if (describeResp.getBody() == null) {continue;}if (describeResp.getBody().getData() == null) {continue;}status = describeResp.getBody().getData().getStatus();if (status == null) {continue;}System.out.println("- fileId状态: " + status);Thread.sleep(500);}// 关闭client.close();return fileId;} catch (Exception e) {log.error("处理ossId为 {} 的文件失败: {}",ossId, e.getMessage(), e);} finally {Path tempDir = null;if (null != downloadedPath) {tempDir = downloadedPath.getParent().toAbsolutePath();}if (null != tempDir) {// 递归删除目录(包括所有子目录和文件)Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {@Overridepublic FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {// 删除文件Files.delete(file);return FileVisitResult.CONTINUE;}@Overridepublic FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {// 删除空目录Files.delete(dir);return FileVisitResult.CONTINUE;}});}log.info("临时目录已删除!");}}return localFilePath;}public static String getMD5Checksum(File file) throws IOException, NoSuchAlgorithmException {FileInputStream fis = new FileInputStream(file);MessageDigest digest = MessageDigest.getInstance("MD5");FileChannel fileChannel = fis.getChannel();MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());// 使用MappedByteBuffer可以更高效地读取大文件digest.update(buffer);byte[] hashBytes = digest.digest();// 将字节数组转换为十六进制字符串StringBuilder hexString = new StringBuilder();for (byte b : hashBytes) {String hex = Integer.toHexString(0xff & b);if (hex.length() == 1) hexString.append('0');hexString.append(hex);}fileChannel.close();fis.close();return hexString.toString();}

3调用智能体

        ApplicationParam aiParam = ApplicationParam.builder().apiKey("sk- ").appId(" ")  
//        增量输出,即后续输出内容不包含已输出的内容。实时地逐个读取这些片段以获得完整的结果。.incrementalOutput(true).prompt(chatModelDto.getMessage())//可传入历史记录
//            .messages().ragOptions(RagOptions.builder().sessionFileIds(fileSessionList).build()).build();Application application = new Application();ApplicationResult result = application.call(aiParam);String text = result.getOutput().getText();return text;
//流式输出 createResult可忽略,返回Flux<String>
//        Application application = new Application();
//        Flowable<ApplicationResult> result = application.streamCall(aiParam);
//        Flux<Result> resultFlux = Flux.from(result)
//            .map(applicationResult -> {
//                 String response = applicationResult.getOutput().getText();
//                return createResult(response);
//            });
//        return resultFlux;

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

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

相关文章

剪映里面导入多张照片,p图后如何再导出多张照片?

剪映普通版本暂时没发现可以批量导出图片。这里采用其他方式实现。先整体导出视频。这里前期要注意设置帧率&#xff0c;一张图片的时长。 参考一下设置&#xff0c;帧率设置为30&#xff0c;图片导入时长设置为1s&#xff0c;这样的话&#xff0c;方便后期把视频切割为单帧。导…

怎么查看Linux I2C总线挂载了那些设备?

1. 根据系统启动查看设备树节点文件&#xff08;系统运行后的&#xff09; 比如&#xff1a;要查看I2C2i2c2: i2cfeaa0000 {compatible "rockchip,rk3588-i2c", "rockchip,rk3399-i2c";reg <0x0 0xfeaa0000 0x0 0x1000>;clocks <&cru CLK_…

bat脚本实现获取非微软官方服务列表

Get-CimInstance -ClassName Win32_Service |Where-Object { $_.State -eq Running -and $_.StartMode -ne Disabled } | ForEach-Object {$isMicrosoft $false$signerInfo 无可执行路径if ($_.PathName) {# 提取可执行文件路径&#xff08;处理带引号/参数的路径&#xff09…

小程序难调的组件

背景。做小程序用到了自定义表单。前后端都是分开写的&#xff0c;没有使用web-view。所以要做到功能对称时间选择器。需要区分datetime, year, day等类型使用uview组件较方便 <template><view class"u-date-picker" v-if"visible"><view c…

从零构建TransformerP2-新闻分类Demo

欢迎来到啾啾的博客&#x1f431;。 记录学习点滴。分享工作思考和实用技巧&#xff0c;偶尔也分享一些杂谈&#x1f4ac;。 有很多很多不足的地方&#xff0c;欢迎评论交流&#xff0c;感谢您的阅读和评论&#x1f604;。 目录引言1 一个完整的Transformer模型2 需要准备的“工…

qt qml实现电话簿 通讯录

qml实现电话簿&#xff0c;基于github上开源代码修改而来&#xff0c;增加了搜索和展开&#xff0c;效果如下 代码如下 #include <QGuiApplication> #include <QQmlApplicationEngine>int main(int argc, char *argv[]) {QCoreApplication::setAttribute(Qt::AA_…

顺序表——C语言

顺序表实现代码解析与学习笔记一、顺序表基础概念顺序表是线性表的一种顺序存储结构&#xff0c;它使用一段连续的内存空间&#xff08;数组&#xff09;存储数据元素&#xff0c;通过下标直接访问元素&#xff0c;具有随机访问的特性。其核心特点是&#xff1a;元素在内存中连…

【Oracle篇】Oracle Data Pump远程备份技术:直接从远端数据库备份至本地环境

&#x1f4ab;《博主主页》&#xff1a;    &#x1f50e; CSDN主页__奈斯DB    &#x1f50e; IF Club社区主页__奈斯、 &#x1f525;《擅长领域》&#xff1a;擅长阿里云AnalyticDB for MySQL(分布式数据仓库)、Oracle、MySQL、Linux、prometheus监控&#xff1b;并对…

Linux系统--文件系统

大家好&#xff0c;我们今天继续来学习Linux系统部分。上一次我们学习了内存级的文件&#xff0c;下面我们来学习磁盘级的文件。那么话不多说&#xff0c;我们开始今天的学习&#xff1a; 目录 Ext系列⽂件系统 1. 理解硬件 1-1 磁盘、服务器、机柜、机房 1-2 磁盘物理结构…

KUKA库卡焊接机器人氩气节气设备

在焊接生产过程中&#xff0c;氩气作为一种重要的保护气体被广泛应用于KUKA库卡焊接机器人的焊接操作中。氩气的消耗往往是企业生产成本的一个重要组成部分&#xff0c;因此实现库卡焊接机器人节气具有重要的经济和环保意义。WGFACS节气装置的出现为解决这一问题提供了有效的方…

远程连接----ubuntu ,rocky 等Linux系统,WindTerm_2.7.0

新一代开源免费的终端工具-WindTerm github 27.5k⭐ https://github.com/kingToolbox/WindTerm/releases/download/2.7.0/WindTerm_2.7.0_Windows_Portable_x86_64.zip 主机填写你自己要连接的主机ip 端口默认 22 改成你ssh文件配置的端口 输入远程的 用户名 与密码 成功连接…

笔试——Day32

文章目录第一题题目思路代码第二题题目&#xff1a;思路代码第三题题目&#xff1a;思路代码第一题 题目 素数回文 思路 模拟 构建新的数字&#xff0c;判断该数是否为素数 代码 第二题 题目&#xff1a; 活动安排 思路 区间问题的贪⼼&#xff1a;排序&#xff0c;然…

超高车辆如何影响城市立交隧道安全?预警系统如何应对?

超高车辆对立交隧道安全的潜在威胁在城市立交和隧道中&#xff0c;限高设施的设计通常考虑到大部分正常通行的货车和运输车辆。然而&#xff0c;一些超高的货车、集装箱车或特殊车辆如果未经有效监测而进入限高区域&#xff0c;就可能对道路设施造成极大的安全隐患。尤其在立交…

解决 MinIO 上传文件时报 S3 API Requests must be made to API port错误

在使用 MinIO 进行文件上传时&#xff0c;我遇到了一个比较坑的问题。错误日志如下&#xff1a; io.minio.errors.InvalidResponseException: Non-XML response from server. Response code: 400, Content-Type: text/xml; charsetutf-8, body: <?xml version"1.0&quo…

linux_https,udp,tcp协议(更新中)

目录 https 加密类型 对称加密 非对称加密 加密方案 只用对程加密 只用非对程加密 双方都是用非对程加密 非对称对称加密 非对称对称加密证书 流程图 校验流程图 udp udp协议格式 特点 UDP缓冲区 tcp tcp协议格式 32位序号及确认序号 4位首部 6位标志位 1…

web端-登录页面验证码的实现(springboot+vue前后端分离)超详细

目录 一、项目技术栈 二、实现效果图 ​三、实现路线 四、验证码的实现步骤 五、完整代码 1.前端 2.后端 一、项目技术栈 登录页面暂时涉及到的技术栈如下: 前端 Vue2 Element UI Axios&#xff0c;后端 Spring Boot 2 MyBatis MySQL JWT Maven 二、实现效果图…

疯狂星期四文案网第33天运营日记

网站运营第33天&#xff0c;点击观站&#xff1a; 疯狂星期四 crazy-thursday.com 全网最全的疯狂星期四文案网站 运营报告 今日访问量 今日搜索引擎收录情况 必应收录239个页面&#xff0c;还在持续增加中&#xff0c;已经获得必应的认可&#xff0c;逐渐收录所有页面 百度…

客户端利用MinIO对服务器数据进行同步

MinIO 是一款高性能、开源的对象存储服务&#xff0c;专为海量数据存储设计&#xff0c;兼容 Amazon S3 API&#xff08;即与 AWS S3 协议兼容&#xff09;&#xff0c;可用于构建私有云存储、企业级数据湖、备份归档系统等场景。它以轻量、灵活、高效为核心特点&#xff0c;广…

WPF 双击行为实现详解:DoubleClickBehavior 源码分析与实战指南

WPF 双击行为实现详解:DoubleClickBehavior 源码分析与实战指南 文章目录 WPF 双击行为实现详解:DoubleClickBehavior 源码分析与实战指南 引言 一、行为(Behavior)基础概念 1.1 什么是行为? 1.2 行为的优势 二、DoubleClickBehavior 源码分析 2.1 类定义与依赖属性 2.2 双…

零知开源——基于STM32F103RBT6的TDS水质监测仪数据校准和ST7789显示实战教程

✔零知开源是一个真正属于国人自己的开源软硬件平台&#xff0c;在开发效率上超越了Arduino平台并且更加容易上手&#xff0c;大大降低了开发难度。零知开源在软件方面提供了完整的学习教程和丰富示例代码&#xff0c;让不懂程序的工程师也能非常轻而易举的搭建电路来创作产品&…