format-dialog-answer-attached-html-before-render.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {
  2. formatRefferenceString,
  3. formatRefferenceFlag,
  4. formatFileDownloadStr
  5. } from './format-dialog-answer-custom-markdown-str';
  6. /**
  7. * 拼接到智能体回复后面的html字符串
  8. * 智能体的回答,最终呈现到界面上,共有如下几个步骤:
  9. * 1. 智能体回复的markdown
  10. * 2. 将markdown解析为html文件
  11. * 3. 在解析后的html字符串后,拼接一些特殊情况下的其他html字符串
  12. *
  13. * 此方法所做的事情就是生成上述步骤3所需要的 特殊情况下的其他html字符串
  14. * 最终将该html字符串,赋给 client_custom_attached_html_before_render 属性
  15. * 在 ../conversation-item/DialogAnswer.vue 组件中,会进行上述步骤2和步骤3的处理
  16. * @param {object} currentMsg - 前一次的消息,如果是流式消息,则需要上一次的Content进行拼接,从而形成新的消息
  17. * @returns
  18. */
  19. export default function formatDialogAnswerAttachedHtmlBeforeRender(currentMsg) {
  20. /**
  21. * 在answer字符串渲染到界面之前,在answer后拼接的html字符串
  22. */
  23. let temp_html_str = '';
  24. // 处理python代码
  25. if (currentMsg.client_custom_linked_code) {
  26. temp_html_str = temp_html_str + currentMsg.client_custom_linked_code;
  27. }
  28. // 由于SQL和代码不能通过markdown解析,所以此处进行字符串的拼接
  29. if (currentMsg.client_custom_linked_sql) {
  30. temp_html_str = temp_html_str + currentMsg.client_custom_linked_sql;
  31. }
  32. // 处理图片展示
  33. if (currentMsg.client_custom_linked_image) {
  34. temp_html_str = temp_html_str + `<img src="${currentMsg.client_custom_linked_image}" />`;
  35. }
  36. // 拼接文件的下载链接
  37. if (currentMsg.client_custom_linked_download_files) {
  38. temp_html_str = temp_html_str + `<div class="agent-answer-download-container"></div>`;
  39. // const file_name = currentMsg.client_custom_linked_download_files.file_name;
  40. // const file_url = currentMsg.client_custom_linked_download_files.file_url;
  41. // const download_file_str = formatFileDownloadStr(file_name, file_url);
  42. // temp_html_str = temp_html_str + download_file_str;
  43. }
  44. /**
  45. * 在answer字符串渲染到界面之前,在answer后拼接的html字符串
  46. */
  47. currentMsg.client_custom_attached_html_before_render = temp_html_str;
  48. return currentMsg;
  49. }