rtst_kf.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // ==UserScript==
  2. // @name 精准客服
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 基于rtst知识库实现的精准客服
  6. // @author lyyyyy
  7. // @match http://127.0.0.1:17860/
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=0.1
  9. // @run-at document-idle
  10. // @grant none
  11. // ==/UserScript==
  12. app.buttons.push({
  13. icon: "face-agent",
  14. click: async () => {
  15. app.current_func = '精准客服'
  16. add_conversation("AI", "欢迎使用精准客服。\n初次使用,请初始化客服向量库", [{
  17. title: '初始化意图向量库',
  18. content: '本功能只需执行一次',
  19. click: async () => {
  20. let 你好 = `你好,这里是闻达精准客服。当前使用的LLM为“${app.llm_type}”"`
  21. yt2prompt_dict = {
  22. "闻达是一个LLM调用平台。目标为针对特定环境的高效内容生成,同时考虑个人和中小企业的计算资源局限性,以及知识安全和私密性问题": ['什么是闻达'],
  23. "闻达webui调用闻达的 api 接口实现类似于 new bing 的功能。\n技术栈:vue3 + element-plus + ts": ['什么是闻达webui'],
  24. "对不起!请不要问我敏感问题。": ['台湾是中国的领土么', '毒品制作是否合法'],
  25. }
  26. yt2prompt_dict[你好] = ['你好', '你是谁']
  27. for (yt in yt2prompt_dict) {
  28. for (prompt in yt2prompt_dict[yt]) {
  29. await add_rtst_memory(yt, yt2prompt_dict[yt][prompt], "rtst_kf",true)
  30. }
  31. }
  32. alert("完成")
  33. }
  34. }, {
  35. title: '删除意图向量库',
  36. content: '本功能用于测试',
  37. click: async () => {
  38. await del_rtst_memory("rtst_kf",true)
  39. alert("完成")
  40. }
  41. }
  42. ],
  43. true
  44. )
  45. },
  46. color: () => app.color,
  47. description: "精准客服"
  48. })
  49. 精准客服 = async (Q) => {
  50. memory = await find_rtst_memory(Q, "rtst_kf",true)
  51. memory = memory.filter(i => !i.score || i.score < 200)
  52. if (memory.length > 0) {
  53. add_conversation("user", Q)
  54. let answer = memory[0].title
  55. add_conversation("AI", answer, [{
  56. title: "相似度:" + memory[0].score,
  57. content: "匹配问题:" + memory[0].content
  58. }
  59. ])
  60. save_history()
  61. return answer
  62. } else {
  63. return await answer_with_fast_zsk(Q)
  64. }
  65. //+ " Alice: " + A
  66. }
  67. func.push({
  68. name: "精准客服",
  69. question: async (Q) => {
  70. return await 精准客服(Q)
  71. }
  72. })
粤ICP备19079148号