【Java】UNIT2.0 API调用示例
756665228 发布于2018-07 浏览:5950 回复:20
9
收藏

官网给出了示例代码。但是请求参数为字符串拼接。为了方便大家实际应用。小帅丶封装成了一个JavaBean。当然看大家喜好了。并不是说纯字符串拼接不好。

  • 需要用到的第三方jar


    com.alibaba
    fastjson
    1.2.47

 

  • 请求参数封装的对象UnitV2RequestBean
import java.util.List;
/**
 * UNIT 2.0 API请求所需要的bean对象封装
 * @author 小帅丶
 * set/get方法省略 请自行补上
 */
public class UnitV2RequestBean {
	private String version;//2.0,当前api版本对应协议版本号为2.0,固定值
	private String bot_id;//BOT唯一标识,在『我的BOT』的BOT列表中第一列数字即为bot_id
	private String log_id;//开发者需要在客户端生成的唯一id,用来定位请求,响应中会返回该字段。对话中每轮请求都需要一个log_id。
	private Request request;//本轮请求体
	private String bot_session;//BOT的session信息
	/**
	 * 本轮请求体对象
	 * @author 小帅丶
	 *
	 */
	public static class Request{
		private String user_id;//与BOT对话的用户id
		private String query;//本轮请求query(用户说的话)
		private QueryInfo query_info;//本轮请求query的附加信息。
		private int bernard_level;//澄清确认的敏感程度。取值范围:0(关闭)、1(中敏感度)、2(高敏感度)。
		private String client_session;//client希望传给BOT的本地信息
	}
	/**
	 * 
	 * @author 小帅丶
	 *
	 */
	public static class QueryInfo{
		private String type;
		private String source;
	}
	/**
	 * 
	 * @author 小帅丶
	 *
	 */
	public static class ClientSession{
		private String client_results;
		private List candidate_options;
	}
}

 

  • 调用示例代码

httputil代码下载:https://ai.baidu.com/file/544D677F5D4E4F17B4122FBD60DB82B3

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
/**
 * UNIT 2.0 API请求示例代码
 * @author 小帅丶
 *
 */
public class UnitV2Sample {
	public static String UNIT_URL ="https://aip.baidubce.com/rpc/2.0/unit/bot/chat";
	public static void main(String[] args) throws Exception {
		String result = getUNITV2Result("场景ID", "本轮对话内容", "自己应用获取的AccessToken");
		System.out.println(result);
	}
	/**
	 * UNIT 2.0 API请求方法 只需要场景id 和对话内容参数 大家可以根据需要稍作修改
	 * @param bot_id 场景id
	 * @param query 本轮对话内容
	 * @param access_token 请求接口所需的access_token
	 * @return String
	 * @throws Exception
	 */
	public static String getUNITV2Result(String bot_id,String query,String access_token) throws Exception{
		UnitV2RequestBean bean = new UnitV2RequestBean();
		bean.setVersion("2.0");
		bean.setBot_id(bot_id);
		bean.setLog_id("XS"+System.currentTimeMillis());
		Request request = new Request();
		request.setUser_id("XS0001");//测试设置 大家请自行更改
		request.setQuery(query);
		QueryInfo query_info = new QueryInfo();
		query_info.setType("TEXT");
		query_info.setSource("KEYBOARD");
		request.setQuery_info(query_info);
		request.setBernard_level(0);
		//希望传给bot的本地信息
		ClientSession client_session = new ClientSession();
		client_session.setClient_results("hhhh");
		List candidate_options = new ArrayList();
		candidate_options.add(0, "123");
		candidate_options.add(1, "456");
		client_session.setCandidate_options(candidate_options);
		/**
		 * ClientSession所需要的是字符串类型 内容为json格式  
		 * "client_session": "{\"candidate_options\": [\"123\", \"456\"], \"client_results\": \"hhhh\"}"
		 */
		String client_sessionparam = JSONObject.toJSONString(client_session);
		request.setClient_session(client_sessionparam);
		bean.setRequest(request);
		bean.setBot_session("");
		String jsonparam = JSONObject.toJSONString(bean);
		System.out.println("参数"+jsonparam);
		String result = HttpUtil.post(UNIT_URL, access_token, "application/json", jsonparam);
		return result;
	}
}

 

收藏
点赞
9
个赞
共20条回复 最后由果断叫小黑回复于2019-09
#21果断叫小黑回复于2019-09
#18 756665228回复
多轮接口测试还真没有过。可以加我QQ  783021975 帮你试试。
展开

小帅有多轮对话测试的例子吗?

0
#20叶鱼地方回复于2019-09

原来结果解析就在同一个文件夹下啊

0
#19叶鱼地方回复于2019-09

能把返回的结果也解析一下吗?返回的数据太多,头晕

0
#18用户已被禁言回复于2019-02
#17 四叶草1有星星回复
在实现多伦对话的时候传入的bot_session 参数是:{\\\"bot_id\\\":\\\"37819\\\",\\\"bot_views\\\":{\\\"bernard_res\\\":[{\\\"action_list\\\":[{\\\"action_id\\\":\\\"\\\",\\\"confidence\\\":0.0,\\\"custom_reply\\\":\\\"\\\",\\\"refine_detail\\\":{\\\"clarify_reason\\\":\\\"\\\",\\\"interact\\\":\\\"\\\",\\\"option_list\\\":[]},\\\"say\\\":\\\"\\\",\\\"type\\\":\\\"understood\\\"}],\\\"msg\\\":\\\"ok\\\",\\\"pre_nlu_outs\\\":[{\\\"otags_basic\\\":[{\\\"blength\\\":2,\\\"boffset\\\":0,\\\"eid\\\":\\\"\\\",\\\"entity_confidence\\\":0.0,\\\"etype\\\":\\\"user_hello\\\",\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"father_fully_covered\\\":false,\\\"father_index\\\":-1,\\\"features\\\":[],\\\"formal\\\":\\\"\\\",\\\"formals\\\":[\\\"\\\"],\\\"length\\\":1,\\\"method\\\":\\\"[D:user_hello] == [D:user_hello]\\\",\\\"name\\\":\\\"喂\\\",\\\"offset\\\":0,\\\"rstatus\\\":2,\\\"type_confidence\\\":10.50},{\\\"blength\\\":4,\\\"boffset\\\":4,\\\"eid\\\":\\\"\\\",\\\"entity_confidence\\\":0.0,\\\"etype\\\":\\\"user_hello\\\",\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"father_fully_covered\\\":false,\\\"father_index\\\":-1,\\\"features\\\":[],\\\"formal\\\":\\\"\\\",\\\"formals\\\":[\\\"\\\"],\\\"length\\\":1,\\\"method\\\":\\\"[D:user_hello] == [D:user_hello]\\\",\\\"name\\\":\\\"您好\\\",\\\"offset\\\":2,\\\"rstatus\\\":2,\\\"type_confidence\\\":10.50}],\\\"otags_wpcomp\\\":[],\\\"polarity\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"tokens_basic\\\":[{\\\"buffer\\\":\\\"喂\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.9479930996894836,\\\"offset\\\":0,\\\"type\\\":34,\\\"weight\\\":0.4515353739261627},{\\\"buffer\\\":\\\",\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":2,\\\"type\\\":37,\\\"weight\\\":0.01189841516315937},{\\\"buffer\\\":\\\"您好\\\",\\\"length\\\":4,\\\"norm_degree\\\":0.0,\\\"offset\\\":4,\\\"type\\\":19,\\\"weight\\\":0.5365661978721619}],\\\"tokens_wpcomp\\\":[{\\\"buffer\\\":\\\"喂\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":0,\\\"type\\\":34,\\\"weight\\\":0.4515353739261627},{\\\"buffer\\\":\\\",\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":1,\\\"type\\\":37,\\\"weight\\\":0.2317169010639191},{\\\"buffer\\\":\\\"您好\\\",\\\"length\\\":4,\\\"norm_degree\\\":0.0,\\\"offset\\\":2,\\\"type\\\":19,\\\"weight\\\":0.2801815271377563}]}],\\\"qu_res\\\":{\\\"candidates\\\":[{\\\"confidence\\\":100.0,\\\"domain_confidence\\\":0.0,\\\"extra_info\\\":{\\\"group_id\\\":\\\"25\\\",\\\"real_threshold\\\":\\\"1\\\",\\\"threshold\\\":\\\"0.4\\\"},\\\"from_who\\\":\\\"pow-slu-lev1\\\",\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"intent_need_clarify\\\":false,\\\"match_info\\\":\\\"{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"id\\\\\\\":\\\\\\\"1958113\\\\\\\",\\\\\\\"informal_word\\\\\\\":\\\\\\\",\\\\\\\\t您好\\\\\\\",\\\\\\\"match_keywords\\\\\\\":\\\\\\\" \\\\\\\",\\\\\\\"match_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_slots\\\\\\\":{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{},\\\\\\\"from_who\\\\\\\":\\\\\\\"smart_qu\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"喂 \\\\\\\\t您好 \\\\\\\",\\\\\\\"slots\\\\\\\":[]},\\\\\\\"real_threshold\\\\\\\":1.0,\\\\\\\"threshold\\\\\\\":0.4000000059604645}\\\",\\\"slots\\\":[]}],\\\"lexical_analysis\\\":[{\\\"basic_word\\\":[\\\"喂\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"喂\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.4510},{\\\"basic_word\\\":[\\\",\\\"],\\\"etypes\\\":[],\\\"term\\\":\\\",\\\",\\\"type\\\":\\\"37\\\",\\\"weight\\\":0.0110},{\\\"basic_word\\\":[\\\"您好\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"您好\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.5360}],\\\"qu_res_chosen\\\":\\\"{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"real_threshold\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"threshold\\\\\\\":\\\\\\\"0.4\\\\\\\"},\\\\\\\"from_who\\\\\\\":\\\\\\\"pow-slu-lev1\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"group_id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"25\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"1958113\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"informal_word\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_keywords\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_slots\\\\\\\\\\\\\\\":{\\\\\\\\\\\\\\\"confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"domain_confidence\\\\\\\\\\\\\\\":0.0,\\\\\\\\\\\\\\\"extra_info\\\\\\\\\\\\\\\":{},\\\\\\\\\\\\\\\"from_who\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"smart_qu\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"INTENTION_1\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent_confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"intent_need_clarify\\\\\\\\\\\\\\\":false,\\\\\\\\\\\\\\\"match_info\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂 \\\\\\\\\\\\\\\\t您好 \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"slots\\\\\\\\\\\\\\\":[]},\\\\\\\\\\\\\\\"real_threshold\\\\\\\\\\\\\\\":1.0,\\\\\\\\\\\\\\\"threshold\\\\\\\\\\\\\\\":0.4000000059604645}\\\\\\\",\\\\\\\"slots\\\\\\\":[]}\\\\n\\\",\\\"raw_query\\\":\\\"喂,您好\\\",\\\"sentiment_analysis\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"status\\\":0,\\\"timestamp\\\":0},\\\"schema\\\":{\\\"domain_confidence\\\":0.0,\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"slots\\\":[]},\\\"status\\\":0}],\\\"bernard_status\\\":[{\\\"index\\\":0,\\\"step\\\":\\\"AFTER_DM_TRIGGER\\\"}],\\\"intervention\\\":{\\\"interv_qu_res\\\":\\\"\\\",\\\"interv_query\\\":\\\"\\\",\\\"qu_res_interved\\\":\\\"\\\",\\\"qu_res_original\\\":\\\"\\\",\\\"query_original\\\":\\\"\\\",\\\"type\\\":\\\"\\\",\\\"user_id\\\":\\\"\\\"},\\\"user_slots\\\":{}},\\\"dialog_state\\\":{\\\"contexts\\\":{},\\\"intents\\\":[{\\\"index\\\":0,\\\"name\\\":\\\"INTENTION_1\\\"}],\\\"user_slots\\\":{}},\\\"interactions\\\":[{\\\"interaction_id\\\":\\\"interaction-1551319336305-707575714-8013-66\\\",\\\"request\\\":{\\\"bernard_level\\\":1,\\\"client_session\\\":\\\"{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"candidate_options\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":[],\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"client_results\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}\\\",\\\"hyper_params\\\":{\\\"slu_tags\\\":[]},\\\"query\\\":\\\"喂,您好\\\",\\\"query_info\\\":{\\\"asr_candidates\\\":[],\\\"source\\\":\\\"KEYBOARD\\\",\\\"type\\\":\\\"TEXT\\\"},\\\"updates\\\":\\\"\\\",\\\"user_id\\\":\\\"UNIT_WEB_37819\\\"},\\\"response\\\":{\\\"action_list\\\":[{\\\"action_id\\\":\\\"intention_1_satisfy\\\",\\\"confidence\\\":100.0,\\\"custom_reply\\\":\\\"\\\",\\\"refine_detail\\\":{\\\"clarify_reason\\\":\\\"\\\",\\\"interact\\\":\\\"\\\",\\\"option_list\\\":[]},\\\"say\\\":\\\"**先生/女士,您好!我是联通公司客户经理,工号:****,请问您是尾号XXXX机主吗?\\\",\\\"type\\\":\\\"satisfy\\\"}],\\\"msg\\\":\\\"ok\\\",\\\"qu_res\\\":{\\\"candidates\\\":[{\\\"confidence\\\":100.0,\\\"domain_confidence\\\":0.0,\\\"extra_info\\\":{\\\"group_id\\\":\\\"25\\\",\\\"real_threshold\\\":\\\"1\\\",\\\"threshold\\\":\\\"0.4\\\"},\\\"from_who\\\":\\\"pow-slu-lev1\\\",\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"intent_need_clarify\\\":false,\\\"match_info\\\":\\\"{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"id\\\\\\\":\\\\\\\"1958113\\\\\\\",\\\\\\\"informal_word\\\\\\\":\\\\\\\",\\\\\\\\t您好\\\\\\\",\\\\\\\"match_keywords\\\\\\\":\\\\\\\" \\\\\\\",\\\\\\\"match_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_slots\\\\\\\":{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{},\\\\\\\"from_who\\\\\\\":\\\\\\\"smart_qu\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"喂 \\\\\\\\t您好 \\\\\\\",\\\\\\\"slots\\\\\\\":[]},\\\\\\\"real_threshold\\\\\\\":1.0,\\\\\\\"threshold\\\\\\\":0.4000000059604645}\\\",\\\"slots\\\":[]}],\\\"lexical_analysis\\\":[{\\\"basic_word\\\":[\\\"喂\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"喂\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.4510},{\\\"basic_word\\\":[\\\",\\\"],\\\"etypes\\\":[],\\\"term\\\":\\\",\\\",\\\"type\\\":\\\"37\\\",\\\"weight\\\":0.0110},{\\\"basic_word\\\":[\\\"您好\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"您好\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.5360}],\\\"qu_res_chosen\\\":\\\"{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"real_threshold\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"threshold\\\\\\\":\\\\\\\"0.4\\\\\\\"},\\\\\\\"from_who\\\\\\\":\\\\\\\"pow-slu-lev1\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"group_id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"25\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"1958113\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"informal_word\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_keywords\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_slots\\\\\\\\\\\\\\\":{\\\\\\\\\\\\\\\"confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"domain_confidence\\\\\\\\\\\\\\\":0.0,\\\\\\\\\\\\\\\"extra_info\\\\\\\\\\\\\\\":{},\\\\\\\\\\\\\\\"from_who\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"smart_qu\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"INTENTION_1\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent_confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"intent_need_clarify\\\\\\\\\\\\\\\":false,\\\\\\\\\\\\\\\"match_info\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂 \\\\\\\\\\\\\\\\t您好 \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"slots\\\\\\\\\\\\\\\":[]},\\\\\\\\\\\\\\\"real_threshold\\\\\\\\\\\\\\\":1.0,\\\\\\\\\\\\\\\"threshold\\\\\\\\\\\\\\\":0.4000000059604645}\\\\\\\",\\\\\\\"slots\\\\\\\":[]}\\\\n\\\",\\\"raw_query\\\":\\\"喂,您好\\\",\\\"sentiment_analysis\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"status\\\":0,\\\"timestamp\\\":0},\\\"schema\\\":{\\\"domain_confidence\\\":0.0,\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"slots\\\":[]},\\\"status\\\":0},\\\"timestamp\\\":\\\"2019-02-28 10:02:16.305\\\"}],\\\"session_id\\\":\\\"session-155131933691-707575714-8013-18\\\"}\\n 参数有点长,这个参数是从上一轮返回的bot_session 中直接拷贝的,再次访问的时候报错: {"error_code":282004,"error_msg":"Parameter[bot_session] invalid or missing"}   请问这个问题有遇到么?
展开

多轮接口测试还真没有过。可以加我QQ  783021975 帮你试试。

0
#17四叶草1有星星回复于2019-02

在实现多伦对话的时候传入的bot_session 参数是:{\\\"bot_id\\\":\\\"37819\\\",\\\"bot_views\\\":{\\\"bernard_res\\\":[{\\\"action_list\\\":[{\\\"action_id\\\":\\\"\\\",\\\"confidence\\\":0.0,\\\"custom_reply\\\":\\\"\\\",\\\"refine_detail\\\":{\\\"clarify_reason\\\":\\\"\\\",\\\"interact\\\":\\\"\\\",\\\"option_list\\\":[]},\\\"say\\\":\\\"\\\",\\\"type\\\":\\\"understood\\\"}],\\\"msg\\\":\\\"ok\\\",\\\"pre_nlu_outs\\\":[{\\\"otags_basic\\\":[{\\\"blength\\\":2,\\\"boffset\\\":0,\\\"eid\\\":\\\"\\\",\\\"entity_confidence\\\":0.0,\\\"etype\\\":\\\"user_hello\\\",\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"father_fully_covered\\\":false,\\\"father_index\\\":-1,\\\"features\\\":[],\\\"formal\\\":\\\"\\\",\\\"formals\\\":[\\\"\\\"],\\\"length\\\":1,\\\"method\\\":\\\"[D:user_hello] == [D:user_hello]\\\",\\\"name\\\":\\\"喂\\\",\\\"offset\\\":0,\\\"rstatus\\\":2,\\\"type_confidence\\\":10.50},{\\\"blength\\\":4,\\\"boffset\\\":4,\\\"eid\\\":\\\"\\\",\\\"entity_confidence\\\":0.0,\\\"etype\\\":\\\"user_hello\\\",\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"father_fully_covered\\\":false,\\\"father_index\\\":-1,\\\"features\\\":[],\\\"formal\\\":\\\"\\\",\\\"formals\\\":[\\\"\\\"],\\\"length\\\":1,\\\"method\\\":\\\"[D:user_hello] == [D:user_hello]\\\",\\\"name\\\":\\\"您好\\\",\\\"offset\\\":2,\\\"rstatus\\\":2,\\\"type_confidence\\\":10.50}],\\\"otags_wpcomp\\\":[],\\\"polarity\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"tokens_basic\\\":[{\\\"buffer\\\":\\\"喂\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.9479930996894836,\\\"offset\\\":0,\\\"type\\\":34,\\\"weight\\\":0.4515353739261627},{\\\"buffer\\\":\\\",\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":2,\\\"type\\\":37,\\\"weight\\\":0.01189841516315937},{\\\"buffer\\\":\\\"您好\\\",\\\"length\\\":4,\\\"norm_degree\\\":0.0,\\\"offset\\\":4,\\\"type\\\":19,\\\"weight\\\":0.5365661978721619}],\\\"tokens_wpcomp\\\":[{\\\"buffer\\\":\\\"喂\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":0,\\\"type\\\":34,\\\"weight\\\":0.4515353739261627},{\\\"buffer\\\":\\\",\\\",\\\"length\\\":2,\\\"norm_degree\\\":0.0,\\\"offset\\\":1,\\\"type\\\":37,\\\"weight\\\":0.2317169010639191},{\\\"buffer\\\":\\\"您好\\\",\\\"length\\\":4,\\\"norm_degree\\\":0.0,\\\"offset\\\":2,\\\"type\\\":19,\\\"weight\\\":0.2801815271377563}]}],\\\"qu_res\\\":{\\\"candidates\\\":[{\\\"confidence\\\":100.0,\\\"domain_confidence\\\":0.0,\\\"extra_info\\\":{\\\"group_id\\\":\\\"25\\\",\\\"real_threshold\\\":\\\"1\\\",\\\"threshold\\\":\\\"0.4\\\"},\\\"from_who\\\":\\\"pow-slu-lev1\\\",\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"intent_need_clarify\\\":false,\\\"match_info\\\":\\\"{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"id\\\\\\\":\\\\\\\"1958113\\\\\\\",\\\\\\\"informal_word\\\\\\\":\\\\\\\",\\\\\\\\t您好\\\\\\\",\\\\\\\"match_keywords\\\\\\\":\\\\\\\" \\\\\\\",\\\\\\\"match_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_slots\\\\\\\":{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{},\\\\\\\"from_who\\\\\\\":\\\\\\\"smart_qu\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"喂 \\\\\\\\t您好 \\\\\\\",\\\\\\\"slots\\\\\\\":[]},\\\\\\\"real_threshold\\\\\\\":1.0,\\\\\\\"threshold\\\\\\\":0.4000000059604645}\\\",\\\"slots\\\":[]}],\\\"lexical_analysis\\\":[{\\\"basic_word\\\":[\\\"喂\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"喂\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.4510},{\\\"basic_word\\\":[\\\",\\\"],\\\"etypes\\\":[],\\\"term\\\":\\\",\\\",\\\"type\\\":\\\"37\\\",\\\"weight\\\":0.0110},{\\\"basic_word\\\":[\\\"您好\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"您好\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.5360}],\\\"qu_res_chosen\\\":\\\"{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"real_threshold\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"threshold\\\\\\\":\\\\\\\"0.4\\\\\\\"},\\\\\\\"from_who\\\\\\\":\\\\\\\"pow-slu-lev1\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"group_id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"25\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"1958113\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"informal_word\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_keywords\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_slots\\\\\\\\\\\\\\\":{\\\\\\\\\\\\\\\"confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"domain_confidence\\\\\\\\\\\\\\\":0.0,\\\\\\\\\\\\\\\"extra_info\\\\\\\\\\\\\\\":{},\\\\\\\\\\\\\\\"from_who\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"smart_qu\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"INTENTION_1\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent_confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"intent_need_clarify\\\\\\\\\\\\\\\":false,\\\\\\\\\\\\\\\"match_info\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂 \\\\\\\\\\\\\\\\t您好 \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"slots\\\\\\\\\\\\\\\":[]},\\\\\\\\\\\\\\\"real_threshold\\\\\\\\\\\\\\\":1.0,\\\\\\\\\\\\\\\"threshold\\\\\\\\\\\\\\\":0.4000000059604645}\\\\\\\",\\\\\\\"slots\\\\\\\":[]}\\\\n\\\",\\\"raw_query\\\":\\\"喂,您好\\\",\\\"sentiment_analysis\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"status\\\":0,\\\"timestamp\\\":0},\\\"schema\\\":{\\\"domain_confidence\\\":0.0,\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"slots\\\":[]},\\\"status\\\":0}],\\\"bernard_status\\\":[{\\\"index\\\":0,\\\"step\\\":\\\"AFTER_DM_TRIGGER\\\"}],\\\"intervention\\\":{\\\"interv_qu_res\\\":\\\"\\\",\\\"interv_query\\\":\\\"\\\",\\\"qu_res_interved\\\":\\\"\\\",\\\"qu_res_original\\\":\\\"\\\",\\\"query_original\\\":\\\"\\\",\\\"type\\\":\\\"\\\",\\\"user_id\\\":\\\"\\\"},\\\"user_slots\\\":{}},\\\"dialog_state\\\":{\\\"contexts\\\":{},\\\"intents\\\":[{\\\"index\\\":0,\\\"name\\\":\\\"INTENTION_1\\\"}],\\\"user_slots\\\":{}},\\\"interactions\\\":[{\\\"interaction_id\\\":\\\"interaction-1551319336305-707575714-8013-66\\\",\\\"request\\\":{\\\"bernard_level\\\":1,\\\"client_session\\\":\\\"{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"candidate_options\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":[],\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"client_results\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"}\\\",\\\"hyper_params\\\":{\\\"slu_tags\\\":[]},\\\"query\\\":\\\"喂,您好\\\",\\\"query_info\\\":{\\\"asr_candidates\\\":[],\\\"source\\\":\\\"KEYBOARD\\\",\\\"type\\\":\\\"TEXT\\\"},\\\"updates\\\":\\\"\\\",\\\"user_id\\\":\\\"UNIT_WEB_37819\\\"},\\\"response\\\":{\\\"action_list\\\":[{\\\"action_id\\\":\\\"intention_1_satisfy\\\",\\\"confidence\\\":100.0,\\\"custom_reply\\\":\\\"\\\",\\\"refine_detail\\\":{\\\"clarify_reason\\\":\\\"\\\",\\\"interact\\\":\\\"\\\",\\\"option_list\\\":[]},\\\"say\\\":\\\"**先生/女士,您好!我是联通公司客户经理,工号:****,请问您是尾号XXXX机主吗?\\\",\\\"type\\\":\\\"satisfy\\\"}],\\\"msg\\\":\\\"ok\\\",\\\"qu_res\\\":{\\\"candidates\\\":[{\\\"confidence\\\":100.0,\\\"domain_confidence\\\":0.0,\\\"extra_info\\\":{\\\"group_id\\\":\\\"25\\\",\\\"real_threshold\\\":\\\"1\\\",\\\"threshold\\\":\\\"0.4\\\"},\\\"from_who\\\":\\\"pow-slu-lev1\\\",\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"intent_need_clarify\\\":false,\\\"match_info\\\":\\\"{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"id\\\\\\\":\\\\\\\"1958113\\\\\\\",\\\\\\\"informal_word\\\\\\\":\\\\\\\",\\\\\\\\t您好\\\\\\\",\\\\\\\"match_keywords\\\\\\\":\\\\\\\" \\\\\\\",\\\\\\\"match_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_pattern\\\\\\\":\\\\\\\"喂\\\\\\\\t您好\\\\\\\",\\\\\\\"ori_slots\\\\\\\":{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{},\\\\\\\"from_who\\\\\\\":\\\\\\\"smart_qu\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"喂 \\\\\\\\t您好 \\\\\\\",\\\\\\\"slots\\\\\\\":[]},\\\\\\\"real_threshold\\\\\\\":1.0,\\\\\\\"threshold\\\\\\\":0.4000000059604645}\\\",\\\"slots\\\":[]}],\\\"lexical_analysis\\\":[{\\\"basic_word\\\":[\\\"喂\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"喂\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.4510},{\\\"basic_word\\\":[\\\",\\\"],\\\"etypes\\\":[],\\\"term\\\":\\\",\\\",\\\"type\\\":\\\"37\\\",\\\"weight\\\":0.0110},{\\\"basic_word\\\":[\\\"您好\\\"],\\\"etypes\\\":[\\\"[D:user_hello]\\\"],\\\"term\\\":\\\"您好\\\",\\\"type\\\":\\\"user_hello\\\",\\\"weight\\\":0.5360}],\\\"qu_res_chosen\\\":\\\"{\\\\\\\"confidence\\\\\\\":100.0,\\\\\\\"domain_confidence\\\\\\\":0.0,\\\\\\\"extra_info\\\\\\\":{\\\\\\\"group_id\\\\\\\":\\\\\\\"25\\\\\\\",\\\\\\\"real_threshold\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"threshold\\\\\\\":\\\\\\\"0.4\\\\\\\"},\\\\\\\"from_who\\\\\\\":\\\\\\\"pow-slu-lev1\\\\\\\",\\\\\\\"intent\\\\\\\":\\\\\\\"INTENTION_1\\\\\\\",\\\\\\\"intent_confidence\\\\\\\":100.0,\\\\\\\"intent_need_clarify\\\\\\\":false,\\\\\\\"match_info\\\\\\\":\\\\\\\"{\\\\\\\\\\\\\\\"group_id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"25\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"id\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"1958113\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"informal_word\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_keywords\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\" \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"match_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_pattern\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂\\\\\\\\\\\\\\\\t您好\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"ori_slots\\\\\\\\\\\\\\\":{\\\\\\\\\\\\\\\"confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"domain_confidence\\\\\\\\\\\\\\\":0.0,\\\\\\\\\\\\\\\"extra_info\\\\\\\\\\\\\\\":{},\\\\\\\\\\\\\\\"from_who\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"smart_qu\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"INTENTION_1\\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"intent_confidence\\\\\\\\\\\\\\\":100.0,\\\\\\\\\\\\\\\"intent_need_clarify\\\\\\\\\\\\\\\":false,\\\\\\\\\\\\\\\"match_info\\\\\\\\\\\\\\\":\\\\\\\\\\\\\\\"喂 \\\\\\\\\\\\\\\\t您好 \\\\\\\\\\\\\\\",\\\\\\\\\\\\\\\"slots\\\\\\\\\\\\\\\":[]},\\\\\\\\\\\\\\\"real_threshold\\\\\\\\\\\\\\\":1.0,\\\\\\\\\\\\\\\"threshold\\\\\\\\\\\\\\\":0.4000000059604645}\\\\\\\",\\\\\\\"slots\\\\\\\":[]}\\\\n\\\",\\\"raw_query\\\":\\\"喂,您好\\\",\\\"sentiment_analysis\\\":{\\\"label\\\":\\\"1\\\",\\\"pval\\\":0.9970},\\\"status\\\":0,\\\"timestamp\\\":0},\\\"schema\\\":{\\\"domain_confidence\\\":0.0,\\\"intent\\\":\\\"INTENTION_1\\\",\\\"intent_confidence\\\":100.0,\\\"slots\\\":[]},\\\"status\\\":0},\\\"timestamp\\\":\\\"2019-02-28 10:02:16.305\\\"}],\\\"session_id\\\":\\\"session-155131933691-707575714-8013-18\\\"}\\n

参数有点长,这个参数是从上一轮返回的bot_session 中直接拷贝的,再次访问的时候报错:

{"error_code":282004,"error_msg":"Parameter[bot_session] invalid or missing"}

 

请问这个问题有遇到么?

0
#16用户已被禁言回复于2018-09
#15 NC聂C回复
请问在调用HttpUtil时,有这个错误W/System: ClassLoader referenced unknown path: /data/app/com.example.jacknie.kirin-1/lib/x86 该怎么处理呢?
展开

你这是Java语言吗?

接口错误都是json格式的字符串哦

1
#15NC聂C回复于2018-09

请问在调用HttpUtil时,有这个错误W/System: ClassLoader referenced unknown path: /data/app/com.example.jacknie.kirin-1/lib/x86

该怎么处理呢?

0
#14tiancorn回复于2018-09
#13 用户已被禁言回复
每次请求会有bot_session  麻烦你仔细看一下文档说明

你看你调用的模型是什么时候训练的,最新的训练策略对应的模型已经把这个必填改为了可选。可以先训练一下。稍后我们做一下兼容处理。

0
#13用户已被禁言回复于2018-08
#12 Test卖咸鱼回复
连续的多轮对话怎么调接口呢

每次请求会有bot_session  麻烦你仔细看一下文档说明

1
#12Test卖咸鱼回复于2018-08

连续的多轮对话怎么调接口呢

0
#11用户已被禁言回复于2018-08
#10 NC聂C回复
添加package com.baidu.ai.aip.utils;之后出现错误,提示Package name does not correspond to the file path...... 请问该怎么解决呢?
展开

不明白。我的代码引入所需要的工具类 第三方jar都给出去下载地址了。

1
#10NC聂C回复于2018-08

添加package com.baidu.ai.aip.utils;之后出现错误,提示Package name does not correspond to the file path......

请问该怎么解决呢?

0
#9mxw2552261回复于2018-08

Good

0
#8用户已被禁言回复于2018-08
#6 晚自习的星空回复
想请问一下,调用API接口后,bot对话框是自动生成的吗?需不需要自己构建对话框?
展开

接口只是功能。业务层UI层 和接口没直接关系的

1
#7tiancorn回复于2018-08
#6 晚自习的星空回复
想请问一下,调用API接口后,bot对话框是自动生成的吗?需不需要自己构建对话框?
展开

不是的,要自己弄

0
#6晚自习的星空回复于2018-08

想请问一下,调用API接口后,bot对话框是自动生成的吗?需不需要自己构建对话框?

0
#5伯爵囧rz回复于2018-08

谢谢

0
#4ie421回复于2018-08

很不错

0
#3伊茨米可回复于2018-07

感谢小帅分享~~

0
TOP
切换版块