知识库上传文件

This commit is contained in:
ire 2025-02-13 14:40:04 +08:00
parent 53e7f47065
commit aff9e403a6
2 changed files with 33 additions and 9 deletions

View File

@ -88,7 +88,7 @@ public class ConversationController {
@PreAuthorize("@ss.hasPermission('llm:conversation:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportConversationExcel(@Valid ConversationPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ConversationDO> list = conversationService.getConversationPage(pageReqVO).getList();
// 导出 Excel
@ -106,4 +106,4 @@ public class ConversationController {
public CommonResult<JSONArray> textToImage(@Valid @RequestBody TextToImageReqVo req) {
return success(conversationService.textToImage(req));
}
}
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.llm.service.http;
import cn.hutool.http.HttpRequest;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -131,17 +132,40 @@ public class RagHttpService {
// 配置 Unirest
/* Unirest.config().reset();
Unirest.config().socketTimeout(86400000);*/
// 发送上传请求
HttpResponse<String> uploadResponse = Unirest.post(ragUploadReqVO.getUrl())
.field("file_id", ragUploadReqVO.getFileId())
.field("file", new ByteArrayInputStream(utf8Bytes), ragUploadReqVO.getFileName())
.asString();
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(utf8Bytes);
int bufferSize = 1024; // 定义缓冲区大小为1024字节
byte[] byteArray = new byte[bufferSize]; // 创建字节数组
int bytesRead; // 记录实际读取的字节数
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); // 输出流用于存储字节
while ((bytesRead = byteArrayInputStream.read(byteArray)) != -1) {
// 如果没有读取到数据bytesRead会返回-1
outputStream.write(byteArray, 0, bytesRead); // 将读取的字节写入输出流
}
// 将ByteArrayOutputStream转换为byte数组
byte[] result = outputStream.toByteArray();
inputStream.close(); // 关闭InputStream
outputStream.close(); // 关闭ByteArrayOutputStream
String body = HttpRequest.post(ragUploadReqVO.getUrl())
.form("file", result, ragUploadReqVO.getFileName())
.form("file_id", ragUploadReqVO.getFileId())
.execute().body();
// // 发送上传请求
// HttpResponse<String> uploadResponse = Unirest.post(ragUploadReqVO.getUrl())
// .field("file_id", ragUploadReqVO.getFileId())
// .field("file", new ByteArrayInputStream(utf8Bytes), ragUploadReqVO.getFileName())
// .asString();
// 检查响应状态
log.info("Response Body: {}", uploadResponse.getBody());
ragEmbedRespVO = JSON.parseObject(uploadResponse.getBody(), RagEmbedRespVO.class);
// log.info("Response Body: {}", uploadResponse.getBody());
ragEmbedRespVO = JSON.parseObject(body, RagEmbedRespVO.class);
log.info("ragEmbedRespVO:{}", ragEmbedRespVO);
if (ragEmbedRespVO.isStatus()) {