wdss.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <html>
  2. <head>
  3. <title>闻达搜索</title>
  4. <meta charset="utf-8">
  5. <meta name="apple-mobile-web-app-capable" content="yes" />
  6. <meta name="mobile-web-app-capable" content="yes" />
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  8. <meta name="viewport" content="width=650, user-scalable=no">
  9. <link rel="shortcut icon" href="#" />
  10. <link href="/static/mdi_font/css/materialdesignicons.min.css" rel="stylesheet">
  11. <link href="/static/vuetify.min.css" rel="stylesheet">
  12. <script src="/static/vue.js"></script>
  13. <script src="/static/vuetify.min.js"></script>
  14. <script src="/static/markdown-it.min.js"></script>
  15. <style>
  16. div {
  17. transition: all 0.3s;
  18. }
  19. .v-sheet.v-card {
  20. margin: 20px;
  21. padding: 10px;
  22. }
  23. .logo-center {
  24. left: calc(50% - 140px);
  25. width: 260px;
  26. font-size: 4em;
  27. padding-top: 2.5em;
  28. padding-bottom: 0.8em;
  29. position: relative;
  30. }
  31. .logo-left {
  32. left: 20px;
  33. width: 100%;
  34. font-size: xx-large;
  35. position: relative;
  36. }
  37. .input-box {
  38. margin: auto;
  39. width: fit-content;
  40. min-width: 580px;
  41. }
  42. pre {
  43. margin: 20px;
  44. white-space: break-spaces;
  45. }
  46. .v-application--wrap {
  47. display: unset;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="app" v-cloak>
  53. <v-app>
  54. <v-combobox multiple small-chips dense hide-details="auto" v-model="s查询参数"
  55. outlined label="知识库" class="ma-2"
  56. :items="items"></v-combobox>
  57. <a style="float: right;" href="/static/st.html">资料管理</a>
  58. <div :class="(s关键词.length!=0||results.length!=0)?'logo-left':'logo-center'"><b
  59. style="color: purple;">闻达</b><b>搜索</b></div>
  60. <v-row class="input-box">
  61. <v-col cols="10">
  62. <v-textarea autofocus v-model="s关键词" label="关键词" no-resize rows="1"
  63. hide-details="auto"
  64. @keypress.enter="submit"></v-textarea>
  65. </v-col>
  66. <v-col cols="2">
  67. <v-btn color="purple" dark size="x-large" @click="submit()">
  68. 搜索
  69. </v-btn>
  70. </v-col>
  71. </v-row>
  72. <v-card v-ripple elevation="2" v-if="s回答.length">
  73. <pre>{{s回答}}</pre>
  74. </v-card>
  75. <v-card v-ripple elevation="2" v-for="result in results"
  76. @click.stop='result.url&&window.open(result.url,"_blank")'>
  77. <v-card-title>{{result.title}}<v-chip class="ma-2"
  78. :color="result.score>i分数阈值?'green':'red'"
  79. text-color="white" v-text="result.score" v-if="result.score!=undefined"></v-chip></v-card-title>
  80. <v-divider></v-divider>
  81. <v-card-text v-text="result.content">
  82. </v-card>
  83. <v-snackbar v-model="b显示提示文本" :timeout="3000" style="white-space: pre-line">{{s提示文本}}</v-snackbar>
  84. </v-app>
  85. </div>
  86. <script>
  87. items = [
  88. 'calc:50',
  89. 'serper:50',
  90. 'sogowx:50',
  91. ]
  92. f读取现有库 = async () => {
  93. response = await fetch("/api/list_rtst_in_disk", {
  94. method: 'post',
  95. })
  96. let list_rtst_in_disk = await response.json()
  97. list_rtst_in_disk = list_rtst_in_disk.map(decodeURI).map(s => "rtst:10:" + s)
  98. app.items = list_rtst_in_disk.concat(app.items)
  99. let hash = decodeURI(document.location.hash.replace('#', ''))
  100. if (hash) {
  101. hash = hash.split(',')
  102. }
  103. else {
  104. hash = [app.items[0]]
  105. }
  106. app.s查询参数 = hash
  107. }
  108. app = new Vue({
  109. el: '#app',
  110. vuetify: new Vuetify(),
  111. data: () => ({
  112. s关键词: "",
  113. s回答: "",
  114. i分数阈值: 60,
  115. results: [],
  116. // 是否显示snackbar
  117. b显示提示文本: false,
  118. // snackbar的文本
  119. s提示文本: "",
  120. temperature: 0.8,
  121. top_p: 0.2,
  122. max_length: 2000,
  123. llm_type: "",
  124. s查询参数: '',
  125. items: items,
  126. }),
  127. methods: {
  128. },
  129. watch: {
  130. s查询参数: (s查询参数) => {
  131. document.location.hash = s查询参数.join(',')
  132. }
  133. }
  134. })
  135. f读取现有库()
  136. submit = async (e) => {
  137. e && e.preventDefault()
  138. window.ws && await ws.close();
  139. memory = await find_rtst_memory(app.s关键词, "rtst_kf", true)
  140. memory = memory.filter(i => !i.score || i.score < 200)
  141. if (memory.length > 0) {
  142. app.s回答 = memory[0].title
  143. app.results = memory.map(i => ({
  144. title: i.content,
  145. score: ((220 - i.score) / 220 * 100).toFixed(0),
  146. content: i.title
  147. }))
  148. return
  149. }
  150. kownladge = await find_dynamic(app.s关键词, 5, { libraryStategy: app.s查询参数.map(encodeURI).join(" "), maxItmes: 100 })
  151. kownladge = kownladge.map(i => ({
  152. title: get_title_form_md(i.title),
  153. score: ((220 - i.score) / 220 * 100).toFixed(0),
  154. url: get_url_form_md(i.title),
  155. content: i.content
  156. }))
  157. app.results = kownladge
  158. kownladge = kownladge.filter(i => !i.score || i.score > app.i分数阈值)
  159. if (kownladge.length > 0) {
  160. `if (app.llm_type == "rwkv") {
  161. let prompt = 'raw!Instruction: 深刻理解下面提供的信息,根据信息完成问答。\n\nInput: ' +
  162. kownladge.map((e, i) => i + 1 + "." + e.content).join('\n') + "\n\nResponse: Question: " + app.s关键词 + "\nAnswer: "
  163. return await send_raw(prompt, '', [], (s) => { app.s回答 = s })
  164. } else {
  165. let prompt = '总结下列与问题相关的信息。\n' +
  166. kownladge.map((e, i) => i + 1 + "." + e.content).join('\n') + "\n问题:" + app.s关键词
  167. return await send_raw(prompt, '', [], (s) => { app.s回答 = s })
  168. }`
  169. } else {
  170. alert("没有找到")
  171. //return await send(Q, keyword = Q, show = true, sources = sources)
  172. }
  173. }
  174. get_title_form_md = (s) => {
  175. try {
  176. return s.match('\\[(.+)\\]')[1]
  177. } catch {
  178. return s
  179. }
  180. }
  181. get_url_form_md = (s) => {
  182. try {
  183. return s.match('\\((.+)\\)')[1]
  184. } catch {
  185. return s
  186. }
  187. }
  188. alert = (text) => {
  189. app.s提示文本 = text; //.replace(/\n/g,"<br>")
  190. app.b显示提示文本 = true;
  191. }
  192. </script>
  193. <script src="wd_sdk.js"></script>
  194. <script src="api/llm"></script>
  195. </body>
  196. </html>
粤ICP备19079148号