|
|
|
@ -35,6 +35,7 @@ import reactor.core.publisher.Flux;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
@ -59,7 +60,6 @@ public class ChatServiceImpl implements IChatService {
|
|
|
|
|
difyChatReqVO.setUser("admin");
|
|
|
|
|
DIFYChatReqInputVO inputs = new DIFYChatReqInputVO();
|
|
|
|
|
difyChatReqVO.setQuery(query);
|
|
|
|
|
// difyChatReqVO.setQuery("尽可能详细的介绍一下勐赫小镇的医疗服务");
|
|
|
|
|
difyChatReqVO.setInputs(inputs);
|
|
|
|
|
StringBuilder sentence = new StringBuilder();
|
|
|
|
|
log.info("query:{}", query);
|
|
|
|
@ -72,7 +72,7 @@ public class ChatServiceImpl implements IChatService {
|
|
|
|
|
.bodyValue(JSON.toJSONString(difyChatReqVO))
|
|
|
|
|
.retrieve()
|
|
|
|
|
.bodyToFlux(StreamResponse.class)
|
|
|
|
|
.map(response -> {
|
|
|
|
|
.mapNotNull(response -> {
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
|
|
map.put("event", response.getEvent());
|
|
|
|
|
if (response.getEvent().equals("message") && response.getAnswer() != null) {
|
|
|
|
@ -85,21 +85,23 @@ public class ChatServiceImpl implements IChatService {
|
|
|
|
|
String voiceBaseId = UUID.randomUUID().toString();
|
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
|
sentence.setLength(0); // Clear the sentence
|
|
|
|
|
sentence.setLength(0);
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (response.getEvent().equals("message_end") && !sentence.isEmpty()) {
|
|
|
|
|
}
|
|
|
|
|
if (response.getEvent().equals("message_end")) {
|
|
|
|
|
if (!sentence.isEmpty()) {
|
|
|
|
|
log.info(sentence.toString());
|
|
|
|
|
TtsResultDTO ttsResultDTO = TtsUtil.ttsTransform(sentence.toString());
|
|
|
|
|
String voiceBaseId = UUID.randomUUID().toString();
|
|
|
|
|
voiceCache.put(voiceBaseId, ttsResultDTO.getAudio());
|
|
|
|
|
map.put("audioId", voiceBaseId);
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
|
}
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
|
}
|
|
|
|
|
return ServerSentEvent.builder(map).build();
|
|
|
|
|
});
|
|
|
|
|
return null;
|
|
|
|
|
}).filter(Objects::nonNull);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|