大模型修改成配置文件可配
This commit is contained in:
parent
b370b13fe0
commit
435c7d8187
@ -59,6 +59,7 @@ public class AliYunQianWen {
|
||||
public Mono<Boolean> sendMessage(String msg,
|
||||
IQianWen<? super String> onNext,
|
||||
QWenReplyResponse qwenReplyResponse) {
|
||||
log.info("调用通义星尘回答:{}", msg);
|
||||
if(!canAsk){
|
||||
msgManager = new MessageManager(10);
|
||||
}
|
||||
|
||||
@ -73,15 +73,18 @@ public class AliYunXingChen {
|
||||
).build();
|
||||
}
|
||||
public Mono<Boolean> sendMessage(String msg,
|
||||
IQianWen<? super String> onNext){
|
||||
IQianWen<? super String> onNext,
|
||||
QWenReplyResponse qwenReplyResponse){
|
||||
log.info("调用通义星尘回答:{}", msg);
|
||||
Message message = Message.builder().name(userName).role("user").content(msg).build();
|
||||
addMessage(message);
|
||||
chatReqParams.setMessages(messages);
|
||||
qwenReplyResponse.setCode(200);
|
||||
return Mono.defer(() -> {
|
||||
try {
|
||||
Flowable<ChatResult> response = api.streamOut(chatReqParams);
|
||||
RecordMessage recordMessage = new RecordMessage();
|
||||
response.forEach(m -> {
|
||||
response.blockingForEach(m -> {
|
||||
String v = m.getChoices().get(0).getMessages().get(0).getContent().replaceAll(recordMessage.getMsg(), "");
|
||||
onNext.sendMessage(v);
|
||||
if("stop".equals(m.getChoices().get(0).getStopReason())){
|
||||
@ -97,6 +100,7 @@ public class AliYunXingChen {
|
||||
});
|
||||
}catch (Exception e){
|
||||
log.info("调用星尘异常{}", e);
|
||||
qwenReplyResponse.setCode(500);
|
||||
}
|
||||
return Mono.just(true);
|
||||
});
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
package com.qiuguo.iot.third.service;
|
||||
|
||||
import com.qiuguo.iot.data.request.qwen.TongYiCommunicationRest;
|
||||
import com.qiuguo.iot.data.resp.qg.algorithm.QWenReplyResponse;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface ITongYi {
|
||||
Mono<QWenReplyResponse> communication(TongYiCommunicationRest rest, IQianWen<? super String> onNext);
|
||||
}
|
||||
@ -28,7 +28,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class QWenService {
|
||||
public class QWenService implements ITongYi{
|
||||
|
||||
@Resource
|
||||
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
|
||||
@ -37,6 +37,7 @@ public class QWenService {
|
||||
protected static ConcurrentHashMap<String, AliYunQianWen> qianwenGroup = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<QWenReplyResponse> communication(TongYiCommunicationRest rest, IQianWen<? super String> onNext){
|
||||
AliYunQianWen aliQianWen = null;
|
||||
if (!qianwenGroup.containsKey(rest.getOnlyId())) {
|
||||
|
||||
@ -30,13 +30,13 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class TongYiXinChenService {
|
||||
public class TongYiXinChenService implements ITongYi{
|
||||
|
||||
|
||||
|
||||
protected static ConcurrentHashMap<String, AliYunXingChen> qianwenGroup = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public Mono<QWenReplyResponse> communication(TongYiCommunicationRest rest, IQianWen<? super String> onNext){
|
||||
AliYunXingChen aliXingChen = null;
|
||||
if (!qianwenGroup.containsKey(rest.getOnlyId())) {
|
||||
@ -48,7 +48,8 @@ public class TongYiXinChenService {
|
||||
aliXingChen = qianwenGroup.get(rest.getOnlyId());
|
||||
}
|
||||
QWenReplyResponse qWenReplyResponse = new QWenReplyResponse();
|
||||
return aliXingChen.sendMessage(rest.getText(), onNext).flatMap(b -> {
|
||||
|
||||
return aliXingChen.sendMessage(rest.getText(), onNext, qWenReplyResponse).flatMap(b -> {
|
||||
return Mono.just(qWenReplyResponse);
|
||||
});
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.qiuguo.iot.base.constans.Log4Constans;
|
||||
import com.qiuguo.iot.base.enums.*;
|
||||
import com.qiuguo.iot.base.utils.StringUtils;
|
||||
import com.qiuguo.iot.box.websocket.api.config.properties.SomeProperties;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.BaseSession;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.QueueMessage;
|
||||
import com.qiuguo.iot.box.websocket.api.domain.box.BoxSession;
|
||||
@ -17,6 +18,7 @@ import com.qiuguo.iot.third.nlp.action.Actions;
|
||||
import com.qiuguo.iot.third.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
@ -26,8 +28,10 @@ import javax.annotation.Resource;
|
||||
public abstract class ActionCommand {
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
protected QWenService qwenService;
|
||||
SomeProperties someProperties;
|
||||
|
||||
|
||||
@Resource
|
||||
protected MqService mqService;
|
||||
@ -118,25 +122,13 @@ public abstract class ActionCommand {
|
||||
|
||||
}
|
||||
|
||||
protected Mono<Void> toQianWen(Action action, BaseSession baseSession, Integer type){
|
||||
log.info("调用千问{}", action.getAsk());
|
||||
TongYiCommunicationRest tongYiCommunicationRest = new TongYiCommunicationRest();
|
||||
tongYiCommunicationRest.setText(action.getAsk());
|
||||
tongYiCommunicationRest.setStatus("2");
|
||||
tongYiCommunicationRest.setRequestId(baseSession.getRequestId());
|
||||
//调用星尘
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString());
|
||||
//下面是调用千问
|
||||
/*if(baseSession instanceof BoxSession){
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getSn());
|
||||
}else{
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString());
|
||||
}*/
|
||||
private IQianWen<String> getIQianWen(Action action,
|
||||
BaseSession baseSession,
|
||||
TongYiCommunicationRest tongYiCommunicationRest,
|
||||
Integer type,
|
||||
QueueMessage queueMessage) {
|
||||
|
||||
|
||||
QueueMessage queueMessage = new QueueMessage();
|
||||
queueMessage.setRequestId(baseSession.getRequestId());
|
||||
return qwenService.communication(tongYiCommunicationRest, new IQianWen<String>() {
|
||||
return new IQianWen<String>() {
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
//通知到客户端
|
||||
@ -158,7 +150,37 @@ public abstract class ActionCommand {
|
||||
queueMessage.setStatus(YesNo.NO.getCode());
|
||||
MDC.remove(Log4Constans.PRINT_LOG_ID);
|
||||
}
|
||||
}).flatMap(data ->{
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
protected Mono<Void> toTongYi(Action action, BaseSession baseSession, Integer type){
|
||||
log.info("调用千问{}", action.getAsk());
|
||||
TongYiCommunicationRest tongYiCommunicationRest = new TongYiCommunicationRest();
|
||||
tongYiCommunicationRest.setText(action.getAsk());
|
||||
tongYiCommunicationRest.setStatus("2");
|
||||
tongYiCommunicationRest.setRequestId(baseSession.getRequestId());
|
||||
|
||||
|
||||
ITongYi iTongYi = SpringUtil.getBean(someProperties.getTongYi());
|
||||
if(iTongYi instanceof TongYiXinChenService){
|
||||
//调用星尘
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString());
|
||||
tongYiCommunicationRest.setRoleId(baseSession.getRoleId());
|
||||
}else{
|
||||
if(baseSession instanceof BoxSession){
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getSn());
|
||||
}else{
|
||||
tongYiCommunicationRest.setOnlyId(baseSession.getUserId().toString());
|
||||
}
|
||||
}
|
||||
QueueMessage queueMessage = new QueueMessage();
|
||||
queueMessage.setRequestId(baseSession.getRequestId());
|
||||
return iTongYi.communication(tongYiCommunicationRest, getIQianWen(action,
|
||||
baseSession,
|
||||
tongYiCommunicationRest,
|
||||
type,
|
||||
queueMessage)).flatMap(data ->{
|
||||
queueMessage.setStatus(YesNo.NO.getCode());
|
||||
if(data.getCode() == 200){
|
||||
log.info("千问正常结束");
|
||||
@ -171,7 +193,7 @@ public abstract class ActionCommand {
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
})/*.subscribeOn(Schedulers.boundedElastic()).subscribe()*/;
|
||||
});
|
||||
}
|
||||
|
||||
protected Mono<Boolean> sendMq(String msg){
|
||||
|
||||
@ -12,7 +12,7 @@ public class QianWenActionCommand extends ActionCommand implements IActionComma
|
||||
public Mono<Boolean> process(Action action, BaseSession baseSession) {
|
||||
log.info("千问 Action:{}", action.getAsk());
|
||||
|
||||
return toQianWen(action,
|
||||
return toTongYi(action,
|
||||
baseSession,
|
||||
action.getSystemTalkAnswerConfigEntity() == null ? AskTypeEnum.TTS.getCode() : action.getSystemTalkAnswerConfigEntity().getAnswerType()).flatMap(vo ->{
|
||||
//千问只调一次
|
||||
|
||||
@ -13,7 +13,7 @@ public class TtsActionCommand extends ActionCommand implements IActionCommand{
|
||||
log.info("纯文本Tts Action:{}", action.getAsk());
|
||||
|
||||
if(!action.getAction().equals(action.getAsk())){
|
||||
return toQianWen(
|
||||
return toTongYi(
|
||||
action,
|
||||
baseSession,
|
||||
AskTypeEnum.TTS.getCode()
|
||||
|
||||
@ -26,6 +26,9 @@ public class SomeProperties {
|
||||
private Boolean checkTimeout;
|
||||
@Value("${device.timeout}")
|
||||
private Long timeOut;//2分钟
|
||||
|
||||
@Value("${Ali.tongyi}")
|
||||
protected String tongYi;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -57,4 +57,9 @@ public class BaseSession {
|
||||
* TTS合成声音的声音标识
|
||||
*/
|
||||
String ttsId;
|
||||
|
||||
/**
|
||||
* 形成角色id
|
||||
*/
|
||||
String roleId;
|
||||
}
|
||||
|
||||
@ -270,6 +270,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
entity.setOtherDeviceId(dv.getSn());
|
||||
entity.setCategoryCode(DeviceCodeEnum.BOX.getName());
|
||||
entity.setBindName("果宝儿Box");
|
||||
boxSession.setRoleId(entity.getCategoryCode());
|
||||
return deviceUserBindService.setNoMain(userId, DeviceTypeEnum.GUO_BOX.getCode()).defaultIfEmpty(0).flatMap(m ->{
|
||||
log.info("解除历史isMain标注个数{}", m);
|
||||
return deviceUserBindService.insertDeviceUserBind(entity).flatMap(l ->{
|
||||
@ -279,6 +280,7 @@ public class BoxWebSocketHandler implements WebSocketHandler {
|
||||
|
||||
}else{
|
||||
boxSession.setTtsId(entity.getTts());
|
||||
boxSession.setRoleId(entity.getCategoryCode());
|
||||
if(entity.getIsBind().equals(YesNo.YES.getCode())){
|
||||
//通知用户端设备绑定成功
|
||||
sendNoticeToUser(userId, "设备联网成功,设备序列号:" + dv.getSn(), AskTypeEnum.BOX_ON_LINE.getCode());
|
||||
|
||||
@ -164,7 +164,7 @@ public class CustomerWebSocketHandler implements WebSocketHandler {
|
||||
.flatMap(deviceUserBindEntity -> {
|
||||
if(deviceUserBindEntity.getId() != null){
|
||||
log.info("用户绑定信息为{}", deviceUserBindEntity);
|
||||
|
||||
userSession.setRoleId(deviceUserBindEntity.getCategoryCode());
|
||||
userSession.setDeviceId(deviceUserBindEntity.getDeviceId());
|
||||
userSession.setSn(deviceUserBindEntity.getOtherDeviceId());
|
||||
|
||||
|
||||
@ -59,6 +59,7 @@ Ali:
|
||||
qianwen: 'sk-8d64677afaf6404cb83ce1910b5b2558'
|
||||
accesskeId: 'LTAI5t7d1iZb18SvGQhtDnyN'
|
||||
accesskeySecret: 'j2Cp3uCDGuiA7xZIJmYOCmDhJl9HuJ'
|
||||
tongyi: 'tongYiXinChenService'
|
||||
xingchen:
|
||||
key: 'lm-dIINta/ISx0/8aZK5xKt/A=='
|
||||
basepath: https://nlp.aliyuncs.com
|
||||
Loading…
x
Reference in New Issue
Block a user