Răsfoiți Sursa

feat: 优化history

zhuozh 9 luni în urmă
părinte
comite
719b7d36da
1 a modificat fișierele cu 15 adăugiri și 2 ștergeri
  1. 15 2
      src/pages/home/index.tsx

+ 15 - 2
src/pages/home/index.tsx

@@ -152,6 +152,20 @@ const Home: React.FC = () => {
     setbtnLoading(false);
   };
 
+  /**
+   * 获取历史记录的结构数据
+   * @param list
+   */
+  const getHistory = (list: any) => {
+    const rtnList: any[] = [];
+    for (let i = 0; i < list?.length; i++) {
+      rtnList.push({ role: '用户', text: list[i].problem, time: '' });
+      rtnList.push({ role: '聊天机器人', text: list[i].rtnResult, time: '' });
+    }
+
+    return rtnList;
+  };
+
   /**
    * 获取闲聊的搜索结果
    */
@@ -169,8 +183,7 @@ const Home: React.FC = () => {
             {
               text_id: getUuid(),
               text: content,
-              history:
-                curDialogue?.msgList?.map((item: any) => item.problem) || [],
+              history: getHistory(curDialogue?.msgList),
             },
           ],
         }),