api
parent
e56db6285e
commit
5201605876
@ -1,18 +1,21 @@
|
||||
package com.supervision.contoller;
|
||||
|
||||
import com.supervision.service.IChatService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/chat")
|
||||
@RequiredArgsConstructor
|
||||
public class ChatController {
|
||||
|
||||
private final IChatService chatService;
|
||||
|
||||
@PostMapping("/queryStatisticsData")
|
||||
public String queryStatisticsData() {
|
||||
return "success";
|
||||
@PostMapping("/talk")
|
||||
public String talk(@RequestParam("file") MultipartFile multipartFile) {
|
||||
return chatService.talk(multipartFile);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,8 @@
|
||||
package com.supervision.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
public interface IChatService {
|
||||
String talk(MultipartFile file);
|
||||
}
|
||||
|
@ -1,6 +1,48 @@
|
||||
package com.supervision.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.supervision.dto.paddlespeech.res.TtsResultDTO;
|
||||
import com.supervision.model.dify.DIFYChatReqInputVO;
|
||||
import com.supervision.model.dify.DifyChatReqVO;
|
||||
import com.supervision.model.dify.DifyChatResVO;
|
||||
import com.supervision.service.IChatService;
|
||||
import com.supervision.util.AsrUtil;
|
||||
import com.supervision.util.DifyApiUtil;
|
||||
import com.supervision.util.TtsUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ChatServiceImpl implements IChatService {
|
||||
|
||||
@Resource
|
||||
private DifyApiUtil difyApiUtil;
|
||||
|
||||
@Override
|
||||
public String talk(MultipartFile file) {
|
||||
String talkResult = "";
|
||||
try {
|
||||
DifyChatReqVO difyChatReqVO = new DifyChatReqVO();
|
||||
difyChatReqVO.setUser("admin");
|
||||
DIFYChatReqInputVO inputs = new DIFYChatReqInputVO();
|
||||
inputs.setQuery(AsrUtil.asrTransformByBytes(file.getBytes()));
|
||||
difyChatReqVO.setInputs(inputs);
|
||||
String response = difyApiUtil.chat(difyChatReqVO);
|
||||
log.info("response:{}", response);
|
||||
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(response);
|
||||
talkResult = JSON.toJSONString(ttsResultDTO);
|
||||
log.info("ttsResultDTO:{}", JSON.toJSONString(ttsResultDTO));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return talkResult;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue