提交生成rasa的yml文件的代码

dev_v1.0.1
liu 2 years ago
parent 77ba20f827
commit 8edb5cab16

@ -0,0 +1,33 @@
version: "3.1"
intents:
- self_introduction
- goodbye
- greet
- ask_bushufu
responses:
utter_self_introduction:
- text: "再见"
utter_goodbye:
- text: "你好医生"
utter_greet:
- text: "你好"
utter_ask_bushufu:
- text: "我最近感觉心跳特别快,喘不上气。"
utter_tool_tool_shizhen:
- text: "---tool---1"
utter_tool_tool_huxi:
- text: "---tool---10"
actions:
- utter_self_introduction
- utter_goodbye
- utter_greet
- utter_ask_bushufu
- utter_tool_tool_shizhen
- utter_tool_tool_huxi
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true

@ -0,0 +1,28 @@
version: "3.1"
nlu:
- intent: greet
examples: |
- 你好
- 你好啊
- 你好你好
- intent: goodbye
examples: |
- 再见
- 拜拜
- intent: self_introduction
examples: |
- 我是张医生
- intent: ask_bushufu
examples: |
- 今天您有什么不舒服?哪里不舒服?
- intent: tool_tool_shizhen
examples: |
- 1
- 22
- 333
- intent: tool_tool_huxi
examples: |
- 1
- 22
- 333

@ -32,7 +32,7 @@
<spring.boot.version>2.3.5.RELEASE</spring.boot.version>
<fastjson.version>1.2.76</fastjson.version>
<mybatis-puls-spring-boot.version>3.3.1</mybatis-puls-spring-boot.version>
<druid.version>1.1.10</druid.version>
<druid.version>1.1.22</druid.version>
<hutool.version>5.8.16</hutool.version>
<knife4j.version>3.0.3</knife4j.version>
</properties>

@ -0,0 +1,28 @@
version: "3.1"
rules:
- rule: 自我介绍
steps:
- intent: self_introduction
- action: utter_self_introduction
- rule: 再见
steps:
- intent: goodbye
- action: utter_goodbye
- rule: 问候
steps:
- intent: greet
- action: utter_greet
- rule: 问不舒服
steps:
- intent: ask_bushufu
- action: utter_ask_bushufu
- rule: 视诊
steps:
- intent: tool_tool_shizhen
- action: utter_tool_tool_shizhen
- rule: 呼吸
steps:
- intent: tool_tool_huxi
- action: utter_tool_tool_huxi

@ -0,0 +1,27 @@
package com.supervision.handler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
public class StringListTypeHandler extends JacksonTypeHandler {
private static final ObjectMapper objectMapper = new ObjectMapper();
public StringListTypeHandler(Class<Object> type) {
super(type);
}
@Override
protected Object parse(String json) {
try {
return objectMapper.readValue(json, new TypeReference<List<String>>() {});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

@ -26,11 +26,6 @@ public class AskQuestion implements Serializable {
*/
private String intentId;
/**
*
*/
private String code;
/**
*
*/

@ -4,15 +4,20 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import com.supervision.handler.StringListTypeHandler;
import lombok.Data;
/**
*
*
* @TableName vp_config_ancillary_item
*/
@TableName(value ="vp_config_ancillary_item")
@TableName(value = "vp_config_ancillary_item", autoResultMap = true)
@Data
public class ConfigAncillaryItem implements Serializable {
/**
@ -36,6 +41,9 @@ public class ConfigAncillaryItem implements Serializable {
*/
private String info;
@TableField(typeHandler = StringListTypeHandler.class)
private List<String> callOutQuestion;
/**
* ID
*/

@ -1,18 +1,20 @@
package com.supervision.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.supervision.handler.StringListTypeHandler;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import lombok.Data;
import java.util.List;
/**
*
* @TableName vp_config_physical_tool
*/
@TableName(value ="vp_config_physical_tool")
@TableName(value ="vp_config_physical_tool",autoResultMap = true)
@Data
public class ConfigPhysicalTool implements Serializable {
/**
@ -41,6 +43,9 @@ public class ConfigPhysicalTool implements Serializable {
*/
private Integer requireLocation;
@TableField(typeHandler = StringListTypeHandler.class)
private List<String> callOutQuestion;
/**
* ID
*/

@ -7,7 +7,6 @@
<resultMap id="BaseResultMap" type="com.supervision.model.AskQuestion">
<id property="id" column="id" jdbcType="VARCHAR"/>
<result property="intentId" column="intent_id" jdbcType="VARCHAR"/>
<result property="code" column="code" jdbcType="VARCHAR"/>
<result property="question" column="question" jdbcType="VARCHAR"/>
<result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
@ -16,7 +15,7 @@
</resultMap>
<sql id="Base_Column_List">
id,intent_id,code,
id,intent_id
question,create_user_id,create_time,
update_user_id,update_time
</sql>

@ -9,6 +9,7 @@
<result property="itemClass" column="item_class" jdbcType="VARCHAR"/>
<result property="itemName" column="item_name" jdbcType="VARCHAR"/>
<result property="info" column="info" jdbcType="VARCHAR"/>
<result column="call_out_question" jdbcType="ARRAY" property="callOutQuestion" typeHandler="com.supervision.handler.StringListTypeHandler" />
<result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateUserId" column="update_user_id" jdbcType="VARCHAR"/>

@ -10,6 +10,7 @@
<result property="code" column="code" jdbcType="VARCHAR"/>
<result property="toolName" column="tool_name" jdbcType="VARCHAR"/>
<result property="requireLocation" column="require_location" jdbcType="INTEGER"/>
<result column="call_out_question" jdbcType="ARRAY" property="callOutQuestion" typeHandler="com.supervision.handler.StringListTypeHandler" />
<result property="createUserId" column="create_user_id" jdbcType="VARCHAR"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="updateUserId" column="update_user_id" jdbcType="VARCHAR"/>

@ -34,6 +34,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<!-- 用来生成yml文件,jakson的模板库满足不了多行文本|管道符的需求-->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
</dependencies>

@ -13,6 +13,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.io.IOException;
import java.util.List;
@Api(tags = "问诊")
@RestController
@ -38,17 +39,20 @@ public class AskController {
@ApiOperation("回复语音及文字消息")
@GetMapping("replyVoice")
public ReplyVoiceResVO replyVoice(){
return askService.replyVoice();
}
@ApiOperation("查询对话历史")
public void queryAskHistory(String processId){
public ReplyVoiceResVO replyVoice() {
return askService.replyVoice();
}
@ApiOperation("进行对话")
@GetMapping("conversation")
public List<String> conversation(String question) {
return askService.conversation(question);
}
@ApiOperation("查询对话历史")
public void queryAskHistory(String processId) {
}
}

@ -0,0 +1,22 @@
package com.supervision.controller;
import com.supervision.service.RasaService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("rasa")
@RequiredArgsConstructor
public class RasaController {
private final RasaService rasaService;
@GetMapping("generateRasaYml")
public void generateRasaYml(String diseaseId){
rasaService.generateRasaYml(diseaseId);
}
}

@ -1,15 +1,28 @@
package com.supervision.controller;
import com.supervision.model.ConfigPhysicalTool;
import com.supervision.service.ConfigPhysicalToolService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("test")
@RequiredArgsConstructor
public class TestController {
private final ConfigPhysicalToolService configPhysicalToolService;
@GetMapping("testExpireTime")
public String testExpireTime() {
return "OK";
}
@GetMapping("testQueryJSON")
public List<ConfigPhysicalTool> testQueryJSON(){
return configPhysicalToolService.list();
}
}

@ -0,0 +1,13 @@
package com.supervision.pojo.rasa;
import lombok.Data;
@Data
public class RasaReqDTO {
private String sender;
private String message;
}

@ -0,0 +1,11 @@
package com.supervision.pojo.rasa;
import lombok.Data;
@Data
public class RasaResDTO {
private String recipient_id;
private String text;
}

@ -0,0 +1,28 @@
package com.supervision.pojo.rasa.train.intent;
import lombok.Data;
import java.util.LinkedHashMap;
import java.util.List;
@Data
public class DomainYmlTemplate {
private List<String> intents;
private LinkedHashMap<String,List<String>> responses;
private List<String> actions;
private SessionConfig session_config = new SessionConfig();
@Data
public static class SessionConfig{
private final int session_expiration_time = 60;
private final Boolean carry_over_slots_to_new_session = true;
}
}

@ -0,0 +1,17 @@
package com.supervision.pojo.rasa.train.intent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Intent {
private String id;
private String code;
private String desc;
}

@ -0,0 +1,11 @@
package com.supervision.pojo.rasa.train.intent;
import lombok.Data;
import java.util.List;
@Data
public class NluTemplate {
}

@ -0,0 +1,23 @@
package com.supervision.pojo.rasa.train.intent;
import lombok.Data;
import org.yaml.snakeyaml.nodes.Tag;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@Data
public class NluYmlTemplate {
private List<Nlu> nlu;
@Data
public static class Nlu{
private String intent;
private List<String> examples;
}
}

@ -0,0 +1,44 @@
package com.supervision.pojo.rasa.train.intent;
import cn.hutool.core.map.MapUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.*;
@Data
public class RuleYmlTemplate {
private List<Rule> rules;
@Data
public static class Rule {
private String rule;
private List<Step> steps;
public Rule() {
}
public Rule(String rule, String intent, String action) {
this.rule = rule;
steps = new ArrayList<>();
Step step = new Step(intent, action);
steps.add(step);
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Step {
private String intent;
private String action;
}
}

@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface AskService {
@ -13,5 +14,7 @@ public interface AskService {
ReplyVoiceResVO replyVoice() ;
List<String> conversation(String question);
}

@ -0,0 +1,6 @@
package com.supervision.service;
public interface RasaService {
void generateRasaYml(String diseaseId);
}

@ -13,6 +13,8 @@ import com.supervision.pojo.paddlespeech.req.TtsReqDTO;
import com.supervision.pojo.paddlespeech.res.AsrResultDTO;
import com.supervision.pojo.paddlespeech.res.PaddleSpeechResDTO;
import com.supervision.pojo.paddlespeech.res.TtsResultDTO;
import com.supervision.pojo.rasa.RasaReqDTO;
import com.supervision.pojo.rasa.RasaResDTO;
import com.supervision.pojo.vo.ReplyVoiceResVO;
import com.supervision.service.AskService;
import lombok.RequiredArgsConstructor;
@ -21,6 +23,9 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
@ -33,6 +38,9 @@ public class AskServiceImpl implements AskService {
@Value("${paddle-speech.asr}")
private String asr;
@Value("${rasa.url}")
private String rasa;
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
@ -82,4 +90,15 @@ public class AskServiceImpl implements AskService {
}
}
@Override
public List<String> conversation(String question) {
RasaReqDTO rasaReqDTO = new RasaReqDTO();
rasaReqDTO.setSender("tester1");
rasaReqDTO.setMessage(question);
String post = HttpUtil.post(rasa, JSONUtil.toJsonStr(rasaReqDTO));
List<RasaResDTO> list = JSONUtil.toList(post, RasaResDTO.class);
return list.stream().map(RasaResDTO::getText).collect(Collectors.toList());
}
}

@ -0,0 +1,228 @@
package com.supervision.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.supervision.model.*;
import com.supervision.pojo.rasa.train.intent.*;
import com.supervision.service.*;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@RequiredArgsConstructor
public class RasaServiceImpl implements RasaService {
private final AskIntentService askIntentService;
private final AskQuestionService askQuestionService;
private final AskDefaultIntentService askDefaultIntentService;
private final AskDefaultQuestionService askDefaultQuestionService;
private final AskDefaultAnswerService askDefaultAnswerService;
private final AskAnswerService askAnswerService;
private final ConfigPhysicalToolService configPhysicalToolService;
@Override
public void generateRasaYml(String diseaseId) {
Map<String, Intent> defaultIntentCodeAndIdMap = new HashMap<>();
Map<String, Intent> questionCodeAndIdMap = new HashMap<>();
Map<String, ConfigPhysicalTool> toolCodeIdMap = new HashMap<>();
List<RuleYmlTemplate.Rule> ruleList = new ArrayList<>();
try {
generateNlu(diseaseId, defaultIntentCodeAndIdMap, questionCodeAndIdMap, toolCodeIdMap);
} catch (Exception e) {
e.printStackTrace();
}
generateDomain(defaultIntentCodeAndIdMap, questionCodeAndIdMap, toolCodeIdMap, ruleList);
generateRule(ruleList);
}
private void generateNlu(String diseaseId, Map<String, Intent> defaultIntentCodeAndIdMap,
Map<String, Intent> intentCodeAndIdMap,
Map<String, ConfigPhysicalTool> toolCodeIdMap) throws IOException, TemplateException {
// 首先生成根据意图查找到nlu文件
List<NluYmlTemplate.Nlu> nluList = new ArrayList<>();
// 默认意图
List<AskDefaultIntent> defaultIntentList = askDefaultIntentService.list();
// 根据默认意图找到所有的问题
if (CollUtil.isNotEmpty(defaultIntentList)) {
Set<String> defaultIntentIdSet = defaultIntentList.stream().map(AskDefaultIntent::getId).collect(Collectors.toSet());
// 去默认问题表找问题
List<AskDefaultQuestion> questionList = askDefaultQuestionService.lambdaQuery().in(AskDefaultQuestion::getDefaultIntentId, defaultIntentIdSet).list();
Map<String, List<AskDefaultQuestion>> defaultQuestionByDefaultIntentId = questionList.stream().collect(Collectors.groupingBy(AskDefaultQuestion::getDefaultIntentId));
// 生成nlu的节点
for (AskDefaultIntent askDefaultIntent : defaultIntentList) {
List<AskDefaultQuestion> questions = defaultQuestionByDefaultIntentId.get(askDefaultIntent.getId());
if (CollUtil.isNotEmpty(questions)) {
// 开始生成
NluYmlTemplate.Nlu nlu = new NluYmlTemplate.Nlu();
nlu.setIntent(askDefaultIntent.getCode());
// 注意,这里的格式应该是 "- 你好\n- 你好啊\n- 你好你好" 这种的格式,所以我们要拼接
nlu.setExamples(questions.stream().map(AskDefaultQuestion::getQuestion).collect(Collectors.toList()));
nluList.add(nlu);
// 添加到map中,key为意图编码,value为意图ID
defaultIntentCodeAndIdMap.put(askDefaultIntent.getCode(), new Intent(askDefaultIntent.getId(), askDefaultIntent.getCode(), askDefaultIntent.getDescription()));
}
}
}
// 然后处理该疾病对应的意图
List<AskIntent> askIntentList = askIntentService.lambdaQuery().eq(AskIntent::getDiseaseId, diseaseId).list();
// 根据默认意图找到所有的问题
if (CollUtil.isNotEmpty(askIntentList)) {
Set<String> askIntentListSet = askIntentList.stream().map(AskIntent::getId).collect(Collectors.toSet());
// 去默认问题表找问题
List<AskQuestion> questionList = askQuestionService.lambdaQuery().in(AskQuestion::getIntentId, askIntentListSet).list();
Map<String, List<AskQuestion>> questionByDefaultIntentId = questionList.stream().collect(Collectors.groupingBy(AskQuestion::getIntentId));
// 生成nlu的节点
for (AskIntent askIntent : askIntentList) {
List<AskQuestion> questions = questionByDefaultIntentId.get(askIntent.getId());
if (CollUtil.isNotEmpty(questions)) {
// 开始生成
NluYmlTemplate.Nlu nlu = new NluYmlTemplate.Nlu();
nlu.setIntent(askIntent.getCode());
nlu.setExamples(questions.stream().map(AskQuestion::getQuestion).collect(Collectors.toList()));
nluList.add(nlu);
// 添加到map中,key为意图编码,value为意图ID
intentCodeAndIdMap.put(askIntent.getCode(), new Intent(askIntent.getId(), askIntent.getCode(), askIntent.getDescription()));
}
}
}
// 这里处理呼出的问题(code和问题不能为空)
List<ConfigPhysicalTool> physicalToolList = configPhysicalToolService.lambdaQuery()
.isNotNull(ConfigPhysicalTool::getCode)
.isNotNull(ConfigPhysicalTool::getCallOutQuestion).list();
for (ConfigPhysicalTool tool : physicalToolList) {
// 把呼出的问题全部加进去
NluYmlTemplate.Nlu nlu = new NluYmlTemplate.Nlu();
String toolIntent = "tool_" + tool.getCode();
nlu.setIntent(toolIntent);
nlu.setExamples(tool.getCallOutQuestion());
nluList.add(nlu);
// 生成tool的map,key是code,value是工具对应的ID
toolCodeIdMap.put(toolIntent, tool);
}
// 生成后生成yml对象
// createYmlFile(nluYml, "nlu.yml");
// 加载模板配置
NluYmlTemplate nluYmlTemplate = new NluYmlTemplate();
nluYmlTemplate.setNlu(nluList);
createYmlFile(NluYmlTemplate.class, "nlu.ftl", nluYmlTemplate, "nlu.yml");
}
public void generateDomain(Map<String, Intent> defaultQuestionCodeAndIdMap,
Map<String, Intent> questionCodeAndIdMap, Map<String, ConfigPhysicalTool> toolCodeIdMap,
List<RuleYmlTemplate.Rule> ruleList) {
LinkedHashMap<String, List<String>> responses = new LinkedHashMap<>();
// 首先根据默认意图找到所有的意图ID
Collection<Intent> defaultIntentIdColl = defaultQuestionCodeAndIdMap.values();
// 找到默认意图对应的回复
if (CollUtil.isNotEmpty(defaultIntentIdColl)) {
Set<String> defaultIntentIdSet = defaultIntentIdColl.stream().map(Intent::getId).collect(Collectors.toSet());
List<AskDefaultAnswer> defaultAnswerList = askDefaultAnswerService.lambdaQuery().in(AskDefaultAnswer::getDefaultIntentId, defaultIntentIdSet).list();
Map<String, String> answerMap = defaultAnswerList.stream().collect(Collectors.toMap(AskDefaultAnswer::getId, AskDefaultAnswer::getAnswer, (k1, k2) -> k1));
for (Map.Entry<String, Intent> entry : defaultQuestionCodeAndIdMap.entrySet()) {
String defaultIntentCode = entry.getKey();
Intent defaultIntent = entry.getValue();
String answer = answerMap.get(defaultIntent.getId());
String utter = "utter_" + defaultIntentCode;
responses.put(utter, CollUtil.newArrayList(answer));
ruleList.add(new RuleYmlTemplate.Rule(defaultIntent.getDesc(), defaultIntent.getCode(), utter));
}
}
// 然后疾病意图对应的回复
Collection<Intent> intentIdColl = questionCodeAndIdMap.values();
if (CollUtil.isNotEmpty(intentIdColl)) {
Set<String> intentIdSet = intentIdColl.stream().map(Intent::getId).collect(Collectors.toSet());
List<AskAnswer> answerList = askAnswerService.lambdaQuery().in(AskAnswer::getIntentId, intentIdSet).list();
Map<String, String> answerMap = answerList.stream().collect(Collectors.toMap(AskAnswer::getId, AskAnswer::getAnswer, (k1, k2) -> k1));
for (Map.Entry<String, Intent> entry : questionCodeAndIdMap.entrySet()) {
String intentCode = entry.getKey();
Intent intent = entry.getValue();
String answer = answerMap.get(intent.getId());
String utter = "utter_" + intentCode;
responses.put(utter, CollUtil.newArrayList(answer));
ruleList.add(new RuleYmlTemplate.Rule(intent.getDesc(), intent.getCode(), utter));
}
}
// 生成呼出tool对应的回复
for (Map.Entry<String, ConfigPhysicalTool> entry : toolCodeIdMap.entrySet()) {
String intentCode = entry.getKey();
ConfigPhysicalTool tool = entry.getValue();
String utter = "utter_" + intentCode;
String answer = "---tool---" + tool.getId() ;
responses.put(utter, CollUtil.newArrayList(JSONUtil.toJsonStr(answer)));
ruleList.add(new RuleYmlTemplate.Rule(tool.getToolName(), intentCode, utter));
}
DomainYmlTemplate domainYmlTemplate = new DomainYmlTemplate();
// 意图
List<String> intentList = new ArrayList<>();
intentList.addAll(defaultQuestionCodeAndIdMap.keySet());
intentList.addAll(questionCodeAndIdMap.keySet());
domainYmlTemplate.setIntents(intentList);
// 回复
domainYmlTemplate.setResponses(responses);
// action
List<String> actionList = new ArrayList<>(responses.keySet());
domainYmlTemplate.setActions(actionList);
// 生成yml文件
createYmlFile(DomainYmlTemplate.class, "domain.ftl", domainYmlTemplate, "domain.yml");
}
/**
* rule
*/
public void generateRule(List<RuleYmlTemplate.Rule> ruleList) {
RuleYmlTemplate ruleYmlTemplate = new RuleYmlTemplate();
ruleYmlTemplate.setRules(ruleList);
// 生成yml文件
createYmlFile(RuleYmlTemplate.class, "rules.ftl", ruleYmlTemplate, "rules.yml");
}
private void createYmlFile(Class<?> clazz, String ftlName, Object data, String ymlName) {
try {
// 这个版本和maven依赖的版本一致
Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
configuration.setClassForTemplateLoading(clazz, "/templates"); // 模板文件的所在目录
// 获取模板
Template template = configuration.getTemplate(ftlName);
// 创建输出文件
PrintWriter out = new PrintWriter(ymlName);
// 填充并生成输出
template.process(data, out);
// 关闭资源
out.close();
} catch (Exception e) {
log.error("导出模板失败", e);
}
}
}

@ -60,4 +60,6 @@ mybatis-plus:
paddle-speech:
# https://github.com/PaddlePaddle/PaddleSpeech/wiki/PaddleSpeech-Server-RESTful-API
tts: http://192.168.10.137:8090/paddlespeech/tts
asr: http://192.168.10.137:8090/paddlespeech/asr
asr: http://192.168.10.137:8090/paddlespeech/asr
rasa:
url: 192.168.10.137:5005/webhooks/rest/webhook

@ -0,0 +1,23 @@
version: "3.1"
intents:
<#list intents as intent>
- ${intent}
</#list>
responses:
<#list responses?keys as response>
${response}:
<#list responses[response] as item>
- text: "${item}"
</#list>
</#list>
actions:
<#list actions as action>
- ${action}
</#list>
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true

@ -0,0 +1,10 @@
version: "3.1"
nlu:
<#list nlu as item>
- intent: ${item.intent}
examples: |
<#list item.examples as example>
- ${example}
</#list>
</#list>

@ -0,0 +1,12 @@
version: "3.1"
rules:
<#list rules as item>
- rule: ${item.rule}
steps:
<#list item.steps as ss>
- intent: ${ss.intent}
- action: ${ss.action}
</#list>
</#list>
Loading…
Cancel
Save