ytsb.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // ==UserScript==
  2. // @name 意图识别
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description
  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: "multicast",
  14. click: async () => {
  15. app.current_func = '意图识别(GLM3)'
  16. },
  17. color: () => app.color,
  18. description: "意图识别(GLM3)"
  19. })
  20. app.buttons.push({
  21. icon: "multicast",
  22. click: async () => {
  23. app.chat = []
  24. app.current_func = '意图识别'
  25. add_conversation("AI", "欢迎使用意图识别,初次使用,请初始化意图向量库", [{
  26. title: '初始化意图向量库',
  27. content: '本功能只需执行一次',
  28. click: async () => {
  29. yt2prompt_dict = {
  30. 快速知识库: ['为什么', '我想问一下', '什么是'],
  31. 中文绘图: ['帮我画一张', '画一个'],
  32. 提问助手: ['请对会议内容提问', '对于上一个回答,你有那些疑问', '帮我提出几个有建设性的问题'],
  33. }
  34. for (yt in yt2prompt_dict) {
  35. for (prompt in yt2prompt_dict[yt]) {
  36. await add_rtst_memory(yt, yt2prompt_dict[yt][prompt], "_ytsb")
  37. }
  38. }
  39. alert("初始化完成")
  40. }
  41. }, {
  42. title: '删除意图向量库',
  43. content: '本功能用于测试',
  44. click: async () => {
  45. await del_rtst_memory("_ytsb")
  46. alert("删除完成")
  47. }
  48. }
  49. ],
  50. true
  51. )
  52. },
  53. color: () => app.color,
  54. description: "意图识别"
  55. })
  56. func.push({
  57. name: "意图识别",
  58. question: async () => {
  59. Q = app.question
  60. memory = await find_rtst_memory(Q, "_ytsb")
  61. if (memory.length > 0) {
  62. add_conversation("AI", '识别到意图为:' + memory[0].title + ",正在调用相应auto")
  63. // A = await send(app.question )
  64. let 当前_auot = app.func_menu.find((i) => i.name == memory[0].title)
  65. if (typeof 当前_auot.question == "function") {
  66. 当前_auot.question();
  67. } else {
  68. let Q = app.question
  69. await send(当前_auot.question + Q, Q);
  70. app.question = ''
  71. }
  72. // app.func_menu.find((i) => i.name == memory[0].title).question(Q)
  73. } else {
  74. A = await send(app.question)
  75. }
  76. //+ " Alice: " + A
  77. },
  78. })
  79. func.push({
  80. name: "意图识别(GLM3)",
  81. question: async () => {
  82. Q = app.question
  83. tools = [
  84. {
  85. "name": "ytsb",
  86. "description": `用户意图识别`,
  87. "parameters": {
  88. "type": "object",
  89. "properties": {
  90. "yt": {
  91. "description": `从列表["画图","提问","写论文","其他"]中选择用户意图`
  92. },
  93. "text": {
  94. "description": `用户意图对应的主题,如,用户输入画一只狗,应返回"狗"`
  95. },
  96. },
  97. "required": ['yt', "text"]
  98. }
  99. }
  100. ]
  101. r = await send_raw(Q, '', [
  102. {
  103. "role": "system",
  104. "content": JSON.stringify(tools),
  105. },
  106. ], (s) => { },
  107. )
  108. r = (JSON.parse(r)).parameters
  109. app.question=r.text
  110. alert('识别到意图为:' + r.yt + ',主题为:' + r.text + ",正在调用相应auto")
  111. yt = ({ "画图": '中文绘图', "提问": '快速知识库', "写论文": '根据标题写论文', "其他": '' })[r.yt]
  112. let 当前_auot = app.func_menu.find((i) => i.name == yt)
  113. if (typeof 当前_auot.question == "function") {
  114. 当前_auot.question(r.text);
  115. } else {
  116. let Q = app.question
  117. await send(当前_auot.question + Q, Q);
  118. app.question = ''
  119. }
  120. // app.func_menu.find((i) => i.name == memory[0].title).question(Q)
  121. //+ " Alice: " + A
  122. },
  123. })
粤ICP备19079148号