一、申请——腾讯智能对话平台

1.1 企业申请公测

image.png

1.2查询获取 BotId : 867ea6d8-a2d9-4d7f-8e50-f2a45d4f0873

image.png

1.3获取应用SDKAppID: 1400582896

image.png

1.4 机器人绑定应用SDKAppID

1.5发布上线

image.png

二、使用

可参考官网Api——SDK开发文档: https://cloud.tencent.com/document/api/1060/37438

1.1导入依赖(在业务层)

  1. <dependency>
  2. <groupId>com.tencentcloudapi</groupId>
  3. <artifactId>tencentcloud-sdk-java</artifactId>
  4. <version>3.1.322</version>
  5. </dependency>

1.2测试代码

  1. package xyz.ytcloud.core.utils;
  2. import com.tencentcloudapi.common.Credential;
  3. import com.tencentcloudapi.common.profile.ClientProfile;
  4. import com.tencentcloudapi.common.profile.HttpProfile;
  5. import com.tencentcloudapi.common.exception.TencentCloudSDKException;
  6. import com.tencentcloudapi.tbp.v20190627.TbpClient;
  7. import com.tencentcloudapi.tbp.v20190627.models.*;
  8. public class TencentAl {
  9. public static void main(String[] args) {
  10. try {
  11. Credential cred = new Credential("AKIDiAPRPExObXBZoxFr0tBED0ayDDwc7nLq", "vc2MsEQZVffZMEpxoPwiIcgYFfuzmIft");
  12. HttpProfile httpProfile = new HttpProfile();
  13. httpProfile.setEndpoint("tbp.tencentcloudapi.com");
  14. ClientProfile clientProfile = new ClientProfile();
  15. clientProfile.setHttpProfile(httpProfile);
  16. TbpClient client = new TbpClient(cred, "", clientProfile);
  17. TextProcessRequest req = new TextProcessRequest();
  18. req.setBotId("867ea6d8-a2d9-4d7f-8e50-f2a45d4f0873");
  19. req.setBotEnv("release");
  20. req.setTerminalId("1");
  21. req.setInputText("今天天气太热了"); //传参
  22. TextProcessResponse resp = client.TextProcess(req);
  23. // 输出json格式的字符串回包
  24. System.out.println(TextProcessResponse.toJsonString(resp)); //测试结果打印
  25. } catch (TencentCloudSDKException e) {
  26. System.out.println(e.toString());
  27. }
  28. }
  29. }

2.3测试

image.png

2.4封装工具类

  1. package xyz.ytcloud.core.utils;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.tencentcloudapi.common.Credential;
  5. import com.tencentcloudapi.common.profile.ClientProfile;
  6. import com.tencentcloudapi.common.profile.HttpProfile;
  7. import com.tencentcloudapi.common.exception.TencentCloudSDKException;
  8. import com.tencentcloudapi.tbp.v20190627.TbpClient;
  9. import com.tencentcloudapi.tbp.v20190627.models.*;
  10. import xyz.ytcloud.common.config.SystemConfig;
  11. public class TencentAlUtils {
  12. public static TextProcessRequest req;
  13. public static TbpClient client;
  14. static {
  15. Credential cred = new Credential(SystemConfig.TENCENT_SECRETID, SystemConfig.TENCENT_SECRETKEY);
  16. HttpProfile httpProfile = new HttpProfile();
  17. httpProfile.setEndpoint(SystemConfig.TENCENT_Endpoint);
  18. ClientProfile clientProfile = new ClientProfile();
  19. clientProfile.setHttpProfile(httpProfile);
  20. client = new TbpClient(cred,"", clientProfile);
  21. req = new TextProcessRequest();
  22. req.setBotId(SystemConfig.TENCENT_BotId);
  23. req.setBotEnv(SystemConfig.TENCENT_BotEnv);
  24. req.setTerminalId(SystemConfig.TENCENT_TerminalId);
  25. }
  26. public static JSONArray getAlContext(String context) {
  27. try {
  28. req.setInputText(context);
  29. TextProcessResponse resp = client.TextProcess(req);
  30. return JSONObject.parseArray("["+TextProcessResponse.toJsonString(resp)+"]");
  31. }
  32. catch (TencentCloudSDKException e) {
  33. System.out.println(e.toString());
  34. }
  35. return null;
  36. }
  37. }

常量

image.png

  1. /**
  2. * 腾讯云
  3. */
  4. public static final String TENCENT_SECRETID = "AKIDiAPRPExObXBZoxFr0tBED0ayDDwc7nLq";
  5. public static final String TENCENT_SECRETKEY = "vc2MsEQZVffZMEpxoPwiIcgYFfuzmIft";
  6. public static final String TENCENT_BotId="867ea6d8-a2d9-4d7f-8e50-f2a45d4f0873";
  7. public static final String TENCENT_Endpoint="tbp.tencentcloudapi.com";
  8. public static final String TENCENT_BotEnv="release";
  9. public static final String TENCENT_TerminalId="1";

2.5 TencentAlService

  1. package xyz.ytcloud.core.manager.intf;
  2. import xyz.ytcloud.common.vo.R;
  3. public interface TencentAlService {
  4. R getAlContext(String context);
  5. }

2.6 TencentAlServiceImpl

  1. package xyz.ytcloud.core.manager.impl;
  2. import org.springframework.stereotype.Service;
  3. import xyz.ytcloud.common.utils.RUtils;
  4. import xyz.ytcloud.common.vo.R;
  5. import xyz.ytcloud.core.manager.intf.TencentAlService;
  6. import xyz.ytcloud.core.utils.TencentAlUtils;
  7. @Service
  8. public class TencentAlServiceImpl implements TencentAlService {
  9. @Override
  10. public R getAlContext(String context) {
  11. return RUtils.ok("ok",TencentAlUtils.getAlContext(context));
  12. }
  13. }

2.7 TencentAlController

  1. package xyz.ytcloud.as.api.controller;
  2. import io.swagger.annotations.Api;
  3. import io.swagger.annotations.ApiOperation;
  4. import org.springframework.web.bind.annotation.*;
  5. import xyz.ytcloud.common.utils.RUtils;
  6. import xyz.ytcloud.common.vo.R;
  7. import xyz.ytcloud.core.utils.TencentAlUtils;
  8. @RestController
  9. @RequestMapping("/api/send")
  10. @Api(value = "人工智能机器人",tags = "人工智能机器人")
  11. public class TencentAlController {
  12. @GetMapping("/alContext")
  13. @ApiOperation(value = "获取Al回复内容",notes = "获取Al回复内容")
  14. public R getAlContext(String context){
  15. return RUtils.ok("ok", TencentAlUtils.getAlContext(context));
  16. }
  17. }

2.8测试接口

image.png

2.9Vue代码

  1. <template>
  2. <div>
  3. <div>
  4. <van-nav-bar
  5. left-text="返回"
  6. left-arrow
  7. @click-left="onClickLeft"
  8. >
  9. <template #right>
  10. <van-cell is-link @click="showPopup">
  11. <van-icon
  12. name="phone-o"
  13. size="18"
  14. />
  15. </van-cell>
  16. </template>
  17. </van-nav-bar>
  18. </div>
  19. <div>
  20. <van-notice-bar scrollable
  21. text="亲爱的用户,骑士小哥哥们正在路上全力奔波呢~不过当前订单量较多,如果餐品出现延后到达的情况,小布谷先跟您说声对不起,耽误您的用餐了~不过希望您能再给骑士小哥哥们一些时间,小布谷替他们感谢您的理解与支持~"/>
  22. </div>
  23. <div>
  24. <div class="talk_con">
  25. <div class="talk_show" id="words">
  26. <div :class="[(i.person=='A')?'atalk':'btalk']" v-for="i in list1">
  27. <div :style=i.sty01>
  28. <span style="color: blueviolet;font-size: 20px">{{ i.say }}</span>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="talk_input" style="margin-top: 400px;text-align: center">
  33. <input type="text" class="talk_word" id="talkwords" v-model="text1">
  34. <!-- 绑定单击监听,把value传到vuelist1 -->
  35. <input type="button" value="发送" class="talk_sub" id="talksub" @click="fnAdd">
  36. </div>
  37. </div>
  38. </div>
  39. <van-popup closeable v-model:show="show" position="bottom" :style="{ height: '30%' }">
  40. <van-button style="margin-top: 100px;margin-right: 100px;width:110px;height: 100px" icon="">
  41. <van-icon size="50px" name="phone-o">
  42. <div style="font-size: 10px">客服热线</div>
  43. </van-icon>
  44. </van-button>
  45. <van-button style="width:110px;height: 100px">
  46. <van-icon size="50px" name="phone">
  47. <div style="font-size: 10px">网络客服电话</div>
  48. </van-icon>
  49. </van-button>
  50. </van-popup>
  51. </div>
  52. </template>
  53. <script>
  54. import {ref} from 'vue';
  55. export default {
  56. setup() {
  57. const onClickLeft = () => history.back();
  58. const show = ref(false);
  59. const showPopup = () => {
  60. show.value = true;
  61. };
  62. return {
  63. onClickLeft,
  64. show,
  65. showPopup,
  66. };
  67. }, mounted() {
  68. this.$dialog.alert({
  69. message: '亲爱的用户,骑士小哥哥们正在路上全力奔波呢~不过当前订单量较多,如果餐品出现延后到达的情况,小布谷先跟您说声对不起,耽误您的用餐了~不过希望您能再给骑士小哥哥们一些时间,小布谷替他们感谢您的理解与支持~',
  70. });
  71. },
  72. data() {
  73. return {
  74. list1: [
  75. {
  76. person: '我',
  77. say: '',
  78. sty01: 'text-align:right;margin-right:40px',
  79. },
  80. {
  81. person: '客服007',
  82. say: '',
  83. sty01: 'text-align:left;margin-left:40px',
  84. },
  85. ],
  86. sel1: 0,
  87. text1: '',
  88. text2: '666',
  89. index: 0,
  90. aaaaaa: '',
  91. }
  92. },
  93. methods: {
  94. fnAdd() {
  95. if (this.text1 == '') {
  96. alert("请输入内容!");
  97. return;
  98. }
  99. // 列表追加数据push()
  100. // this.list1.push({person: (this.sel1 == 0) ? '我' : 'B', say1: this.text1});
  101. this.list1.push({person: '我', say: this.text1, sty01: 'text-align:right;margin-right:40px'});
  102. //请求后端接口,获取智能对话信息
  103. this.axios.get("send/alContext?context=" + this.text1).then((res) => {
  104. this.text2 = res.data.data[0].ResponseMessage.GroupList[0].Content;
  105. // 每次输入内容后,清空输入栏数据
  106. //将人工智能消息存入
  107. this.list1.push({person: '客服007', say: this.text2, sty01: 'text-align:left;margin-left:40px'});
  108. })
  109. this.text1 = '';
  110. },
  111. }
  112. };
  113. </script>
  114. <style scoped>
  115. </style>

3.0测试功能

image.png

企业实名公测,无次数限制,并发吞吐量500次/秒(同一秒可以500人同时发起请求,不会有延迟)

三、使用范围

API接口调用、微信公众号、微信小程序、Web服务器、腾讯小微 都可以使用。
具体方法参见官方API——SDK开发文档 https://cloud.tencent.com/document/api/1060/37438
image.png

四、开发者大会—孙栎倩

4.1人工智能自定义参数配置

11.6机器人实践.pptx
https://www.yuque.com/office/yuque/0/2021/pptx/22619330/1635685364249-4bca8f3f-a715-452d-8bdf-175cc8c25bb8.pptx?from=https%3A%2F%2Fwww.yuque.com%2Fdocs%2Fshare%2F19ec6723-2a35-4655-bd6d-b6326a261010