wdsl.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. <style>
  15. div {
  16. transition: all 0.3s;
  17. }
  18. .v-sheet.v-card {
  19. margin: 20px;
  20. padding: 10px;
  21. }
  22. svg{
  23. background-color: white;
  24. }
  25. .logo-center {
  26. left: calc(50% - 140px);
  27. width: 260px;
  28. font-size: 4em;
  29. padding-top: 2.5em;
  30. padding-bottom: 0.8em;
  31. position: relative;
  32. }
  33. .logo-left {
  34. left: 20px;
  35. width: 100%;
  36. font-size: xx-large;
  37. position: relative;
  38. }
  39. .input-box {
  40. margin: auto;
  41. width: fit-content;
  42. min-width: 580px;
  43. }
  44. pre {
  45. margin: 20px;
  46. white-space: break-spaces;
  47. }
  48. .v-application--wrap {
  49. display: unset;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div id="app" v-cloak>
  55. <v-app>
  56. <div :class="(s题目.length!=0||s提纲.length!=0)?'logo-left':'logo-center'"><b
  57. style="color: purple;">闻达</b><b>思路</b></div>
  58. <v-row class="input-box">
  59. <v-col cols="10">
  60. <v-textarea autofocus v-model="s题目" label="题目" no-resize rows="1" hide-details="auto"
  61. @keypress.enter="sctg"></v-textarea>
  62. </v-col>
  63. <v-col cols="2">
  64. <v-btn color="purple" dark size="x-large" @click="f生成提纲()">
  65. 生成
  66. </v-btn>
  67. </v-col>
  68. </v-row>
  69. <v-card elevation="2" v-if="s提纲">
  70. <v-card-title>导图</v-card-title>
  71. <v-divider></v-divider>
  72. <v-card-text> <v-row>
  73. <v-col cols="5">
  74. <v-textarea autofocus v-model="s提纲" label="文本" rows="20" hide-details="auto"></v-textarea>
  75. </v-col>
  76. <v-col cols="7">
  77. <svg id="markmap" style="width: 100%; height: 600px"></svg> </v-col>
  78. </v-row>
  79. </v-card-text>
  80. <v-card-action>
  81. <v-btn color="purple" dark size="x-large" @click="mm.svg._groups[0][0].requestFullscreen()">
  82. 全屏显示
  83. </v-btn>
  84. <v-btn color="purple" dark size="x-large" @click="f复制正文()">
  85. 复制正文
  86. </v-btn>
  87. <v-btn color="purple" dark size="x-large" @click="f保存()">
  88. 保存导图
  89. </v-btn>
  90. </v-card-action>
  91. </v-card>
  92. <!-- <v-card elevation="2" v-for="result in results">
  93. <v-card-title>{{result.title}} <v-spacer></v-spacer>
  94. <v-icon @click="copy(result.content)" v-if="result.prompt">
  95. mdi-content-copy
  96. </v-icon>
  97. <v-icon @click="f重新生成(result)" v-if="result.prompt">
  98. mdi-refresh
  99. </v-icon>
  100. <v-icon @click="f知识库重新生成(result)" v-if="result.prompt">
  101. mdi-book-open-variant
  102. </v-icon>
  103. </v-card-title>
  104. <v-divider v-if="result.prompt"></v-divider>
  105. <pre v-text="result.content"></pre>
  106. </v-card> -->
  107. <v-snackbar v-model="b显示提示文本" :timeout="3000" style="white-space: pre-line">{{s提示文本}}</v-snackbar>
  108. <v-dialog v-model="show_dialog" persistent max-width="600px">
  109. <v-card class="ma-0 pa0">
  110. <v-card-title>
  111. <span class="text-h5">{{dialog_title}}</span>
  112. </v-card-title>
  113. <v-card-text>
  114. <v-container>
  115. <v-textarea autofocus v-model="dialog_input" no-resize rows="2" hide-details="auto"
  116. @keypress.enter="show_dialog = false;window.dialog_input_resolver()"></v-textarea>
  117. </v-container>
  118. </v-card-text>
  119. <v-card-actions>
  120. <v-spacer></v-spacer>
  121. <v-btn color="blue darken-1" text
  122. @click="show_dialog = false;dialog_input='';window.dialog_input_resolver()">
  123. 取消
  124. </v-btn>
  125. <v-btn color="blue darken-1" text @click="show_dialog = false;window.dialog_input_resolver()">
  126. 确认
  127. </v-btn>
  128. </v-card-actions>
  129. </v-card>
  130. </v-dialog>
  131. </v-app>
  132. </div>
  133. <script src="https://cdn.jsdelivr.net/npm/d3@6"></script>
  134. <script src="https://cdn.jsdelivr.net/npm/markmap-view"></script>
  135. <script src="https://cdn.jsdelivr.net/npm/markmap-lib"></script>
  136. <!-- <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar"></script> -->
  137. <script>
  138. const { Markmap, loadCSS, loadJS } = window.markmap;
  139. app = new Vue({
  140. el: '#app',
  141. vuetify: new Vuetify(),
  142. data: () => ({
  143. s题目: "",
  144. s提纲: "",
  145. results: [],
  146. // 是否显示snackbar
  147. b显示提示文本: false,
  148. // snackbar的文本
  149. s提示文本: "",
  150. temperature: 0.8,
  151. top_p: 0.2,
  152. max_length: 2000,
  153. llm_type: "",
  154. //显示对话框
  155. show_dialog: false,
  156. //对话框标题
  157. dialog_title: "",
  158. //对话框用户输入
  159. dialog_input: ""
  160. }),
  161. methods: {
  162. },
  163. watch: {
  164. s提纲: () => {
  165. window.b需重新生成 = true
  166. }
  167. }
  168. })
  169. f生成提纲 = async (e) => {
  170. e && e.preventDefault()
  171. let prompt = `根据所给内容:${app.s题目},以markmap代码生成足够深度以包含尽量多主要细节的思维导图。`
  172. return await send_raw(prompt, '', [
  173. {
  174. "role": "user",
  175. "content": "根据所给内容:学习英语,以markmap代码生成足够深度以包含尽量多主要细节的思维导图。",
  176. },
  177. {
  178. "role": "AI",
  179. "content": "# 学习英语\n## 听力训练\n* 听力技巧\n\t+ 集中注意力\n\t+ 听取关键词\n\t+ 理解句子结构\n\t+ 预测对话内容\n* 听力材料\n\t+ 英语新闻\n\t\t- 新闻内容\n\t\t- 新闻结构\n\t\t- 新闻时间\n\t+ 英语电影\n\t\t- 电影内容\n\t\t- 电影结构\n\t\t- 电影时间\n\t+ 英语歌曲\n\t\t- 歌曲内容\n\t\t- 歌曲结构\n\t\t- 歌曲时间\n## 阅读训练\n* 阅读技巧\n\t+ 阅读顺序\n\t+ 阅读材料分类\n\t+ 阅读策略\n\t+ 阅读时间控制\n* 阅读材料\n\t+ 英语新闻\n\t\t- 新闻主题\n\t\t- 新闻时间\n\t\t- 新闻内容\n\t+ 英语小说\n\t\t- 小说主题\n\t\t- 小说时间\n\t\t- 小说内容\n\t+ 英语散文\n\t\t- 散文主题\n\t\t- 散文时间\n\t\t- 散文内容\n\t+ 英语学术论文\n\t\t- 论文主题\n\t\t- 论文时间\n\t\t- 论文内容\n\t+ 英语杂志\n\t\t- 杂志主题\n\t\t- 杂志时间\n\t\t- 杂志内容\n## 写作训练\n* 写作技巧\n\t+ 写作顺序\n\t+ 写作材料分类\n\t+ 写作策略\n\t+ 写作时间控制\n* 写作材料\n\t+ 英语作文\n\t\t- 作文主题\n\t\t- 作文时间\n\t\t- 作文内容\n\t+ 英语日记\n\t\t- 日记主题\n\t\t- 日记时间\n\t\t- 日记内容\n\t+ 英语文章\n\t\t- 文章主题\n\t\t- 文章时间\n\t\t- 文章内容\n\t+ 英语演讲\n\t\t- 演讲主题\n\t\t- 演讲时间\n\t\t- 演讲内容\n\t+ 英语文章\n\t\t- 文章主题\n\t\t- 文章时间\n\t\t- 文章内容\n\t+ 英语论文\n\t\t- 论文主题\n\t\t- 论文时间\n\t\t- 论文内容\n\t+ 英语杂志\n\t\t- 杂志主题\n\t\t- 杂志时间\n\t\t- 杂志内容",
  180. "sources": []
  181. }
  182. ], (s) => { app.s提纲 = s })
  183. }
  184. setInterval(() => {
  185. if (window.b需重新生成) {
  186. window.b需重新生成 = false
  187. f生成导图()
  188. }
  189. }, 1000)
  190. f清除导图 = async (e) => {
  191. const svgEl = document.querySelector('#markmap');
  192. while (svgEl.children.length > 0) svgEl.removeChild(svgEl.children[0])
  193. }
  194. f生成导图 = async (e) => {
  195. const transformer = new markmap.Transformer()
  196. const { root, features } = transformer.transform(app.s提纲)
  197. if (window.mm) {
  198. window.mm.setData(root);
  199. window.mm.fit();
  200. } else {
  201. window.mm = Markmap.create('#markmap', null, root)
  202. //toolbar = markmap.Toolbar.create(mm);
  203. //document.body.append(toolbar.el);
  204. }
  205. }
  206. sctg = f生成提纲
  207. f生成正文 = async (e) => {
  208. resp = app.s提纲
  209. .replace(/\n- /g, '\n1.')//兼容不同格式
  210. .split("\n")
  211. for (let i in resp) {
  212. let line = resp[i]
  213. if (line == "") continue
  214. line = line.split(".")
  215. if (line.length < 2) {
  216. continue // 判断非提纲内容
  217. }
  218. let num = find_RomanNumerals(line[0])
  219. if (num <= 0 || num == 100) {
  220. let paragraph = {
  221. title: resp[i],
  222. content: '',
  223. prompt: "根据主题:" + app.s题目 + "\n对下列段落进行详细的撰写:" + line[1]
  224. }
  225. app.results.push(paragraph)
  226. await send_raw(paragraph.prompt, '', [], (s) => { paragraph.content = s })
  227. } else {
  228. app.results.push({ title: resp[i], content: "" }) // 保存提纲
  229. }
  230. }
  231. }
  232. f重新生成 = async (paragraph) => {
  233. await edit(paragraph)
  234. await send_raw(paragraph.prompt, '', [], (s) => { paragraph.content = s })
  235. }
  236. f知识库重新生成 = async (paragraph) => {
  237. ` response = await fetch("/api/list_rtst_in_disk", {
  238. method: 'post',
  239. })
  240. let list_rtst_in_disk = await response.json()
  241. list_rtst_in_disk = list_rtst_in_disk.map(decodeURI).map(s => "rtst:10:" + s)
  242. kownladge = await find_dynamic(paragraph.title.split(".")[1], 5, { libraryStategy:list_rtst_in_disk.map(encodeURI).join(" "), maxItmes: 100 })
  243. `
  244. kownladge = await find(paragraph.title.split(".")[1], 5)
  245. kownladge = kownladge.filter(i => !i.score || i.score < 150)
  246. await send_raw(paragraph.prompt + '\n参考下列资料:\n' +
  247. kownladge.map((e, i) => i + 1 + "." + e.content).join('\n'), '', [], (s) => { paragraph.content = s })
  248. }
  249. f复制正文 = async () => {
  250. copy(app.results.map(i => i.title + "\n" + i.content).join("\n"))
  251. }
  252. f保存 = async () => {
  253. const blob = new Blob([new XMLSerializer().serializeToString(mm.svg._groups[0][0])], {
  254. type: "text/plain;charset=utf-8"
  255. })
  256. const objectURL = URL.createObjectURL(blob)
  257. const aTag = document.createElement('a')
  258. aTag.href = objectURL
  259. aTag.download = '【闻达思路】'+ app.s题目+".svg"
  260. aTag.click()
  261. URL.revokeObjectURL(objectURL)
  262. }
  263. alert = (text) => {
  264. app.s提示文本 = text; //.replace(/\n/g,"<br>")
  265. app.b显示提示文本 = true;
  266. }
  267. //编辑prompt
  268. edit = async (current_conversation) => {
  269. let s修改后的内容 = await input('请输入新的提示词', current_conversation.prompt)
  270. if (s修改后的内容) {
  271. current_conversation.prompt = s修改后的内容
  272. alert('修改成功')
  273. } else
  274. alert('取消修改')
  275. }
  276. //获取用户输入
  277. input = async (title = '请输入', input = '') => {
  278. app.dialog_title = title
  279. app.dialog_input = input
  280. app.show_dialog = true
  281. await new Promise(resolve => {
  282. window.dialog_input_resolver = resolve
  283. })
  284. return app.dialog_input
  285. }
  286. </script>
  287. <script src="wd_sdk.js"></script>
  288. <script src="api/llm"></script>
  289. </body>
  290. </html>
粤ICP备19079148号