Ver Fonte

预设问题

李富豪 há 11 meses atrás
pai
commit
7b0b29360a
2 ficheiros alterados com 22 adições e 15 exclusões
  1. 15 10
      app/components/chat.tsx
  2. 7 5
      app/components/sidebar.tsx

+ 15 - 10
app/components/chat.tsx

@@ -627,6 +627,7 @@ export function ChatActions(props: {
   }
 
   useEffect(() => {
+    setGuessList([]);
     const messages = session.messages.slice();
     if (messages.length > 1) {
       const backList = messages.reverse();
@@ -659,6 +660,7 @@ export function ChatActions(props: {
                     }}
                     onClick={() => {
                       props.setUserInput(item);
+                      props.doSubmit(item)
                     }}
                     key={index}
                   >
@@ -974,11 +976,7 @@ function _Chat() {
   const [appList, setAppList] = useState<AppList>([]);
   const [appValue, setAppValue] = useState<string>();
   const globalStore = useGlobalStore();
-  type QuestionList = {
-    key: string,
-    title: string,
-    content: string,
-  }[];
+  type QuestionList = string[];
   const [questionList, setQuestionList] = useState<QuestionList>([]);
   const location = useLocation();
 
@@ -1018,9 +1016,10 @@ function _Chat() {
     }
   }
 
-  const fetchDefaultQuestion = async () => {
+  // 获取预设问题列表
+  const fetchDefaultQuestion = async (appId: string) => {
     try {
-      const res = await api.get('/bigmodel/api/presets');
+      const res = await api.get(`/bigmodel/api/presets/${appId}`);
       setQuestionList(res.data);
     } catch (error) {
       console.error(error);
@@ -1031,13 +1030,18 @@ function _Chat() {
 
   const init = async () => {
     await fetchApplicationList();
-    await fetchDefaultQuestion();
   }
 
   useEffect(() => {
     init();
   }, [])
 
+  useEffect(() => {
+    if (appValue) {
+      fetchDefaultQuestion(appValue);
+    }
+  }, [appValue])
+
   const [inputRows, setInputRows] = useState(2);
   const measure = useDebouncedCallback(
     () => {
@@ -1912,12 +1916,13 @@ function _Chat() {
                           cursor: 'pointer'
                         }}
                         onClick={() => {
-                          setUserInput(item.content)
+                          setUserInput(item)
+                          doSubmit(item)
                         }}
                         key={index}
                       >
                         <div>
-                          {item.title}
+                          {item}
                         </div>
                         <RightOutlined />
                       </div>

+ 7 - 5
app/components/sidebar.tsx

@@ -274,10 +274,11 @@ export const SideBar = (props: { className?: string }) => {
                     try {
                       await api.delete(`/bigmodel/api/dialog/del/${child.key}`);
                       await fetchChatList()
-                      chatStore.clearSessions();
-                      chatStore.updateCurrentSession((value) => {
-                        value.appId = globalStore.selectedAppId;
-                      });
+                      // 删除不需要清理消息
+                      // chatStore.clearSessions();
+                      // chatStore.updateCurrentSession((value) => {
+                      //   value.appId = globalStore.selectedAppId;
+                      // });
                     } catch (error) {
                       console.error(error);
                     }
@@ -352,12 +353,13 @@ export const SideBar = (props: { className?: string }) => {
         <Button
           type="primary"
           style={{ marginBottom: 10 }}
-          onClick={() => {
+          onClick={async () => {
             chatStore.clearSessions();
             chatStore.updateCurrentSession((value) => {
               value.appId = globalStore.selectedAppId;
             });
             navigate(Path.Chat);
+            await fetchChatList()
           }}
         >
           新建对话