Merge pull request #401 from cyhhao/pr2

fix: context message should exclude all error tips
This commit is contained in:
Yifei Zhang
2023-04-03 14:26:32 +08:00
committed by GitHub
3 changed files with 19 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ import Locale from "../locales";
export type Message = ChatCompletionResponseMessage & {
date: string;
streaming?: boolean;
isError?: boolean;
};
export enum SubmitKey {
@@ -351,9 +352,15 @@ export const useChatStore = create<ChatStore>()(
set(() => ({}));
}
},
onError(error) {
botMessage.content += "\n\n" + Locale.Store.Error;
onError(error, statusCode) {
if (statusCode === 401) {
botMessage.content = Locale.Error.Unauthorized;
} else {
botMessage.content += "\n\n" + Locale.Store.Error;
}
botMessage.streaming = false;
userMessage.isError = true;
botMessage.isError = true;
set(() => ({}));
ControllerPool.remove(sessionIndex, messageIndex);
},
@@ -383,7 +390,8 @@ export const useChatStore = create<ChatStore>()(
getMessagesWithMemory() {
const session = get().currentSession();
const config = get().config;
const n = session.messages.length;
const messages = session.messages.filter((msg) => !msg.isError);
const n = messages.length;
const context = session.context.slice();
@@ -393,7 +401,7 @@ export const useChatStore = create<ChatStore>()(
}
const recentMessages = context.concat(
session.messages.slice(Math.max(0, n - config.historyMessageCount)),
messages.slice(Math.max(0, n - config.historyMessageCount)),
);
return recentMessages;