对闹钟一些关键字,增加没有时间调用千问
This commit is contained in:
parent
106ddb6e50
commit
74fe812935
@ -60,7 +60,12 @@ public class AlarmClockActionCommand extends ActionCommand implements IActionCom
|
|||||||
return Mono.just(false);
|
return Mono.just(false);
|
||||||
}
|
}
|
||||||
ActionTime actionTime = action.getTime();
|
ActionTime actionTime = action.getTime();
|
||||||
|
if(actionTime == null){
|
||||||
|
log.info("闹钟关键字没有时间,调用千问");
|
||||||
|
return toTongYi(action, baseSession, AskTypeEnum.TTS.getCode(), actionSendMessage).flatMap(b -> {
|
||||||
|
return Mono.empty();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
DeviceAlarmClockRecordRequest request;
|
DeviceAlarmClockRecordRequest request;
|
||||||
Integer day = null;
|
Integer day = null;
|
||||||
|
|||||||
@ -35,6 +35,10 @@ public class AliYunXingChen {
|
|||||||
*/
|
*/
|
||||||
ChatApiSub api;
|
ChatApiSub api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳,超过一定时间且未更新的。那么将被清理
|
||||||
|
*/
|
||||||
|
Long timestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|
||||||
List<Message> messages = new ArrayList<>(50);
|
List<Message> messages = new ArrayList<>(50);
|
||||||
@ -89,6 +93,7 @@ public class AliYunXingChen {
|
|||||||
|
|
||||||
private Mono<Boolean> sendMsg(IQianWen<? super String> onNext,
|
private Mono<Boolean> sendMsg(IQianWen<? super String> onNext,
|
||||||
QWenReplyResponse qwenReplyResponse){
|
QWenReplyResponse qwenReplyResponse){
|
||||||
|
timestamp = System.currentTimeMillis();//更新最后使用时间
|
||||||
chatReqParams.setMessages(messages);
|
chatReqParams.setMessages(messages);
|
||||||
qwenReplyResponse.setCode(200);
|
qwenReplyResponse.setCode(200);
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -18,13 +18,11 @@ import org.springframework.data.redis.core.ReactiveValueOperations;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
import reactor.core.scheduler.Schedulers;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -37,6 +35,15 @@ public class TongYiXinChenService implements ITongYi{
|
|||||||
|
|
||||||
protected static ConcurrentHashMap<String, AliYunXingChen> qianwenGroup = new ConcurrentHashMap<>();
|
protected static ConcurrentHashMap<String, AliYunXingChen> qianwenGroup = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 超过该时间还未发送消息的将被剔除
|
||||||
|
*/
|
||||||
|
static Long TIME_OUT = 60000L;
|
||||||
|
|
||||||
|
public TongYiXinChenService(){
|
||||||
|
//checkOutTime().subscribeOn(Schedulers.newSingle("tongyi-xinchen-clean")).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<QWenReplyResponse> communication(TongYiCommunicationRest rest, IQianWen<? super String> onNext){
|
public Mono<QWenReplyResponse> communication(TongYiCommunicationRest rest, IQianWen<? super String> onNext){
|
||||||
AliYunXingChen aliXingChen = null;
|
AliYunXingChen aliXingChen = null;
|
||||||
@ -53,7 +60,31 @@ public class TongYiXinChenService implements ITongYi{
|
|||||||
return aliXingChen.sendMessage(rest.getText(), onNext, qWenReplyResponse/*, reactiveStringRedisTemplate*/).flatMap(b -> {
|
return aliXingChen.sendMessage(rest.getText(), onNext, qWenReplyResponse/*, reactiveStringRedisTemplate*/).flatMap(b -> {
|
||||||
return Mono.just(qWenReplyResponse);
|
return Mono.just(qWenReplyResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Mono<Void> checkOutTime(){
|
||||||
|
log.info("开启清理内存数据任务");
|
||||||
|
List<String> keys = new ArrayList<>();
|
||||||
|
while(true){
|
||||||
|
for (String key: qianwenGroup.keySet()
|
||||||
|
) {
|
||||||
|
AliYunXingChen aliYunXingChen = qianwenGroup.get(key);
|
||||||
|
Long now = System.currentTimeMillis();
|
||||||
|
if(now - aliYunXingChen.getTimestamp() > TIME_OUT){
|
||||||
|
keys.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("需要清除内存中:{}数据", keys.size());
|
||||||
|
for(String key: keys){
|
||||||
|
qianwenGroup.remove(key);
|
||||||
|
}
|
||||||
|
keys.clear();
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}catch (Exception e){
|
||||||
|
log.info("定时清理内存中数据异常{}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user