|
|
@ -29,18 +29,23 @@ public class QanythingServiceImpl implements QanythingService {
|
|
|
|
private String APP_SECRET;
|
|
|
|
private String APP_SECRET;
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${youdao.qanthing.baseUrl}")
|
|
|
|
@Value("${youdao.qanthing.baseUrl}")
|
|
|
|
private String BASE_URL = "https://openapi.youdao.com";
|
|
|
|
private String BASE_URL;
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ResultWrapper<ChatResult> chat(String question, List<String> kbIds) throws NoSuchAlgorithmException {
|
|
|
|
public ResultWrapper<ChatResult> chat(String question, List<String> kbIds) throws NoSuchAlgorithmException {
|
|
|
|
|
|
|
|
log.info("chat:请求入参:question:{},kbIds:{}", question, kbIds);
|
|
|
|
ChatParam chatParam = new ChatParam();
|
|
|
|
ChatParam chatParam = new ChatParam();
|
|
|
|
chatParam.setQ(question);
|
|
|
|
chatParam.setQ(question);
|
|
|
|
chatParam.setKbIds(kbIds);
|
|
|
|
chatParam.setKbIds(kbIds);
|
|
|
|
// 添加鉴权相关参数
|
|
|
|
// 添加鉴权相关参数
|
|
|
|
AuthV3Util.addAuthParams(APP_KEY, APP_SECRET, chatParam);
|
|
|
|
AuthV3Util.addAuthParams(APP_KEY, APP_SECRET, chatParam);
|
|
|
|
|
|
|
|
String paramString = JSONUtil.toJsonStr(chatParam);
|
|
|
|
|
|
|
|
log.info("chat:请求参数:{}", paramString);
|
|
|
|
HttpRequest request = HttpRequest.post(BASE_URL + "/q_anything/paas/chat")
|
|
|
|
HttpRequest request = HttpRequest.post(BASE_URL + "/q_anything/paas/chat")
|
|
|
|
.body(JSONUtil.toJsonStr(chatParam));
|
|
|
|
.body(paramString);
|
|
|
|
try (HttpResponse response = request.execute()){
|
|
|
|
try (HttpResponse response = request.execute()){
|
|
|
|
return JSONUtil.toBean(response.body(), new TypeReference<ResultWrapper<ChatResult>>(){},true);
|
|
|
|
String body = response.body();
|
|
|
|
|
|
|
|
log.info("chat:响应结果:{}", body);
|
|
|
|
|
|
|
|
return JSONUtil.toBean(body, new TypeReference<ResultWrapper<ChatResult>>(){},true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|