新增AI相关接口
This commit is contained in:
parent
2735a5296a
commit
0c84a91bc8
|
|
@ -62,6 +62,14 @@ public class ElePropertyConfig {
|
|||
@Value("${backup.mysql.path}")
|
||||
private String sqlDirs;
|
||||
|
||||
@Getter
|
||||
@Value("${ai.remote.host}")
|
||||
private String aiRemoteHost;
|
||||
|
||||
@Getter
|
||||
@Value("${ai.remote.port}")
|
||||
private String aiRemotePort;
|
||||
|
||||
public String getEleTmpPath() {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
return winPrefix + eleTmpPath;
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
|
||||
if (request.getRequestURI().endsWith("index")) {
|
||||
if (request.getRequestURI().endsWith("index") || request.getRequestURI().contains("/data/ed/ai/")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.electromagnetic.industry.software.manage.controller;
|
||||
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.ChatQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.AiChatService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/data/ed/ai/")
|
||||
public class AiChatController {
|
||||
|
||||
@Resource
|
||||
private AiChatService aiChatService;
|
||||
|
||||
@RequestMapping(value = "chat")
|
||||
public ElectromagneticResult<?> chat(@RequestBody ChatQueryDTO chatQueryDTO) {
|
||||
return aiChatService.chat(chatQueryDTO.getQuestion());
|
||||
}
|
||||
|
||||
@RequestMapping(value = "addKnowledge")
|
||||
public ElectromagneticResult<?> addKnowledge(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
return aiChatService.addKnowledge(file);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ChatQueryDTO {
|
||||
private String question;
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.config.ElePropertyConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class AiChatService {
|
||||
|
||||
@Resource
|
||||
private ElePropertyConfig elePropertyConfig;
|
||||
|
||||
public ElectromagneticResult<?> chat(String message) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("msg", message);
|
||||
String url = StrFormatter.format("http://{}:{}/data/ed/ai/chat", elePropertyConfig.getAiRemoteHost(), elePropertyConfig.getAiRemotePort());
|
||||
String res = HttpUtil.post(url, JSONUtil.toJsonStr(map), 5 * 60 * 1000);
|
||||
log.info("answer is {}", res);
|
||||
ElectromagneticResult<?> result = JSONUtil.toBean(res, ElectromagneticResult.class);
|
||||
log.info("result ----------------------------->{}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ElectromagneticResult<?> addKnowledge(MultipartFile file) throws IOException {
|
||||
String content = IoUtil.read(file.getInputStream(), Charset.defaultCharset());
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("content", content);
|
||||
String url = StrFormatter.format("http://{}:{}/data/ed/ai/upload", elePropertyConfig.getAiRemoteHost(), elePropertyConfig.getAiRemotePort());
|
||||
String res = HttpUtil.post(url, JSONUtil.toJsonStr(map));
|
||||
return JSONUtil.toBean(res, ElectromagneticResult.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -37,3 +37,7 @@ backup.remote.host=127.0.0.1
|
|||
backup.remote.port=1111
|
||||
backup.mysql.path=/workspace/mysqlbak/test
|
||||
backup.mysql.script.path=/workspace/mysqlbak/back_dev.sh
|
||||
|
||||
# ai options
|
||||
ai.remote.host=127.0.0.1
|
||||
ai.remote.port=8186
|
||||
Loading…
Reference in New Issue