perf: completions api.fix: new chat question guide (#361)

This commit is contained in:
Archer
2023-09-27 12:05:13 +08:00
committed by GitHub
parent 11848b8f44
commit ab57bfcc4a
16 changed files with 555 additions and 538 deletions

View File

@@ -27,7 +27,7 @@ import { useMarkdown } from '@/hooks/useMarkdown';
import { AppModuleItemType, VariableItemType } from '@/types/app';
import { VariableInputEnum } from '@/constants/app';
import { useForm } from 'react-hook-form';
import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
import type { MessageItemType } from '@/types/core/chat/type';
import { fileDownload } from '@/utils/web/file';
import { htmlTemplate } from '@/constants/common';
import { useRouter } from 'next/router';
@@ -158,6 +158,7 @@ const ChatBox = (
onStartChat?: (e: StartChatFnProps) => Promise<{
responseText: string;
[TaskResponseKeyEnum.responseData]: ChatHistoryItemResType[];
isNewChat?: boolean;
}>;
onDelMessage?: (e: { contentId?: string; index: number }) => void;
},
@@ -173,6 +174,7 @@ const ChatBox = (
const TextareaDom = useRef<HTMLTextAreaElement>(null);
const chatController = useRef(new AbortController());
const questionGuideController = useRef(new AbortController());
const isNewChatReplace = useRef(false);
const [refresh, setRefresh] = useState(false);
const [variables, setVariables] = useState<Record<string, any>>({}); // settings variable
@@ -381,7 +383,11 @@ const ChatBox = (
const messages = adaptChat2GptMessages({ messages: newChatList, reserveId: true });
const { responseData, responseText } = await onStartChat({
const {
responseData,
responseText,
isNewChat = false
} = await onStartChat({
chatList: newChatList,
messages,
controller: abortSignal,
@@ -389,6 +395,8 @@ const ChatBox = (
variables
});
isNewChatReplace.current = isNewChat;
// set finish status
setChatHistory((state) =>
state.map((item, index) => {
@@ -542,9 +550,12 @@ const ChatBox = (
// page change and abort request
useEffect(() => {
isNewChatReplace.current = false;
return () => {
chatController.current?.abort('leave');
questionGuideController.current?.abort('leave');
if (!isNewChatReplace.current) {
questionGuideController.current?.abort('leave');
}
// close voice
cancelBroadcast();
};

View File

@@ -171,11 +171,10 @@
.markdown ol li > *:first-child {
margin-top: 0;
}
.markdown ul ul,
.markdown ul ol,
.markdown ol ol,
.markdown ol ul {
.markdown ul,
.markdown ol {
margin-bottom: 0;
padding-left: 14px;
}
.markdown dl {
padding: 0;