aiCreateVideoDialog copy.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <el-dialog title="智能检索" :visible.sync="dialogVisibleAiCreateVideo" :append-to-body="true" width="700px"
  3. :before-close="handleClose" class="dialog_diy">
  4. <div style="height: 500px;padding:15px" v-loading="loading" element-loading-text="小可正在努力生成中,请稍等...">
  5. <div style="position: relative; width: 100%;height: 40px;margin-bottom: 10px;">
  6. <el-input class="inputC" style="height: 100%;" placeholder="搜索视频关键字(如需搜索多个可“,”隔开)" v-model="detail"
  7. @keyup.enter.native="searchA()"></el-input>
  8. <div class="search_img" @click="searchA" style="right: 10px">
  9. <img src="../../../assets/icon/search.png" alt />
  10. </div>
  11. </div>
  12. <div class="Box">
  13. <!-- <div class="video_box" v-for="(item,index) in data" :key="index">
  14. <img :src="item.snippet.thumbnails.high.url" />
  15. <span class="name">{{ item.snippet.title }}</span>
  16. <span class="detail">{{ item.snippet.description }}</span>
  17. <div class="btn">
  18. <span @click="openUrl(item.id.videoId)">查看</span>
  19. <span @click="checkUrl(item.snippet.title,item.id.videoId)">加入</span>
  20. </div>
  21. </div> -->
  22. <div class="video_box video_box2" v-for="(item, index) in data" :key="index">
  23. <!-- <img :src="item.pic" /> -->
  24. <span class="name" v-html="item.title"></span>
  25. <span class="detail">{{ item.description }}</span>
  26. <div class="btn">
  27. <span @click="openUrl(item.bvid)">查看</span>
  28. <span @click="checkUrl(item.title, item.bvid)">加入</span>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <span slot="footer" class="dialog-footer">
  34. <!-- <el-button @click="aiGet" type="primary">重新生成</el-button> -->
  35. <!-- <el-button @click="confirm" type="primary">确 定</el-button> -->
  36. <el-button @click="close">关 闭</el-button>
  37. </span>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import { v4 as uuidv4 } from "uuid";
  42. export default {
  43. components: {
  44. },
  45. props: {
  46. dialogVisibleAiCreateVideo: {
  47. type: Boolean,
  48. default: false
  49. },
  50. courseName: {
  51. type: String,
  52. default: ""
  53. },
  54. courseState: {
  55. type: Number,
  56. },
  57. lineCount: {
  58. type: Number,
  59. },
  60. unitJson: {
  61. type: Array,
  62. }
  63. },
  64. // 根据用户给你的参考资料
  65. data() {
  66. return {
  67. userid: this.$route.query.userid,
  68. radio: 0,
  69. aiJson: {
  70. ppt: ``,
  71. word: '',
  72. video: ''
  73. },
  74. aiUrl: {
  75. ppt: '',
  76. word: '',
  77. video: ''
  78. },
  79. detail: "",
  80. loading: false,
  81. url: "",
  82. data: [],
  83. uJson: {}
  84. }
  85. },
  86. watch: {
  87. dialogVisibleAiCreateVideo(newValue, oldValue) {
  88. if (newValue) {
  89. // if (this.radio == 0) {
  90. if (this.courseState == 4) {
  91. this.detail = this.courseName
  92. this.aiGet()
  93. } else if (this.courseState == 5) {
  94. // this.detail = this.unitJson[0].chapterInfo[0].taskJson[this.lineCount].task.replace("任务"+(this.lineCount+1)+":","")
  95. this.againEva()
  96. }
  97. // }
  98. // if (this.radio == 1) {
  99. // this.detail = this.aiJson.word
  100. // }
  101. // if (this.radio == 2) {
  102. // this.detail = this.aiJson.video
  103. // }
  104. // this.loading = false
  105. // this.aiGet()
  106. // this.againEva()
  107. }
  108. },
  109. },
  110. methods: {
  111. handleClose(done) {
  112. this.close()
  113. done();
  114. },
  115. close() {
  116. this.$emit('update:dialogVisibleAiCreateVideo', false)
  117. },
  118. openUrl(url) {
  119. // window.open('https://www.youtube.com/embed/'+url)
  120. window.open(`//www.bilibili.com/video/${url}`)
  121. },
  122. checkUrl(name, id) {
  123. let json = {
  124. name: "链接",
  125. title: name.replace(/<[^>]*>?/gm, ''),
  126. // url: 'https://www.youtube.com/embed/'+id,
  127. url: `//player.bilibili.com/player.html?isOutside=true&bvid=${id}`,
  128. type: 8,
  129. }
  130. this.$emit('createAiVideo', json)
  131. this.$message.success('加入成功')
  132. },
  133. changeRadio() {
  134. if (this.radio == 0) {
  135. this.detail = this.aiJson.ppt
  136. }
  137. if (this.radio == 1) {
  138. this.detail = this.aiJson.word
  139. }
  140. if (this.radio == 2) {
  141. this.detail = this.aiJson.video
  142. }
  143. },
  144. // async aiGet() {
  145. // let _this = this
  146. // _this.loading = true
  147. // this.ajax
  148. // .get(`https://www.googleapis.com/youtube/v3/search?key=AIzaSyBUvNQ5Wyua4PbStE2vp3t7MIY4htry-4M&part=snippet&q=${this.detail}&maxResults=10&type=video&order=relevance&regionCode=HK`)
  149. // .then((response) => {
  150. // console.log(response);
  151. // _this.data = response.data.items
  152. // _this.loading = false
  153. // })
  154. // .catch((error) => {
  155. // _this.loading = false
  156. // console.log(error);
  157. // });
  158. // },
  159. async aiGet() {
  160. let _this = this
  161. _this.loading = true
  162. this.ajax.post(`https://gpt4.cocorobo.cn/get_network_search`, {
  163. engine: "bilibili",
  164. keyword: this.detail
  165. }).then(response => {
  166. console.log(response);
  167. _this.data = response.data.FunctionResponse
  168. _this.loading = false
  169. })
  170. .catch((error) => {
  171. _this.loading = false
  172. console.log(error);
  173. });
  174. },
  175. // async aiGet2(msg) {
  176. // let _this = this
  177. // _this.loading = true
  178. // this.ajax
  179. // .get(`https://www.googleapis.com/youtube/v3/search?key=AIzaSyBUvNQ5Wyua4PbStE2vp3t7MIY4htry-4M&part=snippet&q=${msg}&maxResults=10&type=video&order=relevance&regionCode=HK`)
  180. // .then((response) => {
  181. // console.log(response);
  182. // _this.data = response.data.items
  183. // _this.loading = false
  184. // })
  185. // .catch((error) => {
  186. // _this.loading = false
  187. // console.log(error);
  188. // });
  189. // },
  190. async aiGet2(msg) {
  191. let _this = this
  192. return new Promise((resolve, reject) => {
  193. this.ajax.post(`https://gpt4.cocorobo.cn/get_network_search`, {
  194. engine: "bilibili",
  195. keyword: msg
  196. }).then(response => {
  197. console.log(response);
  198. // _this.data = [..._this.data,...response.data.FunctionResponse]
  199. resolve(response.data.FunctionResponse)
  200. })
  201. .catch((error) => {
  202. resolve([])
  203. console.log(error);
  204. });
  205. });
  206. },
  207. async searchA(){
  208. let _this = this
  209. if(!_this.detail){
  210. _this.$message.error("请输入关键字")
  211. return
  212. }
  213. _this.loading = true
  214. let _content = ""
  215. if(_this.detail.split(",").length>1){
  216. _content = _this.detail.split(",")
  217. }else{
  218. _content = _this.detail.split(",")
  219. }
  220. _this.data = []
  221. for (var a = 0; a < _content.length; a++) {
  222. let _data = await _this.aiGet2(_content[a])
  223. _this.data = [..._this.data, ..._data]
  224. }
  225. _this.data = _this.data.sort(
  226. function (a, b) {
  227. return b.play - a.play;
  228. }
  229. );
  230. _this.againEva2();
  231. // _this.loading = false
  232. },
  233. againEva() {
  234. let _this = this
  235. _this.loading = true
  236. let message = `从以下内容中识别出1~2个学科知识点关键词,用于检索知识点相关视频。注意,你仅需要返回关键词,“,”分开。教案:${_this.unitJson[0].chapterInfo[0].taskJson[_this.lineCount].taskDetail3.replaceAll('#', '').replaceAll('*', '').replaceAll('-', '').replaceAll('\n', '')}`
  237. let parm = {
  238. assistant_id: 'f8e1ebb2-2e0d-11ef-8bf4-12e77c4cb76b',
  239. message: [{ "type": "text", "text": message.replaceAll('\n', " ").replaceAll('*', "") }],
  240. session_name: uuidv4(),
  241. userId: _this.userid,
  242. file_ids: [],
  243. model: 'gpt-4o-2024-08-06',
  244. }
  245. _this.ajax
  246. .post("https://gpt4.cocorobo.cn/ai_agent_park_chat", parm)
  247. .then(async (response) => {
  248. console.log(response);
  249. let data = response.data.FunctionResponse
  250. if (data.message) {
  251. console.log(data.message);
  252. let content = data.message;
  253. _this.detail = content
  254. let _content = content.split(",")
  255. if(content.split(",").length>1){
  256. _content = content.split(",")
  257. }else{
  258. _content = content.split(",")
  259. }
  260. _this.data = []
  261. for (var a = 0; a < _content.length; a++) {
  262. let _data = await _this.aiGet2(_content[a])
  263. _this.data = [..._this.data, ..._data]
  264. }
  265. _this.data = _this.data.sort(
  266. function (a, b) {
  267. return b.play - a.play;
  268. }
  269. );
  270. _this.againEva2();
  271. }
  272. // _this.loading = false
  273. })
  274. .catch((error) => {
  275. console.log(error);
  276. _this.loading = true
  277. });
  278. },
  279. againEva2() {
  280. let _this = this
  281. _this.loading = true
  282. let message = `ATTENTION: Use '##' to SPLIT SECTIONS, not '#'.Output format carefully referenced "Format example".
  283. 针对以下视频数组内容,删除其中不适合k12年级的学生在教室里看到的条目,返回以下视频数组不符合的视频的aid,视频数组:${JSON.stringify(_this.data)}
  284. # Format example
  285. [{aid:""},{aid:""}]
  286. `
  287. let parm = {
  288. model: 'gpt-4o-2024-08-06',
  289. temperature: 0,
  290. max_tokens: 4096,
  291. top_p: 1,
  292. frequency_penalty: 0,
  293. presence_penalty: 0,
  294. messages: [{
  295. content: message.replaceAll('\n', " ").replaceAll('*', ""),
  296. role: 'user'
  297. }],
  298. uid: uuidv4(),
  299. stream: false,
  300. mind_map_question: "",
  301. }
  302. _this.ajax
  303. .post("https://gpt4.cocorobo.cn/chat", parm)
  304. .then(async (response) => {
  305. console.log(response);
  306. let data = response.data.FunctionResponse
  307. if (data.choices && data.choices.length && data.choices[0].message) {
  308. console.log(data.choices[0].message.content);
  309. let dArray = []
  310. try {
  311. dArray = JSON.parse(data.choices[0].message.content.replaceAll('```json','').replaceAll('```',''))
  312. } catch (error) {
  313. console.log("error_________________" + error);
  314. try {
  315. let regex = new RegExp("(?<=```json)([\\s\\S]*?)(?=```)");
  316. let match = data.choices[0].message.content.match(regex);
  317. dArray = JSON.parse(match[0]);
  318. } catch (error) {
  319. console.log("error_________________" + error);
  320. }
  321. }
  322. let aid = []
  323. for(var i = 0; i < dArray.length; i++){
  324. aid.push(dArray[i].aid)
  325. }
  326. _this.data = _this.data.filter(el => {
  327. return aid.indexOf(el.aid) === -1
  328. })
  329. _this.$forceUpdate()
  330. }
  331. _this.loading = false
  332. })
  333. .catch((error) => {
  334. console.log(error);
  335. _this.loading = true
  336. });
  337. },
  338. },
  339. }
  340. </script>
  341. <style scoped>
  342. .dialog_diy>>>.el-dialog {
  343. height: auto;
  344. margin: 15vh auto 0 !important;
  345. }
  346. .dialog_diy>>>.el-dialog__header {
  347. background: #454545 !important;
  348. padding: 15px 20px;
  349. }
  350. .dialog_diy>>>.el-dialog__body {
  351. height: calc(100% - 124px);
  352. box-sizing: border-box;
  353. padding: 0px;
  354. }
  355. .dialog_diy>>>.el-dialog__title {
  356. color: #fff;
  357. }
  358. .dialog_diy>>>.el-dialog__headerbtn {
  359. top: 19px;
  360. }
  361. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close {
  362. color: #fff;
  363. }
  364. .dialog_diy>>>.el-dialog__headerbtn .el-dialog__close:hover {
  365. color: #fff;
  366. }
  367. .dialog_diy>>>.el-dialog__body,
  368. .dialog_diy>>>.el-dialog__footer {
  369. background: #fafafa;
  370. }
  371. .binfo_input {
  372. width: 100%;
  373. margin: 0;
  374. padding: 5px 7px;
  375. display: block;
  376. min-width: 0;
  377. outline: none;
  378. box-sizing: border-box;
  379. background: none;
  380. border: none;
  381. border-radius: 4px;
  382. background: #fff;
  383. font-size: 15px;
  384. resize: none;
  385. font-family: "Microsoft YaHei";
  386. min-height: 48px;
  387. /* border: 1px solid #3682fc00; */
  388. border: 1.5px solid #cad1dc;
  389. }
  390. .binfo_textarea {
  391. border: 1.5px solid #cad1dc;
  392. font-size: 15px;
  393. resize: none;
  394. /* background: #f6f6f6; */
  395. font-family: "Microsoft YaHei";
  396. }
  397. .binfo_input:focus-visible {
  398. border: 1.5px solid #3681fc !important;
  399. }
  400. .t_box {
  401. display: flex;
  402. margin-bottom: 15px;
  403. }
  404. .t_box>span:nth-child(1) {
  405. min-width: 80px;
  406. font-size: 16px;
  407. color: #000;
  408. }
  409. .inputC>>>.el-input__inner {
  410. padding: '0 35px 0 15px'
  411. }
  412. .search_img {
  413. width: 20px;
  414. height: 20px;
  415. position: absolute;
  416. right: 10px;
  417. top: 50%;
  418. transform: translateY(-50%);
  419. }
  420. .search_img>img {
  421. width: 100%;
  422. height: 100%;
  423. }
  424. .Box {
  425. width: 100%;
  426. height: calc(100% - 50px);
  427. overflow: auto;
  428. display: flex;
  429. flex-direction: row;
  430. justify-content: flex-start;
  431. flex-wrap: wrap;
  432. }
  433. .video_box {
  434. width: calc(100% / 2 - 10px);
  435. /* overflow: hidden; */
  436. margin-right: 10px;
  437. display: flex;
  438. flex-direction: column;
  439. margin-bottom: 15px;
  440. cursor: pointer;
  441. }
  442. .video_box>img {
  443. height: 200px;
  444. object-fit: cover;
  445. }
  446. .video_box>.detail {
  447. color: #cecece;
  448. }
  449. .video_box>.name {
  450. color: #000;
  451. margin: 5px 0;
  452. height: 32px;
  453. }
  454. .btn {
  455. width: 100%;
  456. height: 35px;
  457. display: flex;
  458. align-items: center;
  459. margin-top: auto;
  460. }
  461. .btn>span:hover {
  462. background: #4087f1;
  463. }
  464. .btn>span {
  465. width: 100%;
  466. height: 100%;
  467. background: #3681fc;
  468. color: #fff;
  469. border-radius: 5px;
  470. margin-top: 10px;
  471. cursor: pointer;
  472. display: flex;
  473. align-items: center;
  474. justify-content: center;
  475. }
  476. .btn>span+span {
  477. margin-left: 10px;
  478. }
  479. .video_box2 {
  480. box-shadow: 0px 0px 4px 2px #d2d2d282;
  481. padding: 5px 10px 10px;
  482. box-sizing: border-box;
  483. border-radius: 5px;
  484. }
  485. </style>