wdlw.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. .logo-center {
  23. left: calc(50% - 140px);
  24. width: 260px;
  25. font-size: 4em;
  26. padding-top: 2.5em;
  27. padding-bottom: 0.8em;
  28. position: relative;
  29. }
  30. .logo-left {
  31. left: 20px;
  32. width: 100%;
  33. font-size: xx-large;
  34. position: relative;
  35. }
  36. .input-box {
  37. margin: auto;
  38. width: fit-content;
  39. min-width: 580px;
  40. }
  41. pre {
  42. margin: 20px;
  43. white-space: break-spaces;
  44. }
  45. .v-application--wrap {
  46. display: unset;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div id="app" v-cloak>
  52. <v-app>
  53. <div :class="(s题目.length!=0||s提纲.length!=0)?'logo-left':'logo-center'"><b
  54. style="color: purple;">闻达</b><b>论文</b></div>
  55. <v-row class="input-box">
  56. <v-col cols="10">
  57. <v-textarea autofocus v-model="s题目" label="题目" no-resize rows="1"
  58. hide-details="auto"
  59. @keypress.enter="sctg"></v-textarea>
  60. </v-col>
  61. <v-col cols="2">
  62. <v-btn color="purple" dark size="x-large" @click="f生成提纲()">
  63. 生成提纲
  64. </v-btn>
  65. </v-col>
  66. </v-row>
  67. <v-card elevation="2" v-if="s提纲">
  68. <v-card-title>提纲</v-card-title>
  69. <v-divider></v-divider>
  70. <v-card-text>
  71. <v-textarea autofocus v-model="s提纲" label="提纲" rows="15"
  72. hide-details="auto"></v-textarea>
  73. </v-card-text>
  74. <v-card-action>
  75. <v-btn color="purple" dark size="x-large" @click="f生成正文()">
  76. 生成正文
  77. </v-btn>
  78. <v-btn color="purple" dark size="x-large" @click="f复制正文()"
  79. v-if="results.length">
  80. 复制正文
  81. </v-btn>
  82. </v-card-action>
  83. </v-card>
  84. <v-card elevation="2" v-for="result in results">
  85. <v-card-title>{{result.title}} <v-spacer></v-spacer>
  86. <v-icon @click="copy(result.content)" v-if="result.prompt">
  87. mdi-content-copy
  88. </v-icon>
  89. <v-icon @click="f重新生成(result)" v-if="result.prompt">
  90. mdi-refresh
  91. </v-icon>
  92. <v-icon @click="f知识库重新生成(result)" v-if="result.prompt">
  93. mdi-book-open-variant
  94. </v-icon>
  95. </v-card-title>
  96. <v-divider v-if="result.prompt"></v-divider>
  97. <pre v-text="result.content"></pre>
  98. </v-card>
  99. <v-snackbar v-model="b显示提示文本" :timeout="3000" style="white-space: pre-line">{{s提示文本}}</v-snackbar>
  100. <v-dialog v-model="show_dialog" persistent max-width="600px">
  101. <v-card class="ma-0 pa0">
  102. <v-card-title>
  103. <span class="text-h5">{{dialog_title}}</span>
  104. </v-card-title>
  105. <v-card-text>
  106. <v-container>
  107. <v-textarea autofocus v-model="dialog_input" no-resize rows="2"
  108. hide-details="auto"
  109. @keypress.enter="show_dialog = false;window.dialog_input_resolver()"></v-textarea>
  110. </v-container>
  111. </v-card-text>
  112. <v-card-actions>
  113. <v-spacer></v-spacer>
  114. <v-btn color="blue darken-1" text
  115. @click="show_dialog = false;dialog_input='';window.dialog_input_resolver()">
  116. 取消
  117. </v-btn>
  118. <v-btn color="blue darken-1" text
  119. @click="show_dialog = false;window.dialog_input_resolver()">
  120. 确认
  121. </v-btn>
  122. </v-card-actions>
  123. </v-card>
  124. </v-dialog>
  125. </v-app>
  126. </div>
  127. <script>
  128. let RomanNumeralsMap = {
  129. 'III': 3,
  130. 'II': 2,
  131. 'IV': 4,
  132. 'IX': 9,
  133. 'XL': 40,
  134. 'XC': 90,
  135. 'CD': 400,
  136. 'CM': 900,
  137. 'I': 1,
  138. 'V': 5,
  139. 'X': 10,
  140. 'L': 50,
  141. 'C': 100,
  142. 'D': 500,
  143. 'M': 1000
  144. }
  145. function find_RomanNumerals(str) {
  146. let number = 0;
  147. for (var p in RomanNumeralsMap) {
  148. if (str.indexOf(p) != -1) {
  149. str = str.split(p).join("");
  150. number += RomanNumeralsMap[p];
  151. }
  152. }
  153. return number
  154. }
  155. app = new Vue({
  156. el: '#app',
  157. vuetify: new Vuetify(),
  158. data: () => ({
  159. s题目: "",
  160. s提纲: "",
  161. results: [],
  162. // 是否显示snackbar
  163. b显示提示文本: false,
  164. // snackbar的文本
  165. s提示文本: "",
  166. temperature: 0.8,
  167. top_p: 0.2,
  168. max_length: 2000,
  169. llm_type: "",
  170. //显示对话框
  171. show_dialog: false,
  172. //对话框标题
  173. dialog_title: "",
  174. //对话框用户输入
  175. dialog_input: ""
  176. }),
  177. methods: {
  178. },
  179. watch: {
  180. }
  181. })
  182. f生成提纲 = async (e) => {
  183. e && e.preventDefault()
  184. let prompt = '根据以下主题,写一篇高度凝练且全面的论文提纲:' + app.s题目
  185. return await send_raw(prompt, '', [], (s) => { app.s提纲 = s })
  186. }
  187. sctg = f生成提纲
  188. f生成正文 = async (e) => {
  189. resp = app.s提纲
  190. .replace(/\n- /g, '\n1.')//兼容不同格式
  191. .split("\n")
  192. for (let i in resp) {
  193. let line = resp[i]
  194. if (line == "") continue
  195. line = line.split(".")
  196. if (line.length < 2&&!resp[i].match(/[一二三四五六七八九十]+/)) {
  197. continue // 判断非提纲内容
  198. }
  199. let num = find_RomanNumerals(line[0])
  200. if (num <= 0 || num == 100) {
  201. let paragraph = {
  202. title: resp[i],
  203. content: '',
  204. prompt: "根据主题:" + app.s题目 + "\n对下列段落进行详细的撰写:" + line[1]
  205. }
  206. app.results.push(paragraph)
  207. await send_raw(paragraph.prompt, '', [], (s) => { paragraph.content = s })
  208. } else {
  209. app.results.push({ title: resp[i], content: "" }) // 保存提纲
  210. }
  211. }
  212. }
  213. f重新生成 = async (paragraph) => {
  214. await edit(paragraph)
  215. await send_raw(paragraph.prompt, '', [], (s) => { paragraph.content = s })
  216. }
  217. f知识库重新生成 = async (paragraph) => {
  218. ` response = await fetch("/api/list_rtst_in_disk", {
  219. method: 'post',
  220. })
  221. let list_rtst_in_disk = await response.json()
  222. list_rtst_in_disk = list_rtst_in_disk.map(decodeURI).map(s => "rtst:10:" + s)
  223. kownladge = await find_dynamic(paragraph.title.split(".")[1], 5, { libraryStategy:list_rtst_in_disk.map(encodeURI).join(" "), maxItmes: 100 })
  224. `
  225. kownladge = await find(paragraph.title.split(".")[1], 5)
  226. kownladge = kownladge.filter(i => !i.score || i.score < 150)
  227. await send_raw(paragraph.prompt+'\n参考下列资料:\n' +
  228. kownladge.map((e, i) => i + 1 + "." + e.content).join('\n'), '', [], (s) => { paragraph.content = s })
  229. }
  230. f复制正文 = async () => {
  231. copy(app.results.map(i => i.title + "\n" + i.content).join("\n"))
  232. }
  233. alert = (text) => {
  234. app.s提示文本 = text; //.replace(/\n/g,"<br>")
  235. app.b显示提示文本 = true;
  236. }
  237. //编辑prompt
  238. edit = async (current_conversation) => {
  239. let s修改后的内容 = await input('请输入新的提示词', current_conversation.prompt)
  240. if (s修改后的内容) {
  241. current_conversation.prompt = s修改后的内容
  242. alert('修改成功')
  243. } else
  244. alert('取消修改')
  245. }
  246. //获取用户输入
  247. input = async (title = '请输入', input = '') => {
  248. app.dialog_title = title
  249. app.dialog_input = input
  250. app.show_dialog = true
  251. await new Promise(resolve => {
  252. window.dialog_input_resolver = resolve
  253. })
  254. return app.dialog_input
  255. }
  256. </script>
  257. <script src="wd_sdk.js"></script>
  258. <script src="api/llm"></script>
  259. </body>
  260. </html>
粤ICP备19079148号