Browse Source

尝试提问

李富豪 11 months ago
parent
commit
1f27396bd2
2 changed files with 76 additions and 9 deletions
  1. 74 7
      app/components/chat.tsx
  2. 2 2
      app/components/sidebar.tsx

+ 74 - 7
app/components/chat.tsx

@@ -574,10 +574,14 @@ export function ChatActions(props: {
   const [showPluginSelector, setShowPluginSelector] = useState(false);
   const [showUploadImage, setShowUploadImage] = useState(false);
 
+  type GuessList = string[]
+  const [guessList, setGuessList] = useState<GuessList>([]);
+
   const [showSizeSelector, setShowSizeSelector] = useState(false);
   const dalle3Sizes: DalleSize[] = ["1024x1024", "1792x1024", "1024x1792"];
   const currentSize =
     chatStore.currentSession().mask.modelConfig?.size ?? "1024x1024";
+  const session = chatStore.currentSession();
 
   useEffect(() => {
     const show = isVisionModel(currentModel);
@@ -605,8 +609,67 @@ export function ChatActions(props: {
     }
   }, [chatStore, currentModel, models]);
 
+  const fetchGuessList = async (record: ChatMessage) => {
+    try {
+      const data = {
+        messages: [
+          {
+            content: record.content,
+            role: record.role,
+          }
+        ]
+      }
+      const res = await api.post('/bigmodel/api/async/completions', data);
+      setGuessList(res.data);
+    } catch (error) {
+      console.error(error);
+    }
+  }
+
+  useEffect(() => {
+    const messages = session.messages.slice();
+    if (messages.length > 1) {
+      const backList = messages.reverse();
+      const item = backList.find(item => item.content && item.role === 'assistant')
+      if (!item) {
+        return
+      }
+      fetchGuessList(item)
+    }
+  }, [session.messages]);
+
   return (
     <div className={styles["chat-input-actions"]}>
+      {guessList.length > 0 && (
+        <div style={{ color: '#8096ca', fontSize: 13 }}>
+          <div>
+            你还可以尝试提问:
+          </div>
+          <div style={{ display: 'flex', marginTop: 10, flexWrap: 'wrap' }}>
+            {
+              guessList.map((item, index) => {
+                return (
+                  <div
+                    style={{
+                      padding: '5px 10px',
+                      background: '#f2f4f8',
+                      borderRadius: 5,
+                      margin: '0 10px 10px 0',
+                      cursor: 'pointer',
+                    }}
+                    onClick={() => {
+                      props.setUserInput(item);
+                    }}
+                    key={index}
+                  >
+                    {item}
+                  </div>
+                )
+              })
+            }
+          </div>
+        </div>
+      )}
       {/* {couldStop && (
         <ChatAction
           onClick={stopAll}
@@ -615,13 +678,13 @@ export function ChatActions(props: {
         />
       )} */}
 
-      {!props.hitBottom && (
+      {/* {!props.hitBottom && (
         <ChatAction
           onClick={props.scrollToBottom}
           text={Locale.Chat.InputActions.ToBottom}
           icon={<BottomIcon />}
         />
-      )}
+      )} */}
 
       {/* {props.hitBottom && (
         <ChatAction
@@ -631,13 +694,13 @@ export function ChatActions(props: {
         />
       )} */}
 
-      {showUploadImage && (
+      {/* {showUploadImage && (
         <ChatAction
           onClick={props.uploadImage}
           text={Locale.Chat.InputActions.UploadImage}
           icon={props.uploading ? <LoadingButtonIcon /> : <ImageIcon />}
         />
-      )}
+      )} */}
 
       {/* <ChatAction
         onClick={nextTheme}
@@ -911,7 +974,11 @@ function _Chat() {
   const [appList, setAppList] = useState<AppList>([]);
   const [appValue, setAppValue] = useState<string>();
   const globalStore = useGlobalStore();
-  type QuestionList = any[];
+  type QuestionList = {
+    key: string,
+    title: string,
+    content: string,
+  }[];
   const [questionList, setQuestionList] = useState<QuestionList>([]);
   const location = useLocation();
 
@@ -1845,12 +1912,12 @@ function _Chat() {
                           cursor: 'pointer'
                         }}
                         onClick={() => {
-                          setUserInput(item)
+                          setUserInput(item.content)
                         }}
                         key={index}
                       >
                         <div>
-                          {item}
+                          {item.title}
                         </div>
                         <RightOutlined />
                       </div>

+ 2 - 2
app/components/sidebar.tsx

@@ -325,7 +325,7 @@ export const SideBar = (props: { className?: string }) => {
     >
       <SideBarHeader
         title="问答历史"
-        logo={<img style={{ marginTop: '10%', marginRight: '10px', height: 42 }} src={faviconSrc.src} />}
+        logo={<img style={{ height: 40 }} src={faviconSrc.src} />}
       >
         {/* <div className={styles["sidebar-header-bar"]}>
           <IconButton
@@ -351,7 +351,7 @@ export const SideBar = (props: { className?: string }) => {
         </div> */}
         <Button
           type="primary"
-          style={{ marginBottom: 20 }}
+          style={{ marginBottom: 10 }}
           onClick={() => {
             chatStore.clearSessions();
             chatStore.updateCurrentSession((value) => {