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

苏州网站建设集团手机上如何上传wordpress

苏州网站建设集团,手机上如何上传wordpress,林州网站建设价格,什么是网络营销?网络营销的目的有哪些内容?直接用于拍照答题不大理想, 可能适用其他用途, 更好的方案: 阿里云百炼(1) : 阿里云百炼应用问答_回答图片问题_方案2_提取题目再提问-CSDN博客 1.实现代码 package cn.nordrassil.ly.test.拍照答题;import com.alibaba.dashscope.app.Application; import com.alibaba.dashsc…

直接用于拍照答题不大理想, 可能适用其他用途, 更好的方案: 阿里云百炼(1) : 阿里云百炼应用问答_回答图片问题_方案2_提取题目再提问-CSDN博客

1.实现代码

package cn.nordrassil.ly.test.拍照答题;import com.alibaba.dashscope.app.Application;
import com.alibaba.dashscope.app.ApplicationParam;
import com.alibaba.dashscope.app.ApplicationResult;
import com.alibaba.dashscope.app.RagOptions;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.sdk.service.bailian20231229.AsyncClient;
import com.aliyun.sdk.service.bailian20231229.models.*;
import com.google.gson.Gson;
import darabonba.core.client.ClientOverrideConfiguration;import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;public class 阿里云百炼应用问答_回答图片问题_方案1_提问时上传图片文件 {private static Map<String, String> params = new HashMap<>();static {params.put("accessKeyId", "");params.put("accessKeySecret", "");params.put("workspaceId", "");params.put("apiKey", "");params.put("appId", "");params.put("filePath", "C:\\Users\\admin\\Pictures\\1.png");}public static void main(String[] args) throws Exception {init();/* 1.上传文件 *//** 1.1.申请文档上传租约 **/StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()// Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set..accessKeyId(params.get("accessKeyId")).accessKeySecret(params.get("accessKeySecret"))//.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token.build());// Configure the ClientAsyncClient client = AsyncClient.builder().region("cn-beijing") // Region ID//.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient).credentialsProvider(provider)//.serviceConfiguration(Configuration.create()) // Service-level configuration// Client-level configuration rewrite, can set Endpoint, Http request parameters, etc..overrideConfiguration(ClientOverrideConfiguration.create()// Endpoint 请参考 https://api.aliyun.com/product/bailian.setEndpointOverride("bailian.cn-beijing.aliyuncs.com")//.setConnectTimeout(Duration.ofSeconds(30))).build();// Parameter settings for API requestApplyFileUploadLeaseRequest applyFileUploadLeaseRequest = ApplyFileUploadLeaseRequest.builder().categoryType("SESSION_FILE").categoryId("default").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 url = new URL(param.getUrl());connection = (HttpURLConnection) url.openConnection();// 设置请求方法用于文档上传,需与您在上一步中调用ApplyFileUploadLease接口实际返回的Data.Param中Method字段的值一致connection.setRequestMethod("PUT");// 允许向connection输出,因为这个连接是用于上传文档的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));// Asynchronous processing of return values/*response.thenAccept(resp -> {System.out.println(new Gson().toJson(resp));}).exceptionally(throwable -> { // Handling exceptionsSystem.out.println(throwable.getMessage());return null;});*/// 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)// 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 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();/* 2.调用百炼应用 */ApplicationParam aiParam = ApplicationParam.builder()// 若没有配置环境变量,可用百炼API Key将下行替换为:.apiKey("sk-xxx")。但不建议在生产环境中直接将API Key硬编码到代码中,以减少API Key泄露风险。.apiKey(params.get("apiKey")).appId(params.get("appId")) // 替换为实际的应用ID.prompt("请直接输出图片问题的答案, 无需多言").ragOptions(RagOptions.builder().sessionFileIds(Arrays.asList(fileId))  // 替换为实际指定的临时文件 ID,逗号隔开多个.build()).build();Application application = new Application();ApplicationResult result = application.call(aiParam);System.out.printf("%s\n",result.getOutput().getText());// 处理只输出文本textSystem.out.println();}private static void init() throws Exception {String filePath = params.get("filePath");File file = new File(filePath);if (!file.exists()) {System.err.println("文件[" + filePath + "]不存在");System.exit(1);}params.put("fileMd5", getMD5Checksum(file));params.put("fileLength", String.valueOf(file.length()));params.put("fileName", file.getName());}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();}
}

2.依赖

        <dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.83</version><scope>compile</scope></dependency><!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java --><dependency><groupId>com.alibaba</groupId><artifactId>dashscope-sdk-java</artifactId><version>2.20.1</version></dependency><dependency><groupId>com.aliyun</groupId><artifactId>alibabacloud-bailian20231229</artifactId><version>2.0.6</version></dependency>

3.百炼应用提示词

# 角色
你是一位知识渊博的专家,能够根据用户的需求提供准确、详细且有帮助的答案。你具备广泛的知识背景,并能灵活运用这些知识来解答各种问题。## 技能
### 技能 1: 知识检索与应用
- 根据用户的问题,从知识库中检索相关信息。### 技能 2: 问题解答
- 理解用户的问题意图和需求。
- 提供详细、准确的答案,解释关键概念和逻辑。## 限制
- 回答问题时必须基于现有的知识库
- 知识库中没有的回复"知识库无相关信息"# 知识库
请记住以下材料,他们可能对回答问题有帮助。
${documents}

4.测试

4.1.创建知识库导入文档

百炼控制台

点击[中国人民解放军海军福建舰_百度百科]保存为pdf导入知识库

4.2.创建应用绑定知识库

4.3.准备问题图片

4.4.测试

http://www.dtcms.com/a/468712.html

相关文章:

  • 五华建设银行网站wordpress添加icp
  • 易网官方网站google移动网站建站十大原则
  • 思明区建设局网站企业电子商务网站有哪些
  • 不用付费不用登录的网站ui培训的课程
  • 仿冒网站制作成都市房产信息网查询
  • 烟台软件优化网站建设免费网站建设大全
  • 好网站求推荐用python做网站多吗
  • 如何注册商标品牌seo技术培训课程
  • 行业网站建设wordpress从入门
  • 郑州网站建设推销巨量引擎app
  • 服装品牌网站建设网络技术与网站建设
  • 广州网站优化排名横岗做网站公司
  • 网站开发看掉一些功能彩票网站模版
  • 网站建设效果好不好做网站公司(信科网络)
  • 百度做网站好吗廊坊建站
  • 海淘网站是谁做的兰州市城市建设设计院官网
  • 德州做网站哪家好wordpress 采集发布
  • 无锡网站制作哪家不错dw个人网站模板下载
  • 吉林大学学风建设专题网站亚马逊入驻费用及条件
  • wordpress 外贸站主题太原网站建设 网站制作
  • 网站维护推广soapclient WordPress
  • 网站设计主要内容怎样做一家网站
  • 找网站有中文字目的广州做一个营销网站多少钱
  • 如何寻找网站建设需求客户wordpress侧边栏显示单个分类列表
  • 毕业室内设计代做网站做网站素材网
  • 阜新网站优化2344网页游戏大全
  • 怎么给网站加图标网站开发是什么
  • 武强网站建设中国有哪些网站可以做兼职
  • 网站做等级保护建设银行网站的目的是什么
  • 贵州建设水利厅考试网站怎么把自己的产品推广出去