Commit 0957bbba authored by 何金镒's avatar 何金镒

思必驰的兜底技能 2

parent 317ab450
......@@ -40,6 +40,8 @@ public class DifyController {
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Value("${cdc.difyChatSteamMessages}")
private String difyChatSteamMessages;
private String dify_api_key;
......@@ -56,10 +58,16 @@ public class DifyController {
}
}
/**
* 思必驰 demo
* https://www.duiopen.com/docs/ct_dsk_protocol
*
*/
@RequestMapping(value = "/demo", method = RequestMethod.POST, consumes = "application/json")
@ResponseBody
public JSONObject demo(@RequestBody JSONObject jsonObject) {
log.info("demo..请求参数:{}",jsonObject.toString());
Long timestamp = System.currentTimeMillis();
log.info("思必驰 demo..请求参数:{}",jsonObject.toString());
JSONObject result = jsonObject.getJSONObject("request");
JSONObject context = jsonObject.getJSONObject("context");
JSONObject device = context.getJSONObject("device");
......@@ -70,6 +78,8 @@ public class DifyController {
String type = result.get("type").toString();
String input; //请求文本
String res = "{'version': '1.0','response': {'speak': {'type': 'text','text': '%s','ssml': 'SSML markup text string to speak'}},'shouldEndSession': %b}"; //忽略了部分DSK协议字段,shouldEndSession字段决定是否结束本轮对话
JSONObject response = JSONUtil.parseObj(String.format(res, "error", true)); // 响应报文
JSONArray slots;
String ai_result = "";
......@@ -92,6 +102,9 @@ public class DifyController {
// }
// response = JSONUtil.parseObj(res);
// }
if (type.equals("start")) {
log.info("新一轮对话开始...........");
}
//根据userId获取到对应的主机号等信息
QueryWrapper<CDCToken> wrapper = new QueryWrapper<>();
......@@ -100,12 +113,12 @@ public class DifyController {
if(list.size() == 1){
CDCToken token = list.get(0);
String url = "http://172.17.12.12:9998/dify/chatSteamMessages?query="+input;
String url = difyChatSteamMessages + "/dify/chatSteamMessages?query="+input;
ai_result = HttpRequest.get(url)
.header("ccuName", token.getCcuId() )
.header("token", token.getAccessToken())
.header("sn",token.getSn())
.timeout(1000000)
.timeout(600000)
.execute().body();
log.info("dify请求返回:{}",ai_result);
......@@ -128,6 +141,7 @@ public class DifyController {
response = JSONUtil.parseObj(res);
e.printStackTrace();
} finally {
log.info("思必驰 demo..响应时间="+(System.currentTimeMillis()-timestamp));
return response;
}
}
......@@ -296,7 +310,7 @@ public class DifyController {
body.set("conversation_id",conversationId);
}
log.info("dify key:{} , 对话 body:{}",dify_api_key,body);
log.info("dify key:{} ,流式 对话 body:{}",dify_api_key,body);
return webClient.post()
......
......@@ -52,4 +52,5 @@ konke:
cdc:
timeout: 20000
url: http://community.jfzhtest.com/prod-api
difyChatSteamMessages: http://127.0.0.1:${server.port}
......@@ -49,3 +49,4 @@ konke:
cdc:
timeout: 20000
url: http://community.jfzhtest.com/prod-api
difyChatSteamMessages: http://172.17.12.12:${server.port}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment