@ -1,19 +1,17 @@
package com.supervision.rasa.service ;
package com.supervision.rasa.service ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.TimeInterval ;
import cn.hutool.core.io.FileUtil ;
import cn.hutool.core.io.FileUtil ;
import cn.hutool.core.lang.Assert ;
import cn.hutool.core.lang.Assert ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.http.HttpUtil ;
import cn.hutool.http.HttpUtil ;
import cn.hutool.json.JSON ;
import cn.hutool.json.JSONArray ;
import cn.hutool.json.JSONObject ;
import cn.hutool.json.JSONObject ;
import cn.hutool.json.JSONUtil ;
import cn.hutool.json.JSONUtil ;
import com.supervision.rasa.pojo.dto.QuestionAnswerDTO ;
import com.supervision.rasa.pojo.dto.QuestionAnswerDTO ;
import com.supervision.rasa.pojo.dto.Text2vecDataVo ;
import com.supervision.rasa.pojo.dto.Text2vecDataVo ;
import com.supervision.rasa.pojo.dto.Text2vecMatchesReq ;
import com.supervision.rasa.pojo.dto.Text2vecMatchesReq ;
import com.supervision.rasa.pojo.dto.Text2vecMatchesRes ;
import com.supervision.rasa.pojo.dto.Text2vecMatchesRes ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.log4j.Log4j ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
@ -53,9 +51,10 @@ public class Text2vecServiceImpl implements Text2vecService {
String url = TEXT2VEC_SERVICE_DOMAIN + UPDATE_DATASET_PATH ;
String url = TEXT2VEC_SERVICE_DOMAIN + UPDATE_DATASET_PATH ;
log . info ( "updateDataset: url is : {}" , url ) ;
log . info ( "updateDataset: url is : {}" , url ) ;
TimeInterval timer = DateUtil . timer ( ) ;
String body = HttpUtil . post ( url , JSONUtil . toJsonStr ( text2vecDataVoList ) ) ;
String body = HttpUtil . post ( url , JSONUtil . toJsonStr ( text2vecDataVoList ) ) ;
log . info ( "updateDataset: res is :{} ", body ) ;
log . info ( "updateDataset: res is :{} ,耗时:{}s ", body , timer . intervalSecond ( ) ) ;
return "success" . equals ( JSONUtil . parseObj ( body ) . get ( "status" ) ) ;
return "success" . equals ( JSONUtil . parseObj ( body ) . get ( "status" ) ) ;
}
}
@ -87,8 +86,13 @@ public class Text2vecServiceImpl implements Text2vecService {
Map < String , QuestionAnswerDTO > intentCodeAndIdMap = rasaCmdService . getIntentCodeAndIdMap ( ) ;
Map < String , QuestionAnswerDTO > intentCodeAndIdMap = rasaCmdService . getIntentCodeAndIdMap ( ) ;
// 更新text2vec数据信息
// 更新text2vec数据信息
List < Text2vecDataVo > text2vecDataVoList = intentCodeAndIdMap . entrySet ( ) . stream ( )
List < Text2vecDataVo > text2vecDataVoList = intentCodeAndIdMap . entrySet ( ) . stream ( )
. filter ( entry - > Objects . nonNull ( entry . getValue ( ) ) & & CollUtil . isNotEmpty ( entry . getValue ( ) . getQuestionList ( ) ) )
. flatMap ( entry - > entry . getValue ( ) . getQuestionList ( ) . stream ( )
. flatMap ( entry - > entry . getValue ( ) . getQuestionList ( ) . stream ( )
. map ( question - > new Text2vecDataVo ( entry . getKey ( ) , question ) ) ) . collect ( Collectors . toList ( ) ) ;
. map ( question - > new Text2vecDataVo ( entry . getKey ( ) , question ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollUtil . isEmpty ( text2vecDataVoList ) ) {
log . info ( "text2vec数据初始化失败, text2vec数据为空...." ) ;
return ;
}
this . updateDataset ( text2vecDataVoList ) ;
this . updateDataset ( text2vecDataVoList ) ;
}
}