|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.supervision.qanything.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.lang.TypeReference;
|
|
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
|
@ -14,7 +15,10 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
@ -119,6 +123,29 @@ public class QanythingServiceImpl implements QanythingService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void chatStream(HttpServletResponse response, String question, List<String> kbIds) throws NoSuchAlgorithmException, IOException {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(kbIds, "kbIds不能为空");
|
|
|
|
|
Assert.notEmpty(question, "问题不能为空");
|
|
|
|
|
|
|
|
|
|
log.info("chat:请求入参:question:{},kbIds:{}", question, kbIds);
|
|
|
|
|
ChatParam chatParam = new ChatParam();
|
|
|
|
|
chatParam.setQ(question);
|
|
|
|
|
chatParam.setKbIds(kbIds);
|
|
|
|
|
// 添加鉴权相关参数
|
|
|
|
|
AuthV3Util.addAuthParams(APP_KEY, APP_SECRET, chatParam);
|
|
|
|
|
String paramString = JSONUtil.toJsonStr(chatParam);
|
|
|
|
|
log.info("chat:请求参数:{}", paramString);
|
|
|
|
|
|
|
|
|
|
HttpRequest request = HttpRequest.post(BASE_URL + QanythingConstant.URL_CHAT_STREAM)
|
|
|
|
|
.body(paramString);
|
|
|
|
|
try (HttpResponse qResponse = request.execute()){
|
|
|
|
|
InputStream inputStream = qResponse.bodyStream();
|
|
|
|
|
IoUtil.copy(inputStream,response.getOutputStream());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ResultWrapper<List<UploadResult>> uploadDoc(String kbId, File file) throws NoSuchAlgorithmException {
|
|
|
|
|
Assert.notNull(file, "文件不能为空");
|
|
|
|
|