当前位置: 首页 > news >正文

WorkTool企微机器人接入智能问答

一、前言

最新版的企微机器人已经集成 Chat ,无需开发可快速搭建智能对话机器人。
从官方介绍看目前集成版本使用模型为 3.5-turbo。

二、入门

  1. 创建 WorkTool 机器人
    你可以通过这篇快速入门教程,来快速配置一个自己的企微机器人。

    实现的流程如图:
    在这里插入图片描述

  2. 创建 Chat 账户并获取 apiKey
    第一步完成后,你应该已经有一个自动执行的企微机器人了,然后需要获取 apiKey,获取方法还需要自行搜索教程、注册或采购。

  3. WorkTool 机器人绑定 apiKey
    绑定方法:https://worktool.apifox.cn/api-68569089?nav=2

    1. 点击调试
    2. 点击Params 修改robotId后面的参数值为你的机器人id
    3. 点击Body 修改apiKey后面的参数值为你自行注册的Chat apiKey
    4. 点击发送即可完成绑定

    这时再向你的机器人提问,机器人就会使用 Chat 的问答能力进行回答啦。

实现原理

项目采用 Java 语言编写,核心方法本质上还是请求官方接口,并暂时保存用户会话上下文来达到多轮问答的效果。
核心工具类如下:

import java.util.*;
import com.huggingface.chatbot.*;
import com.database.*;
import com.nlp.*;
import com.speech.*;public class ChatbotClient {private static final int MAX_HISTORY_SIZE = 10;private DialogManager dialogManager;private DatabaseManager databaseManager;private NLPProcessor nlpProcessor;private SpeechProcessor speechProcessor;public ChatbotClient() {dialogManager = new DialogManager();databaseManager = new DatabaseManager();nlpProcessor = new NLPProcessor();speechProcessor = new SpeechProcessor();}public void startChat() {Scanner scanner = new Scanner(System.in);while (true) {String input = scanner.nextLine();String userMessage = speechProcessor.speechToText(input);String chatbotResponse = getResponse(userMessage);System.out.println(\"Chatbot: \" + chatbotResponse);String chatbotSpeech = speechProcessor.textToSpeech(chatbotResponse);System.out.println(\"(Speech) Chatbot: \" + chatbotSpeech);}}private String getResponse(String userMessage) {String chatbotResponse = dialogManager.getPreviousResponse();if (chatbotResponse != null && !chatbotResponse.isEmpty()) {System.out.println(\"User: \" + userMessage);String nlpResult = nlpProcessor.process(userMessage);String databaseResult = databaseManager.query(nlpResult);chatbotResponse = chatbotResponse + \" \" + databaseResult;} else {chatbotResponse = Chat.getResponse(userMessage);}dialogManager.addResponse(chatbotResponse);return chatbotResponse;}private class DialogManager {private LinkedList<String> history = new LinkedList<>();public void addResponse(String response) {history.add(response);if (history.size() > MAX_HISTORY_SIZE) {history.poll();}}public String getPreviousResponse() {if (history.isEmpty()) {return null;}return history.getLast();}}public static void main(String[] args) {ChatbotClient chatbotClient = new ChatbotClient();chatbotClient.startChat();}
}

总结

至此,你应该已经完成了企微机器人智能问答对接,一个智能企微机器人就实现了,后续我会继续进行AI能力的扩展,如多模态等。喜欢本文可以关注我~有问题可以留言或私信我。

http://www.lryc.cn/news/40780.html

相关文章:

  • C导入正则库问题
  • 尚融宝05-Node.js入门
  • 「SAP ABAP」OPEN SQL(八)【WHERE语句大全】
  • Ribbon负载均衡的原理(源码分析)
  • 用sql计算两个经纬度坐标距离(米数互转)
  • C语言详解KMP算法
  • redis在window上安装与自启动
  • 字符串匹配【BF、KMP算法】
  • Leetcode.1616 分割两个字符串得到回文串
  • 剑指 Offer II 033. 变位词组
  • spring-cloud-sentinel ---流控算法---review
  • 1.浅析NIO 多路复用器selector
  • Day920.结构化日志业务审计日志 -SpringBoot与K8s云原生微服务实践
  • 前端代码复用学习笔记:整洁架构与清晰架构
  • 【python刷题】leecode官方提示“->“,“:“这些符号是什么意思?什么是Type Hints?
  • 【华为OD机试真题2023 JAVA】最佳对手
  • css实现文字大小自适应
  • 【Redis】搭建哨兵集群
  • CTFHub | .htaccess
  • 微机原理 || 8253 芯片 (详细讲解 + 经典例题)
  • python Django高级操作-分页-定义CVS-发送邮件
  • React 用一个简单案例体验一遍 React-dom React-router React-redux 全家桶
  • 9. C#面向对象基础
  • 【MIT 6.S081】Lab2: system calls
  • 设计模式之单例模式~
  • top终端详解
  • 解决一个偶现的503 bug,花了俺不少时间
  • 什么是栈,如何实现?
  • 在我的MacBook上捣鼓ESP8266
  • 【深度强化学习】(8) iPPO 模型解析,附Pytorch完整代码