dialogArea.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. <template>
  2. <div class="dialog">
  3. <div v-show="cardType == 0">
  4. <div class="d_top" ref="chatRef">
  5. <div class="d_t_chat" v-for="(item, index) in chatList" :key="index">
  6. <div class="d_t_c_user" v-if="item.content">
  7. <div class="d_t_c_u_left">
  8. <div class="d_t_c_u_l_content">{{ item.content }}</div>
  9. <div class="d_t_c_u_l_time">{{ item.createtime }}</div>
  10. </div>
  11. <div class="d_t_c_u_right">
  12. <span>我</span>
  13. </div>
  14. </div>
  15. <div class="d_t_c_ai">
  16. <div class="d_t_c_a_left">
  17. <el-avatar v-if="item.filename" :src="item.filename"></el-avatar>
  18. <span v-else>Ai</span>
  19. </div>
  20. <div class="d_t_c_a_right">
  21. <div
  22. class="d_t_c_a_r_content"
  23. v-loading="item.loading"
  24. v-html="item.aiContent"
  25. ></div>
  26. <div class="d_t_c_a_r_time">{{ item.createtime }}</div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="d_bottom">
  32. <div class="d_b_btnArea">
  33. <div class="d_b_ba-item" @click.stop="choiceRole()">
  34. <img
  35. style="width: 20px;"
  36. src="../../../assets/icon/course/role.png"
  37. alt=""
  38. />
  39. 选择角色
  40. </div>
  41. <div class="d_b_ba-item" @click.stop="clear()">
  42. 清空聊天记录
  43. </div>
  44. </div>
  45. <div class="d_b_inputArea">
  46. <!-- <div class="d_b_tape" @click="goTape()"></div> -->
  47. <div class="d_b_input">
  48. <el-input
  49. :disabled="loading || chatLoading"
  50. v-loading="loading || chatLoading"
  51. @keyup.enter.native="send()"
  52. class="d_b_i_left"
  53. v-model="text"
  54. ></el-input>
  55. <!-- <div class="d_b_i_right" @click="sendFile()">
  56. <span></span>
  57. </div> -->
  58. </div>
  59. <div class="d_b_btn" @click="send()">
  60. <span></span>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="" v-show="cardType == 1">
  66. <div class="choiceTop">
  67. <div class="choiceRoleHeader">
  68. <div>切换角色:</div>
  69. <span>您希望以下哪个角色回答您的问题,请选择:</span>
  70. </div>
  71. <div class="choiceSelect">
  72. <el-button
  73. class="option"
  74. :style="{
  75. background: sortOption == 0 ? '#36A9FC' : '',
  76. color: sortOption == 0 ? '#fff' : ''
  77. }"
  78. @click="optBtn(0)"
  79. plain
  80. >我的</el-button
  81. >
  82. <el-button
  83. class="option"
  84. :style="{
  85. background: sortOption == 1 ? '#36A9FC' : '',
  86. color: sortOption == 1 ? '#fff' : ''
  87. }"
  88. @click="optBtn(1)"
  89. plain
  90. >社区</el-button
  91. >
  92. </div>
  93. <div
  94. class="characterBlock"
  95. v-if="sortOption == 0"
  96. v-for="(item, index) in roleList"
  97. :key="item.id"
  98. @click.stop="choseRole(item)"
  99. >
  100. <div class="imgLeft">
  101. <div class="img">
  102. <img style="width: 100%;height: 100%;" :src="item.avatar" />
  103. </div>
  104. </div>
  105. <div class="txtRight">
  106. <div class="bir">{{ item.assistantName }}</div>
  107. <div
  108. :style="{
  109. color: '#fff',
  110. display:
  111. choseRoleItem.assistant_id == item.assistant_id
  112. ? 'block'
  113. : 'none'
  114. }"
  115. >
  116. 已选择
  117. </div>
  118. <!-- <span></span> -->
  119. </div>
  120. </div>
  121. <div
  122. class="characterBlock"
  123. v-if="sortOption == 1"
  124. v-for="(item, index) in roleList2"
  125. :key="item.id"
  126. @click.stop="choseRole(item)"
  127. >
  128. <div class="imgLeft">
  129. <div class="img">
  130. <img
  131. style="width: 100%;height: 100%;"
  132. :src="
  133. item.headUrl
  134. ? item.headUrl
  135. : require('../../../assets/icon/course/ai.png')
  136. "
  137. />
  138. </div>
  139. </div>
  140. <div class="txtRight">
  141. <div class="bir">{{ item.assistantName }}</div>
  142. <div
  143. :style="{
  144. color: '#fff',
  145. display:
  146. choseRoleItem.assistant_id == item.assistant_id
  147. ? 'block'
  148. : 'none'
  149. }"
  150. >
  151. 已选择
  152. </div>
  153. <!-- <span></span> -->
  154. </div>
  155. </div>
  156. <!-- <div class="characterBlock" @click="addCharacter">
  157. <div class="imgLeft">
  158. <div class="img2">
  159. <img style="width: 100%;height: 100%;" src="https://ccrb.s3.cn-northwest-1.amazonaws.com.cn/basil_add-outline1715564539170.png">
  160. </div>
  161. </div>
  162. <div class="txtRight">
  163. <div style="color: #fff;margin-left: 5px;">添加新角色</div>
  164. </div>
  165. </div> -->
  166. <!-- <div class="filterSubjects">
  167. <div class="fs_title">筛选科目</div>
  168. <div class="fs_box">
  169. <div :class="['fs_b_item',subjectsType==index?'fs_b_itemActive':'']" v-for="(item,index) in subjectsList" :key="index" @click="subjectsType = index">{{ item }}</div>
  170. </div>
  171. </div>
  172. <div class="roleList">
  173. <div class="r_title">角色列表 ({{ roleList.length }})</div>
  174. <div class="r_box">
  175. <div :class="['r_b_item',roleType==index?'r_b_itemActive':'']" v-for="(item,index) in roleList" :key="item.id" @click.stop="roleType=index">
  176. <img :src="item.avatar">
  177. <span>{{ item.name }}</span>
  178. </div>
  179. </div>
  180. </div> -->
  181. </div>
  182. <div class="choiceBottom">
  183. <el-button class="cb_btn" size="mini" @click="noChangeRole()"
  184. >取消</el-button
  185. >
  186. <el-button
  187. class="cb_btn"
  188. size="mini"
  189. type="primary"
  190. @click="changeRole()"
  191. >确定</el-button
  192. >
  193. </div>
  194. </div>
  195. </div>
  196. </template>
  197. <script>
  198. import { v4 as uuidv4 } from "uuid";
  199. import MarkdownIt from "markdown-it";
  200. export default {
  201. data() {
  202. return {
  203. cardType: 0, //0-对话 1-选角色
  204. userid: this.$route.query.userid,
  205. courseId: this.$route.query.courseId,
  206. org: this.$route.query.org,
  207. choseRoleItem: {},
  208. text: "",
  209. sortOption: 0, //切换角色 0我的 1 社区
  210. subjectsList: [
  211. "语文",
  212. "数学",
  213. "英语",
  214. "科学",
  215. "信息",
  216. "历史",
  217. "地理",
  218. "政治",
  219. "生物",
  220. "化学",
  221. "物理",
  222. "其他"
  223. ],
  224. subjectsType: -1,
  225. rightSubjects: -1,
  226. roleType: -1,
  227. rightRole: -1,
  228. loading: false,
  229. chatLoading: false,
  230. roleList2: [
  231. {
  232. id: 3,
  233. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  234. name: "莱昂纳多·达芬奇",
  235. bir: "我是莱昂纳多·达芬奇"
  236. },
  237. {
  238. id: 4,
  239. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  240. name: "列文虎克",
  241. bir: "我是列文虎克"
  242. },
  243. {
  244. id: 5,
  245. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  246. name: "詹姆斯·瓦特",
  247. bir: "我是詹姆斯·瓦特"
  248. },
  249. {
  250. id: 6,
  251. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  252. name: "瑞秋·卡森",
  253. bir: "我是瑞秋·卡森"
  254. },
  255. {
  256. id: 7,
  257. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  258. name: "尼古拉·特斯拉",
  259. bir: "我是尼古拉·特斯拉"
  260. },
  261. {
  262. id: 8,
  263. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  264. name: "约翰·穆尔",
  265. bir: "我是约翰·穆尔"
  266. }
  267. ],
  268. roleList: [
  269. {
  270. id: 0,
  271. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  272. name: "爱因斯坦",
  273. bir: "我是爱因斯坦"
  274. },
  275. {
  276. id: 1,
  277. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  278. name: "居里夫人",
  279. bir: "我是居里夫人"
  280. },
  281. {
  282. id: 2,
  283. avatar: require("../../../assets/icon/course/aiAvatar.png"),
  284. name: "达尔文",
  285. bir: "我是达尔文"
  286. }
  287. // {id:3,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"莱昂纳多·达芬奇"},
  288. // {id:4,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"列文虎克"},
  289. // {id:5,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"詹姆斯·瓦特"},
  290. // {id:6,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"瑞秋·卡森"},
  291. // {id:7,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"尼古拉·特斯拉"},
  292. // {id:8,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"约翰·穆尔"},
  293. // {id:9,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"艾萨克·牛顿"},
  294. // {id:10,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"伽利略"},
  295. // {id:11,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"格雷戈尔·孟德尔"},
  296. // {id:12,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"张衡"},
  297. // {id:13,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"李时珍"},
  298. // {id:14,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"钱学森"},
  299. // {id:15,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"阿基米德"},
  300. // {id:16,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"霍金"},
  301. // {id:17,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"蔡伦"},
  302. // {id:18,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"詹姆斯·瓦特"},
  303. // {id:19,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"路易·巴斯德"},
  304. // {id:20,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"阿尔弗雷德·诺贝尔"},
  305. // {id:21,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"詹姆斯·麦克斯韦"},
  306. // {id:22,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"亚历山大·格拉汉姆·贝尔"},
  307. // {id:23,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"约翰内斯·开普勒"},
  308. // {id:24,avatar:require("../../../assets/icon/course/aiAvatar.png"),name:"安德烈·安培"},
  309. ],
  310. chatList: []
  311. };
  312. },
  313. methods: {
  314. clear(){
  315. this.chatList = [];
  316. },
  317. // addCharacter(){
  318. // this.$message.info("点击了添加新角色")
  319. // },
  320. optBtn(val) {
  321. this.sortOption = val;
  322. },
  323. choiceRole() {
  324. if (this.loading) return this.$message.info("请稍等");
  325. this.cardType = 1;
  326. },
  327. sendFile() {
  328. if (this.loading) return this.$message.info("请稍等");
  329. this.$message.info("点击了附件");
  330. },
  331. goTape() {
  332. if (this.loading) return this.$message.info("请稍等");
  333. this.$message.info(`点击了语音`);
  334. },
  335. send(_text = this.text) {
  336. if (this.loading || this.chatLoading) return this.$message.info("请稍等");
  337. if (_text.trim().length == 0) return this.$message.info("请输入内容");
  338. this.chatLoading = true;
  339. if (this.choseRoleItem.assistant_id) {
  340. let _uid = uuidv4();
  341. let _item = this.choseRoleItem;
  342. this.chatList.push({
  343. loading: true,
  344. role: "user",
  345. content: `${_text}`,
  346. uid: _uid,
  347. AI: "AI",
  348. aiContent: "",
  349. oldContent: "",
  350. isShowSynchronization: false,
  351. filename: _item.headUrl,
  352. index: this.chatList.length,
  353. is_mind_map: false,
  354. fileid: _item.assistantName
  355. // createtime: new Date().toLocaleString().replaceAll("/", "-")
  356. });
  357. this.text = "";
  358. let params = {
  359. assistant_id: this.choseRoleItem.assistant_id,
  360. userId: this.userid,
  361. message: _text,
  362. session_name: `${this.courseId}-studyStudent-dialog`,
  363. uid: _uid,
  364. file_ids: []
  365. };
  366. this.ajax
  367. .post("https://gpt4.cocorobo.cn/ai_agent_park_chat_new", params)
  368. .then(res => {
  369. if (res.data.FunctionResponse.result == "发送成功") {
  370. } else {
  371. this.chatLoading = false;
  372. this.$message.warning(res.data.FunctionResponse.result);
  373. }
  374. })
  375. .catch(err => {
  376. this.chatLoading = false;
  377. console.log(err);
  378. });
  379. this.getAtAuContent(_uid);
  380. } else {
  381. let _uuid = uuidv4();
  382. this.chatList.push({
  383. role: "user",
  384. content: `${_text}`,
  385. uid: _uuid,
  386. AI: "AI",
  387. aiContent: "",
  388. oldContent: "",
  389. isShowSynchronization: false,
  390. filename: "",
  391. index: this.chatList.length,
  392. is_mind_map: false,
  393. loading: true
  394. });
  395. this.scrollBottom();
  396. let params = {
  397. model: "gpt-3.5-turbo",
  398. temperature: 0,
  399. max_tokens: 4096,
  400. top_p: 1,
  401. frequency_penalty: 0,
  402. presence_penalty: 0,
  403. messages: [{ role: "user", content: _text }],
  404. uid: _uuid,
  405. mind_map_question: ""
  406. };
  407. this.text = "";
  408. this.ajax
  409. .post("https://gpt4.cocorobo.cn/chat", params)
  410. .then(res => {
  411. if (res.data.FunctionResponse.result == "发送成功") {
  412. } else {
  413. this.chatLoading = false;
  414. this.$message.warning(res.data.FunctionResponse.result);
  415. }
  416. })
  417. .catch(e => {
  418. this.chatLoading = false;
  419. console.log(e);
  420. });
  421. this.getAiContent(_uuid);
  422. }
  423. },
  424. // 获取ai对话
  425. getAiContent(_uid) {
  426. let _source = new EventSource(`https://gpt4.cocorobo.cn/stream/${_uid}`); //http://gpt4.cocorobo.cn:8011/stream/ https://gpt4.cocorobo.cn/stream/
  427. let _allText = "";
  428. let _mdText = "";
  429. const md = new MarkdownIt();
  430. _source.onmessage = _e => {
  431. if (_e.data.replace("'", "").replace("'", "") == "[DONE]") {
  432. //对话已经完成
  433. _mdText = _mdText.replace("_", "");
  434. _source.close();
  435. this.scrollBottom();
  436. this.chatLoading = false;
  437. this.chatList.find(i => i.uid == _uid).aiContent = _mdText;
  438. this.chatList.find(i => i.uid == _uid).isalltext = true;
  439. this.chatList.find(i => i.uid == _uid).isShowSynchronization = true;
  440. this.chatList.find(i => i.uid == _uid).loading = false;
  441. // 这里保存对话
  442. this.insertChat(_uid);
  443. return;
  444. } else {
  445. //对话还在继续
  446. let _text = "";
  447. _text = _e.data.replaceAll("'", "");
  448. if (_allText == "") {
  449. _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
  450. } else {
  451. _allText += _text;
  452. }
  453. _mdText = _allText + "_";
  454. _mdText = _mdText.replace(/\\n/g, "\n");
  455. _mdText = _mdText.replace(/\\/g, "");
  456. if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
  457. //转化返回的回复流数据
  458. _mdText = md.render(_mdText);
  459. this.chatList.find(i => i.uid == _uid).aiContent = _mdText;
  460. this.chatList.find(i => i.uid == _uid).loading = false;
  461. this.scrollBottom();
  462. // 处理流数据
  463. }
  464. };
  465. },
  466. getAtAuContent(_uid) {
  467. let _source = new EventSource(
  468. `https://gpt4.cocorobo.cn/question/${_uid}`
  469. ); //http://gpt4.cocorobo.cn:8011/question/ https://gpt4.cocorobo.cn/question/
  470. let _allText = "";
  471. let _mdText = "";
  472. const md = new MarkdownIt();
  473. _source.onmessage = _e => {
  474. let _eData = JSON.parse(_e.data);
  475. if (_eData.content.replace("'", "").replace("'", "") == "[DONE]") {
  476. let _result = [];
  477. if ("result" in _eData) {
  478. _result = _eData.result;
  479. for (let i = 0; i < _result.length; i++) {
  480. _mdText = _mdText.replace(_result[i].text, _result[i].fileName);
  481. }
  482. }
  483. _mdText = _mdText.replace("_", "");
  484. this.chatLoading = false;
  485. this.chatList.find(i => i.uid == _uid).aiContent = _mdText;
  486. this.chatList.find(i => i.uid == _uid).isalltext = true;
  487. this.chatList.find(i => i.uid == _uid).isShowSynchronization = true;
  488. this.chatList.find(i => i.uid == _uid).loading = false;
  489. this.insertChat(_uid);
  490. } else {
  491. let _text = _eData.content.replace("'", "").replace("'", "");
  492. if (_allText == "") {
  493. _allText = _text.replace(/^\n+/, ""); //去掉回复消息中偶尔开头就存在的连续换行符
  494. } else {
  495. _allText += _text;
  496. }
  497. _mdText = _allText + "_";
  498. _mdText = _mdText.replace(/\\n/g, "\n");
  499. _mdText = _mdText.replace(/\\/g, "");
  500. if (_allText.split("```").length % 2 == 0) _mdText += "\n```\n";
  501. //转化返回的回复流数据
  502. _mdText = md.render(_mdText);
  503. this.chatList.find(i => i.uid == _uid).aiContent = _mdText;
  504. this.chatList.find(i => i.uid == _uid).loading = false;
  505. this.$nextTick(() => {
  506. this.$refs.chatRef.scrollTop = this.$refs.chatRef.scrollHeight;
  507. });
  508. // 处理流数据
  509. }
  510. };
  511. },
  512. //保存消息
  513. insertChat(_uid) {
  514. let _data = this.chatList.find(i => i.uid == _uid);
  515. if (!_data) return;
  516. let params = {
  517. userId: this.userid,
  518. userName: "qgt",
  519. groupId: "602def61-005d-11ee-91d8-005056b8q12w",
  520. answer: _data.aiContent,
  521. problem: _data.content,
  522. file_id: _data.fileid ? _data.fileid : "",
  523. alltext: _data.aiContent,
  524. type: "chat",
  525. filename: _data.filename,
  526. session_name: `${this.courseId}-studyStudent` //这是对话记录位置
  527. };
  528. this.ajax
  529. .post("https://gpt4.cocorobo.cn/insert_chat", params)
  530. .then(res => {});
  531. },
  532. // 获取对应的聊天记录
  533. getChatList() {
  534. return new Promise((resolve, reject) => {
  535. if (this.loading) return this.$message.info("请稍等...");
  536. this.chatList = [];
  537. this.loading = true;
  538. this.chatLoading = true;
  539. let params = {
  540. userid: this.userid,
  541. groupid: "602def61-005d-11ee-91d8-005056b8q12w",
  542. // session_name:``
  543. session_name: `${this.courseId}-studyStudent`
  544. };
  545. this.ajax
  546. .post("https://gpt4.cocorobo.cn/get_agent_park_chat", params)
  547. .then(res => {
  548. let _data = JSON.parse(res.data.FunctionResponse);
  549. if (_data.length > 0) {
  550. let _chatList = [];
  551. for (let i = 0; i < _data.length; i++) {
  552. _chatList.push({
  553. loading: false,
  554. role: "user",
  555. content: _data[i].problem,
  556. uid: _data[i].id,
  557. AI: "AI",
  558. aiContent: _data[i].answer,
  559. oldContent: _data[i].answer,
  560. isShowSynchronization: false,
  561. filename: _data[i].filename,
  562. index: i,
  563. is_mind_map: false,
  564. fileid: _data[i].fileid
  565. });
  566. }
  567. this.chatList = _chatList;
  568. this.loading = false;
  569. this.chatLoading = false;
  570. } else {
  571. //没有对话记录
  572. this.chatLoading = false;
  573. this.loading = false;
  574. }
  575. resolve();
  576. })
  577. .catch(err => {
  578. console.log(err);
  579. this.$message.error("获取对话记录失败");
  580. this.loading = false;
  581. this.chatLoading = false;
  582. resolve();
  583. });
  584. });
  585. },
  586. getRoleList() {
  587. this.roleList = [];
  588. let params = {
  589. userId: this.userid
  590. };
  591. this.ajax
  592. .post("https://gpt4.cocorobo.cn/get_ai_agent_assistant_list", params)
  593. .then(res => {
  594. let _data = res.data.FunctionResponse.result;
  595. if (_data.length == 0) return;
  596. if (_data) {
  597. this.roleList = JSON.parse(_data);
  598. }
  599. })
  600. .catch(e => {
  601. console.log("获取角色列表失败");
  602. this.roleList = [];
  603. });
  604. },
  605. getPublicRoleList() {
  606. this.roleList2 = [];
  607. let params = {
  608. userId: this.userid,
  609. // organizeid: this.org,
  610. organizeid: "45facc0a-1211-11ec-80ad-005056b86db5"
  611. };
  612. this.ajax
  613. .post(
  614. "https://gpt4.cocorobo.cn/get_ai_agent_assistant_share_list",
  615. params
  616. )
  617. .then(res => {
  618. let _data = res.data.FunctionResponse.result;
  619. if (_data.length == 0) return;
  620. if (_data) {
  621. this.roleList2 = JSON.parse(_data);
  622. }
  623. })
  624. .catch(e => {
  625. this.roleList2 = [];
  626. console.log("获取公共角色失败", e);
  627. });
  628. },
  629. changeRole() {
  630. this.cardType = 0;
  631. // this.rightSubjects = this.subjectsType;
  632. // this.rightRole = this.roleType;
  633. if (this.choseRoleItem.assistant_id) {
  634. this.chatList = [];
  635. let _uuid = uuidv4();
  636. this.chatList.push({
  637. role: "user",
  638. content: `您好,${this.choseRoleItem.assistantName}`,
  639. uid: _uuid,
  640. AI: "AI",
  641. aiContent: this.choseRoleItem.prologue
  642. ? this.choseRoleItem.prologue
  643. : "您好,有什么需要我帮忙的吗?",
  644. oldContent: "",
  645. isShowSynchronization: false,
  646. filename: this.choseRoleItem.headUrl,
  647. index: this.chatList.length,
  648. is_mind_map: false,
  649. loading: false
  650. });
  651. this.scrollBottom();
  652. }
  653. // let params = {
  654. // model: "gpt-3.5-turbo",
  655. // temperature: 0,
  656. // max_tokens: 4096,
  657. // top_p: 1,
  658. // frequency_penalty: 0,
  659. // presence_penalty: 0,
  660. // messages: [{ role: "user", content: `你好,${_text}` }],
  661. // uid: _uuid,
  662. // mind_map_question: ""
  663. // };
  664. // this.text = "";
  665. // this.ajax
  666. // .post("https://gpt4.cocorobo.cn/chat", params)
  667. // .then(res => {
  668. // if (res.data.FunctionResponse.result == "发送成功") {
  669. // } else {
  670. // this.$message.warning(res.data.FunctionResponse.result);
  671. // }
  672. // })
  673. // .catch(e => {
  674. // console.log(e);
  675. // });
  676. // this.getAiContent(_uuid);
  677. // this.chatList.push({
  678. // role: "ai",
  679. // content: "", //这里需要调用接口
  680. // time: new Date().toLocaleString().replace(/\//gi, "-")
  681. // });
  682. // setTimeout(() => {
  683. // let aiContent = "你好";
  684. // switch (this.rightRole) {
  685. // case 0:
  686. // aiContent =
  687. // "你好,我是爱因斯坦,相对论的提出者,相信科学的力量可以揭示宇宙的奥秘。";
  688. // break;
  689. // case 1:
  690. // aiContent =
  691. // "你好,我是居里夫人,放射性研究的先驱,第一位获得两次诺贝尔奖的女性。";
  692. // break;
  693. // case 2:
  694. // aiContent =
  695. // "你好,我是查尔斯·达尔文,进化论的创立者,相信物种通过自然选择不断进化。";
  696. // break;
  697. // case 3:
  698. // aiContent =
  699. // "你好,我是达芬奇,文艺复兴的象征,艺术与科学的多面手。";
  700. // break;
  701. // case 4:
  702. // aiContent =
  703. // "你好,我是列文虎克,通过我的简单显微镜,开启了微生物学的大门。";
  704. // break;
  705. // case 5:
  706. // aiContent =
  707. // "你好,我是詹姆斯·瓦特,改良了蒸汽机,为工业革命提供了动力。";
  708. // break;
  709. // case 6:
  710. // aiContent =
  711. // "你好,我是瑞秋·卡森,环保运动的先驱,通过《寂静的春天》提醒世界关注环境保护。";
  712. // break;
  713. // case 7:
  714. // aiContent =
  715. // "你好,我是特斯拉,交流电的推广者,致力于无线电和电力传输的研究。";
  716. // break;
  717. // case 8:
  718. // aiContent =
  719. // "你好,我是约翰·穆尔,自然保护的倡导者,努力保护美国的森林和野生地区。";
  720. // break;
  721. // case 9:
  722. // aiContent =
  723. // "你好,我是牛顿,万有引力和三大运动定律的发现者,为现代物理学奠定了基础。";
  724. // break;
  725. // case 10:
  726. // aiContent =
  727. // "你好,我是伽利略,通过望远镜观测支持了日心说,被誉为现代观测天文学之父。";
  728. // break;
  729. // case 11:
  730. // aiContent =
  731. // "你好,我是孟德尔,遗传学的奠基人,通过豌豆实验发现了遗传的基本规律。";
  732. // break;
  733. // case 12:
  734. // aiContent =
  735. // "你好,我是张衡,东汉杰出的天文学家和科学家,发明了地动仪。";
  736. // break;
  737. // case 13:
  738. // aiContent =
  739. // "你好,我是李时珍,中国古代著名的医学家,编纂了《本草纲目》。";
  740. // break;
  741. // case 14:
  742. // aiContent =
  743. // "你好,我是钱学森,现代火箭科学的奠基人之一,被誉为“中国航天之父”。";
  744. // break;
  745. // case 15:
  746. // aiContent =
  747. // "你好,我是阿基米德,古希腊的数学家和物理学家,提出了浮力原理。";
  748. // break;
  749. // case 16:
  750. // aiContent =
  751. // "你好,我是斯蒂芬·霍金,研究黑洞和宇宙起源,致力于解释宇宙的奥秘。";
  752. // break;
  753. // case 17:
  754. // aiContent =
  755. // "你好,我是蔡伦,东汉时期改进了造纸术,使纸张更加广泛地应用于社会。";
  756. // break;
  757. // case 18:
  758. // aiContent =
  759. // "你好,我是詹姆斯·瓦特,改良了蒸汽机,为工业革命提供了动力。";
  760. // break;
  761. // case 19:
  762. // aiContent =
  763. // "你好,我是路易·巴斯德,微生物学的奠基人,发现了疫苗和巴斯德消毒法。";
  764. // break;
  765. // case 20:
  766. // aiContent =
  767. // "你好,我是诺贝尔,发明了炸药,为和平与科学的贡献设立了诺贝尔奖。";
  768. // break;
  769. // case 21:
  770. // aiContent =
  771. // "你好,我是麦克斯韦,统一了电磁理论,提出了麦克斯韦方程组。";
  772. // break;
  773. // case 22:
  774. // aiContent =
  775. // "你好,我是贝尔,电话的发明者,致力于通信技术的发展和听力障碍人士的教育。";
  776. // break;
  777. // case 23:
  778. // aiContent =
  779. // "你好,我是开普勒,行星运动三大定律的发现者,为天文学和物理学的发展做出了重要贡献。";
  780. // break;
  781. // case 24:
  782. // aiContent =
  783. // "你好,我是安培,电磁学的先驱之一,提出了电流的磁效应。";
  784. // break;
  785. // }
  786. // this.chatList[this.chatList.length - 1].content = aiContent;
  787. // this.chatList[
  788. // this.chatList.length - 1
  789. // ].time = new Date().toLocaleString().replace(/\//gi, "-");
  790. // this.loading = false;
  791. // }, 2000);
  792. },
  793. choseRole(item) {
  794. this.choseRoleItem = item;
  795. },
  796. noChangeRole() {
  797. this.cardType = 0;
  798. // this.subjectsType = this.rightSubjects;
  799. // this.roleType = this.rightRole;
  800. },
  801. scrollBottom() {
  802. this.$nextTick(() => {
  803. this.$refs.chatRef.scrollTop = this.$refs.chatRef.scrollHeight;
  804. });
  805. }
  806. },
  807. mounted() {
  808. this.getRoleList();
  809. this.getPublicRoleList();
  810. this.getChatList().then(_ => {
  811. this.scrollBottom();
  812. });
  813. }
  814. };
  815. </script>
  816. <style scoped>
  817. .dialog {
  818. width: 100%;
  819. height: 100%;
  820. box-sizing: border-box;
  821. }
  822. .dialog > div {
  823. width: 100%;
  824. height: 100%;
  825. }
  826. .characterBlock {
  827. display: flex;
  828. background: rgba(54, 169, 252, 1);
  829. width: 100%;
  830. height: 80px;
  831. margin: 0 auto;
  832. border-radius: 10px;
  833. margin-bottom: 15px;
  834. cursor: pointer;
  835. }
  836. .characterBlock > .imgLeft {
  837. width: 100px;
  838. display: flex;
  839. justify-content: center;
  840. align-items: center;
  841. }
  842. .characterBlock > .imgLeft > .img {
  843. width: 60px;
  844. height: 60px;
  845. overflow: hidden;
  846. border-radius: 50%;
  847. }
  848. .characterBlock > .imgLeft > .img2 {
  849. width: 70px;
  850. height: 70px;
  851. overflow: hidden;
  852. border-radius: 50%;
  853. }
  854. .characterBlock > .txtRight {
  855. flex: 1;
  856. display: flex;
  857. justify-content: flex-start;
  858. align-items: center;
  859. }
  860. .characterBlock > .txtRight > .bir {
  861. width: 180px;
  862. height: 35px;
  863. display: flex;
  864. align-items: center;
  865. background-color: #fff;
  866. border-radius: 10px;
  867. box-sizing: border-box;
  868. padding: 5px 10px;
  869. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  870. margin-right: 10px;
  871. white-space: nowrap;
  872. overflow: hidden;
  873. text-overflow: ellipsis;
  874. }
  875. .d_top {
  876. width: 100%;
  877. height: calc(100% - 90px);
  878. overflow: auto;
  879. box-sizing: border-box;
  880. padding: 20px 0;
  881. }
  882. .d_t_chat {
  883. width: 100%;
  884. display: flex;
  885. box-sizing: border-box;
  886. padding: 10px;
  887. flex-direction: column;
  888. }
  889. .d_t_chat > div {
  890. display: flex;
  891. align-items: flex-start;
  892. width: 100%;
  893. }
  894. .d_t_c_user {
  895. box-sizing: border-box;
  896. padding-left: 35px;
  897. }
  898. .d_t_c_u_left {
  899. width: 90%;
  900. height: auto;
  901. }
  902. .d_t_c_u_l_content {
  903. width: auto;
  904. max-width: 100%;
  905. height: auto;
  906. box-sizing: border-box;
  907. padding: 10px;
  908. color: white;
  909. background-color: #3681fc;
  910. border-radius: 8px 2px 8px 8px;
  911. white-space: pre-line;
  912. }
  913. .d_t_c_u_l_time {
  914. width: 100%;
  915. display: flex;
  916. justify-content: flex-end;
  917. font-size: 12px;
  918. color: #9f9f9f;
  919. margin-top: 5px;
  920. }
  921. .d_t_c_u_right {
  922. width: 35px;
  923. height: 35px;
  924. display: flex;
  925. justify-content: center;
  926. margin-left: 5px;
  927. }
  928. .d_t_c_u_right > span {
  929. width: 32px;
  930. height: 32px;
  931. display: flex;
  932. justify-content: center;
  933. align-items: center;
  934. color: white;
  935. background-color: #3681fc;
  936. border-radius: 50%;
  937. }
  938. .d_t_c_ai {
  939. box-sizing: border-box;
  940. padding-right: 35px;
  941. margin-top: 10px;
  942. }
  943. .d_t_c_a_right {
  944. min-width: 90%;
  945. height: auto;
  946. }
  947. .d_t_c_a_r_content {
  948. width: auto;
  949. max-width: 100%;
  950. height: auto;
  951. box-sizing: border-box;
  952. padding: 10px;
  953. background-color: #f6f8ff;
  954. border-radius: 2px 8px 8px 8px;
  955. white-space: pre-line;
  956. word-break: break-all;
  957. }
  958. .d_t_c_a_r_time {
  959. width: 100%;
  960. display: flex;
  961. justify-content: flex-start;
  962. font-size: 12px;
  963. color: #9f9f9f;
  964. margin-top: 5px;
  965. }
  966. .d_t_c_a_left {
  967. width: 35px;
  968. height: 35px;
  969. display: flex;
  970. justify-content: center;
  971. margin-right: 5px;
  972. }
  973. .d_t_c_a_left > span {
  974. width: 32px;
  975. height: 32px;
  976. display: flex;
  977. justify-content: center;
  978. align-items: center;
  979. color: white;
  980. background-color: #3681fc;
  981. border-radius: 50%;
  982. }
  983. .d_bottom {
  984. width: 100%;
  985. height: 90px;
  986. display: flex;
  987. flex-direction: column;
  988. justify-content: space-between;
  989. }
  990. .d_b_btnArea {
  991. width: 100%;
  992. height: 30px;
  993. display: flex;
  994. align-items: center;
  995. box-sizing: border-box;
  996. padding: 0 10px;
  997. }
  998. .d_b_ba-item {
  999. width: auto;
  1000. box-sizing: border-box;
  1001. padding: 0 10px;
  1002. height: 25px;
  1003. background-color: white;
  1004. display: flex;
  1005. justify-content: center;
  1006. align-items: center;
  1007. /* 阴影 */
  1008. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.363);
  1009. border-radius: 15px;
  1010. font-size: 14px;
  1011. cursor: pointer;
  1012. }
  1013. .d_b_inputArea {
  1014. width: 100%;
  1015. height: 55px;
  1016. box-sizing: border-box;
  1017. border-top: solid 1px #ededed;
  1018. display: flex;
  1019. justify-content: space-between;
  1020. padding-right: 10px;
  1021. align-items: center;
  1022. }
  1023. .d_b_tape {
  1024. width: 35px;
  1025. height: 35px;
  1026. background: url("../../../assets/icon/course/tape.png") no-repeat;
  1027. background-size: 50% 60%;
  1028. background-position: center;
  1029. cursor: pointer;
  1030. }
  1031. .d_b_input {
  1032. /* width: 75%; */
  1033. flex: 1;
  1034. height: 45px;
  1035. background-color: #f3f3f3;
  1036. border-radius: 50px;
  1037. margin: 0 10px;
  1038. display: flex;
  1039. overflow: hidden;
  1040. align-items: center;
  1041. }
  1042. .d_b_i_left {
  1043. width: 100%;
  1044. line-height: 45px;
  1045. height: 100%;
  1046. }
  1047. .d_b_i_left >>> .el-input__inner {
  1048. border: none;
  1049. background-color: #f3f3f3;
  1050. outline: none;
  1051. border-radius: 50px 0 0 50px;
  1052. }
  1053. .d_b_i_right {
  1054. width: 45px;
  1055. height: 45px;
  1056. display: flex;
  1057. justify-content: center;
  1058. align-items: center;
  1059. }
  1060. .d_b_i_right > span {
  1061. width: 35px;
  1062. height: 35px;
  1063. background: url("../../../assets/icon/course/file.png") no-repeat;
  1064. background-size: 50% 60%;
  1065. background-position: center;
  1066. cursor: pointer;
  1067. }
  1068. .d_b_btn {
  1069. width: 40px;
  1070. height: 40px;
  1071. background-color: #3681fc;
  1072. display: flex;
  1073. justify-content: center;
  1074. align-items: center;
  1075. border-radius: 50%;
  1076. cursor: pointer;
  1077. }
  1078. .d_b_btn > span {
  1079. width: 30px;
  1080. height: 30px;
  1081. background: url("../../../assets/icon/course/send.png") no-repeat;
  1082. background-size: 70% 70%;
  1083. background-position: center;
  1084. }
  1085. .choiceTop {
  1086. width: 100%;
  1087. height: 95%;
  1088. overflow-x: hidden;
  1089. box-sizing: border-box;
  1090. padding: 10px;
  1091. }
  1092. .choiceBottom {
  1093. width: 100%;
  1094. height: 5%;
  1095. display: flex;
  1096. align-items: center;
  1097. justify-content: flex-end;
  1098. }
  1099. .cb_btn {
  1100. margin: 0 10px;
  1101. }
  1102. .choiceRoleHeader {
  1103. width: 100%;
  1104. /* margin: 10px; */
  1105. margin-bottom: 20px;
  1106. }
  1107. .choiceRoleHeader > div {
  1108. font-size: 16px;
  1109. font-weight: bold;
  1110. }
  1111. .choiceRoleHeader > span {
  1112. font-size: 14px;
  1113. }
  1114. .choiceSelect {
  1115. width: 100%;
  1116. display: flex;
  1117. height: 35px;
  1118. justify-content: flex-start;
  1119. align-items: center;
  1120. margin: 15px 0;
  1121. }
  1122. .choiceSelect > .option {
  1123. width: 80px;
  1124. height: 100%;
  1125. border-radius: 5px;
  1126. margin-right: 10px;
  1127. display: flex;
  1128. justify-content: center;
  1129. align-items: center;
  1130. cursor: pointer;
  1131. }
  1132. .filterSubjects {
  1133. margin: 10px;
  1134. width: 100%;
  1135. height: auto;
  1136. }
  1137. .fs_box {
  1138. width: 100%;
  1139. display: flex;
  1140. flex-wrap: wrap;
  1141. margin-top: 10px;
  1142. }
  1143. .fs_b_item {
  1144. width: auto;
  1145. height: 35px;
  1146. font-size: 14px;
  1147. box-sizing: border-box;
  1148. padding: 0 9px;
  1149. background-color: #f3f7fd;
  1150. border: solid 1px #f3f7fd;
  1151. border-radius: 5px;
  1152. margin-right: 8px;
  1153. margin-bottom: 8px;
  1154. display: flex;
  1155. justify-content: center;
  1156. align-items: center;
  1157. cursor: pointer;
  1158. }
  1159. .fs_b_itemActive {
  1160. border: solid 1px #4d8ffc;
  1161. color: #4d8ffc;
  1162. background-color: #f3f7fd;
  1163. }
  1164. .roleList {
  1165. width: 100%;
  1166. height: auto;
  1167. margin: 10px;
  1168. }
  1169. .r_box {
  1170. width: 100%;
  1171. height: auto;
  1172. display: flex;
  1173. flex-wrap: wrap;
  1174. }
  1175. .r_b_item {
  1176. height: 40px;
  1177. font-size: 14px;
  1178. display: flex;
  1179. /* justify-content: center; */
  1180. align-items: center;
  1181. background-color: #f0f2f5;
  1182. border-radius: 5px;
  1183. margin: 5px;
  1184. cursor: pointer;
  1185. box-sizing: border-box;
  1186. padding: 0 4px;
  1187. border: solid 1px #f0f2f5;
  1188. }
  1189. .r_b_itemActive {
  1190. box-sizing: border-box;
  1191. border: solid 1px #aeccfe;
  1192. color: #4d8ffb;
  1193. }
  1194. .r_b_item > img {
  1195. min-width: 24px;
  1196. min-height: 24px;
  1197. width: 24px;
  1198. height: 24px;
  1199. border-radius: 50%;
  1200. margin-right: 10px;
  1201. /* margin-left: 10px; */
  1202. }
  1203. </style>