diff --git a/src/constants/theme.ts b/src/constants/theme.ts index 4b4618500..ec600973e 100644 --- a/src/constants/theme.ts +++ b/src/constants/theme.ts @@ -45,8 +45,13 @@ const Button = defineStyleConfig({ } }, variants: { - outline: { - borderWidth: '1.5px' + white: { + color: '#fff', + backgroundColor: 'transparent', + border: '1px solid #ffffff', + _hover: { + backgroundColor: 'rgba(255,255,255,0.1)' + } } }, defaultProps: { diff --git a/src/pages/api/chat/chatGpt.ts b/src/pages/api/chat/chatGpt.ts index 9d9cf768e..cd2f3af9a 100644 --- a/src/pages/api/chat/chatGpt.ts +++ b/src/pages/api/chat/chatGpt.ts @@ -103,9 +103,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) } }; - for await (const chunk of chatResponse.data as any) { - const parser = createParser(onParse); - parser.feed(decodeURIComponent(chunk)); + const decoder = new TextDecoder(); + try { + for await (const chunk of chatResponse.data as any) { + const parser = createParser(onParse); + parser.feed(decoder.decode(chunk)); + } + } catch (error) { + console.log('pipe error', error); } pass.push(null); } catch (err: any) { diff --git a/src/pages/chat/components/SlideBar.tsx b/src/pages/chat/components/SlideBar.tsx new file mode 100644 index 000000000..502f129cd --- /dev/null +++ b/src/pages/chat/components/SlideBar.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Box, Button } from '@chakra-ui/react'; +import { AddIcon } from '@chakra-ui/icons'; + +const SlideBar = ({ resetChat }: { resetChat: () => void }) => { + return ( + + {/* 新对话 */} + + {/* 我的模型 */} + + {/* 历史记录 */} + + ); +}; + +export default SlideBar; diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index fbfdfee11..f470cb466 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -12,12 +12,21 @@ import { OpenAiModelEnum } from '@/constants/model'; import dynamic from 'next/dynamic'; import { useGlobalStore } from '@/store/global'; import { streamFetch } from '@/api/fetch'; +import SlideBar from './components/SlideBar'; const Markdown = dynamic(() => import('@/components/Markdown')); const textareaMinH = '22px'; -const Chat = ({ chatId, windowId }: { chatId: string; windowId?: string }) => { +const Chat = ({ + chatId, + windowId, + timeStamp +}: { + chatId: string; + windowId?: string; + timeStamp: string; +}) => { const { toast } = useToast(); const router = useRouter(); const { isPc, media } = useScreen(); @@ -45,7 +54,7 @@ const Chat = ({ chatId, windowId }: { chatId: string; windowId?: string }) => { // 初始化聊天框 useQuery( - ['initData'], + ['initData', timeStamp], () => { setLoading(true); return getInitChatSiteInfo(chatId, windowId); @@ -53,7 +62,7 @@ const Chat = ({ chatId, windowId }: { chatId: string; windowId?: string }) => { { onSuccess(res) { // 可能没有 windowId,给它设置一下 - router.replace(`/chat?chatId=${chatId}&windowId=${res.windowId}`); + router.replace(`/chat?chatId=${chatId}&windowId=${res.windowId}&timeStamp=${timeStamp}`); setChatSiteData(res.chatSite); setChatList( @@ -92,8 +101,8 @@ const Chat = ({ chatId, windowId }: { chatId: string; windowId?: string }) => { // 重载对话 const resetChat = useCallback(() => { - window.open(`/chat?chatId=${chatId}`, '_self'); - }, [chatId]); + router.push(`/chat?chatId=${chatId}&timeStamp=${Date.now()}`); + }, [chatId, router]); // gpt3 方法 const gpt3ChatPrompt = useCallback( @@ -270,156 +279,124 @@ const Chat = ({ chatId, windowId }: { chatId: string; windowId?: string }) => { }, [chatList, resetInputVal, windowId]); return ( - - {/* 头部 */} - - {chatSiteData?.name} - {/* 滚动到底部按键 */} - {ChatBox.current && ChatBox.current.scrollHeight > 2 * ChatBox.current.clientHeight && ( - - - - )} - {/* 重置按键 */} - - - {/* 聊天内容 */} - - {chatList.map((item, index) => ( - - - - /icon/logo.png - - - {item.obj === 'AI' ? ( - + + + {/* 聊天内容 */} + + {chatList.map((item, index) => ( + + + + /icon/logo.png + + + {item.obj === 'AI' ? ( + + ) : ( + {item.value} + )} + + + + ))} + + {/* 发送区 */} + + {lastWordHuman ? ( + + 对话出现了异常 + + + + + + ) : ( + + {/* 输入框 */} +