rasa:优化代码

dev_v1.0.1
xueqingkun 2 years ago
parent 3e6344f93b
commit b49979ac1f

@ -57,16 +57,4 @@ public class RasaCmdController {
} }
private final RasaModelManager rasaModelManager;
@ApiOperation("执行启动shell命令")
@PostMapping("/test")
public String test(@RequestBody RasaCmdArgumentVo argument) throws ExecutionException, InterruptedException, TimeoutException {
rasaModelManager.wakeUpInterruptServer();
return " dd";
}
} }

@ -16,6 +16,5 @@ public interface RasaCmdService {
List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException; List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException;
void test();
} }

@ -50,7 +50,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
@Value("${rasa.run-shell}") @Value("${rasa.run-shell}")
private String runShell; private String runShell;
@Value("${rasa.shell.work:/home/rasa_manage/}") @Value("${rasa.shell.work:/data/vp/rasa_shell/}")
private String shellWork; private String shellWork;
private final RasaModeService rasaModeService; private final RasaModeService rasaModeService;
@ -61,11 +61,12 @@ public class RasaCmdServiceImpl implements RasaCmdService {
public String trainExec(RasaCmdArgumentVo argument) throws ExecutionException, InterruptedException, TimeoutException { public String trainExec(RasaCmdArgumentVo argument) throws ExecutionException, InterruptedException, TimeoutException {
// /rasa/v3_jiazhuangxian/domain.yml domain的路径应该是从zip文件中加压出来的文件的路径后面拼上/domain.yml // /rasa/v3_jiazhuangxian/domain.yml domain的路径应该是从zip文件中加压出来的文件的路径后面拼上/domain.yml
String domain = String.join(File.separator,dataPath,argument.getModelId(),"domain.yml");
String domain = replaceDuplicateSeparator(String.join(File.separator,dataPath,argument.getModelId(),"domain.yml"));
// /rasa/v3_jiazhuangxian/ yml文件的路径应该是从zip文件中加压出来的文件的路径,在配置文件中配置 // /rasa/v3_jiazhuangxian/ yml文件的路径应该是从zip文件中加压出来的文件的路径,在配置文件中配置
String localDataPath = String.join(File.separator,dataPath,argument.getModelId()); String localDataPath = replaceDuplicateSeparator(String.join(File.separator,dataPath,argument.getModelId()));
// /rasa/models 生成出来的模型的存放路径,也写在配置文件里面 // /rasa/models 生成出来的模型的存放路径,也写在配置文件里面
String localModelsPath = String.join(File.separator,modelsPath,argument.getModelId()); String localModelsPath = replaceDuplicateSeparator(String.join(File.separator,modelsPath,argument.getModelId()));
List<String> cmds = ListUtil.toList(shellEnv, trainShell,config,localDataPath,domain,localModelsPath); List<String> cmds = ListUtil.toList(shellEnv, trainShell,config,localDataPath,domain,localModelsPath);
cmds.add(argument.getFixedModelName()); cmds.add(argument.getFixedModelName());
@ -97,7 +98,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
// 2. 运行模型 // 2. 运行模型
// 2.1 -m 参数对应的值 /rasa/models/aaa1111.tar.gz 指run的模型的路径/rasa/models应该来自于配置文件和训练时的--out是同一配置项 // 2.1 -m 参数对应的值 /rasa/models/aaa1111.tar.gz 指run的模型的路径/rasa/models应该来自于配置文件和训练时的--out是同一配置项
// aaa1111.tar.gz这个前面的文件名应该是--fixed-model-name指定的.tar.gz是文件后缀代码拼接 // aaa1111.tar.gz这个前面的文件名应该是--fixed-model-name指定的.tar.gz是文件后缀代码拼接
String localPath = String.join(File.separator,modelsPath,argument.getModelId(),argument.getFixedModelName(),".tar.gz"); String localPath = replaceDuplicateSeparator(String.join(File.separator,modelsPath,argument.getModelId(),argument.getFixedModelName()+".tar.gz"));
List<String> cmds = ListUtil.toList(shellEnv, runShell,localPath,endpoints,String.valueOf(port)); List<String> cmds = ListUtil.toList(shellEnv, runShell,localPath,endpoints,String.valueOf(port));
log.info("runExec cmd : {}",StrUtil.join(" ",cmds)); log.info("runExec cmd : {}",StrUtil.join(" ",cmds));
@ -115,14 +116,6 @@ public class RasaCmdServiceImpl implements RasaCmdService {
return String.join("\r\n",outMessageList); return String.join("\r\n",outMessageList);
} }
@Override
public void test() {
RasaModelInfo rasaModelInfo = new RasaModelInfo();
rasaModelInfo.setId("1");
rasaModelInfo.setModelId("1");
rasaModelInfo.setTranStatus(1);
rasaModeService.saveOrUpdate(rasaModelInfo);
}
public List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException { public List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException {
@ -178,4 +171,13 @@ public class RasaCmdServiceImpl implements RasaCmdService {
return messageList.stream().anyMatch(s->StrUtil.isNotEmpty(s) && s.contains(keyWord)); return messageList.stream().anyMatch(s->StrUtil.isNotEmpty(s) && s.contains(keyWord));
} }
private String replaceDuplicateSeparator(String path){
if (StrUtil.isEmpty(path)){
return path;
}
return path.replace(File.separator + File.separator, File.separator);
}
} }

@ -12,14 +12,13 @@ server:
direct-buffers: true direct-buffers: true
rasa: rasa:
#data-path: /home/rasa/model_resource/ # 文件解压后存放位置 data-path: /data/vp/rasa/model_resource/ # 文件解压后存放位置
data-path: F:\tmp\model_resource\ # 文件解压后存放位置 models-path: /data/vp/rasa/models/
models-path: /rasa/models/
endpoints: /rasa/endpoints.yml # 启动的配置项,应该是写在配置文件里面 endpoints: /rasa/endpoints.yml # 启动的配置项,应该是写在配置文件里面
config: /rasa/config-local.yml # 启动rasa需要的配置文件在配置文件中配置 config: /rasa/config-local.yml # 启动rasa需要的配置文件在配置文件中配置
train-shell: /home/rasa_manage/train.sh train-shell: /data/vp/rasa_shell/train.sh
run-shell: /home/rasa_manage/run.sh run-shell: /data/vp/rasa_shell/run.sh
url: 192.168.10.137:{}/webhooks/rest/webhook url: 127.0.0.1:{}/webhooks/rest/webhook
wakeup: wakeup:
cron: 0 */10 * * * ? #每十分钟执行一次 cron: 0 */10 * * * ? #每十分钟执行一次
spring: spring:

Loading…
Cancel
Save