aiCreateVideoDialog.vue 19 KB

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