|
|
|
@@ -12,6 +12,7 @@ import com.xueyi.nlt.nlt.constant.PromptsConstants; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmContext; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmParam; |
|
|
|
import com.xueyi.nlt.nlt.domain.LlmResponse; |
|
|
|
import com.xueyi.nlt.nlt.domain.vo.WelcomeLabelVo; |
|
|
|
import com.xueyi.nlt.nlt.service.ISysLlmService; |
|
|
|
import com.xueyi.system.api.holiday.domain.po.DmHolidayPo; |
|
|
|
import com.xueyi.system.api.holiday.feign.FeignHolidayService; |
|
|
|
@@ -24,6 +25,10 @@ import org.springframework.stereotype.Service; |
|
|
|
import static com.xueyi.nlt.nlt.constant.PromptsConstants.*; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
@Service("generative-welcome") |
|
|
|
@@ -52,7 +57,17 @@ public class GenerativeWelcomeTemplate implements BaseTemplate{ |
|
|
|
|
|
|
|
@Override |
|
|
|
public JSONObject handle(String devId, String content) { |
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
JSONObject timeType = new JSONObject(); |
|
|
|
timeType.put("morning", "早上"); |
|
|
|
timeType.put("noon", "中午"); |
|
|
|
timeType.put("afternoon", "下午"); |
|
|
|
timeType.put("night", "晚上"); |
|
|
|
|
|
|
|
JSONObject peopleType = new JSONObject(); |
|
|
|
peopleType.put("employee", "员工"); |
|
|
|
peopleType.put("employer", "老板"); |
|
|
|
peopleType.put("visitor", "访客"); |
|
|
|
|
|
|
|
String holiday = ""; |
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
if (StringUtils.isBlank(lunar)) { |
|
|
|
@@ -72,23 +87,67 @@ public class GenerativeWelcomeTemplate implements BaseTemplate{ |
|
|
|
DmHolidayPo po = JSON.parseObject(JSON.toJSONString(result.get("data")), DmHolidayPo.class); |
|
|
|
holiday = po.getName(); |
|
|
|
} |
|
|
|
List<WelcomeLabelVo> resultList = new ArrayList<>(); |
|
|
|
String prefix = "假设你是公司前台,"; |
|
|
|
String suffix = "请根据以上信息生成简短的话对他打招呼。生成十句打招呼内容,输出为一个JSON数组[{}],每个元素是一个JSON:{“content”:}。不要给出任何解释说明,不要带人名。"; |
|
|
|
for(String time:timeType.keySet()) { |
|
|
|
String timeString = getTimeTypeFormat(timeType.getString(time)); |
|
|
|
WelcomeLabelVo labelVo = new WelcomeLabelVo(); |
|
|
|
labelVo.setLabelName(time); |
|
|
|
List<WelcomeLabelVo> welcomeLabelVoList = new ArrayList<>(); |
|
|
|
|
|
|
|
//生成节日或节气的特殊招呼语 |
|
|
|
if(!holiday.isBlank()|| !term.isBlank()){ |
|
|
|
WelcomeLabelVo festivalWelcomeLabelVo = new WelcomeLabelVo(); |
|
|
|
festivalWelcomeLabelVo.setLabelName("festival"); |
|
|
|
log.info(prefix + getFestivalFormat(holiday) + getSolarTermFormat(term) + timeString + "看到员工时," + suffix); |
|
|
|
LlmContext llmContext = new LlmContext(prefix + getFestivalFormat(holiday) + getSolarTermFormat(term) + timeString + "看到员工时," + suffix); |
|
|
|
llmContext.setDevId(devId); |
|
|
|
LlmParam llmParam = new LlmParam(); |
|
|
|
LlmResponse response = sysLlmService.chat(llmContext, llmParam); |
|
|
|
JSONArray sentenceArray = JSONArray.parseArray(response.getContent()); |
|
|
|
List<String> responseList = new ArrayList<>(); |
|
|
|
for (JSONObject sentence : sentenceArray.toList(JSONObject.class)) { |
|
|
|
responseList.add(sentence.getString("content")); |
|
|
|
} |
|
|
|
festivalWelcomeLabelVo.setMsgs(responseList); |
|
|
|
welcomeLabelVoList.add(festivalWelcomeLabelVo); |
|
|
|
} |
|
|
|
|
|
|
|
// 根据content内容调用模版并返回结果 |
|
|
|
String prefix = "假设你是公司前台," + getDateFormat(now) + getFestivalFormat(holiday) + getSolarTermFormat(term) + "当你看到公司员工时,请根据以上信息生成简短的话和他打招呼。生成十句打招呼内容,输出为一个JSON数组[{}],每个元素是一个JSON:{“content”:}。不要给出任何解释说明。"; |
|
|
|
String suffix = ""; |
|
|
|
log.info(prefix + content + suffix); |
|
|
|
LlmContext llmContext = new LlmContext(prefix + content + suffix); |
|
|
|
llmContext.setDevId(devId); |
|
|
|
LlmParam llmParam = new LlmParam(); |
|
|
|
LlmResponse response = sysLlmService.chat(llmContext,llmParam); |
|
|
|
try { |
|
|
|
jsonObject.put("msg",response.getContent()); |
|
|
|
return jsonObject; |
|
|
|
} catch (JSONException je) { |
|
|
|
// 返回结果错误,计日志,存log,返回空结果 |
|
|
|
log.error(je.getMessage(),je); |
|
|
|
//按人员类型生成招呼语 |
|
|
|
for (String people : peopleType.keySet()) { |
|
|
|
WelcomeLabelVo welcomeLabelVo = new WelcomeLabelVo(); |
|
|
|
welcomeLabelVo.setLabelName(people); |
|
|
|
String peopleString = getPeopleTypeFormat(peopleType.getString(people)); |
|
|
|
log.info(prefix + timeString + peopleString + suffix); |
|
|
|
LlmContext llmContext = new LlmContext(prefix + timeString + peopleString + suffix); |
|
|
|
llmContext.setDevId(devId); |
|
|
|
LlmParam llmParam = new LlmParam(); |
|
|
|
LlmResponse response = sysLlmService.chat(llmContext, llmParam); |
|
|
|
JSONArray sentenceArray = JSONArray.parseArray(response.getContent()); |
|
|
|
List<String> responseList = new ArrayList<>(); |
|
|
|
for (JSONObject c : sentenceArray.toList(JSONObject.class)) { |
|
|
|
responseList.add(c.getString("content")); |
|
|
|
} |
|
|
|
welcomeLabelVo.setMsgs(responseList); |
|
|
|
welcomeLabelVoList.add(welcomeLabelVo); |
|
|
|
} |
|
|
|
labelVo.setLabels(welcomeLabelVoList); |
|
|
|
resultList.add(labelVo); |
|
|
|
} |
|
|
|
return jsonObject; |
|
|
|
JSONObject finalresult = new JSONObject(); |
|
|
|
finalresult.put("data", resultList); |
|
|
|
return finalresult; |
|
|
|
|
|
|
|
// 根据content内容调用模版并返回结果 |
|
|
|
// String prefix = "假设你是公司前台," + getDateFormat(now) + getFestivalFormat(holiday) + getSolarTermFormat(term) + "当你看到公司员工时,请根据以上信息生成简短的话和他打招呼。生成十句打招呼内容,输出为一个JSON数组[{}],每个元素是一个JSON:{“content”:}。不要给出任何解释说明。"; |
|
|
|
// String suffix = ""; |
|
|
|
// log.info(prefix + content + suffix); |
|
|
|
// LlmContext llmContext = new LlmContext(prefix + content + suffix); |
|
|
|
// llmContext.setDevId(devId); |
|
|
|
// LlmParam llmParam = new LlmParam(); |
|
|
|
// LlmResponse response = sysLlmService.chat(llmContext,llmParam); |
|
|
|
// return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|