forked from XiaoMo/ChatGPT-Next-Web
Merge branch 'Yidadaa:main' into main
This commit is contained in:
commit
ec88785b6d
5
.github/workflows/sync.yml
vendored
5
.github/workflows/sync.yml
vendored
@ -1,5 +1,8 @@
|
|||||||
name: Upstream Sync
|
name: Upstream Sync
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 */6 * * *" # every 6 hours
|
- cron: "0 */6 * * *" # every 6 hours
|
||||||
@ -12,7 +15,7 @@ jobs:
|
|||||||
if: ${{ github.event.repository.fork }}
|
if: ${{ github.event.repository.fork }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Step 1: run a standard checkout action, provided by github
|
# Step 1: run a standard checkout action
|
||||||
- name: Checkout target repo
|
- name: Checkout target repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
@ -370,7 +370,8 @@ export function Chat(props: {
|
|||||||
chatStore.onUserInput(userInput).then(() => setIsLoading(false));
|
chatStore.onUserInput(userInput).then(() => setIsLoading(false));
|
||||||
setUserInput("");
|
setUserInput("");
|
||||||
setPromptHints([]);
|
setPromptHints([]);
|
||||||
inputRef.current?.focus();
|
if (!isMobileScreen()) inputRef.current?.focus();
|
||||||
|
setAutoScroll(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// stop response
|
// stop response
|
||||||
@ -507,7 +508,10 @@ export function Chat(props: {
|
|||||||
bordered
|
bordered
|
||||||
title={Locale.Chat.Actions.Export}
|
title={Locale.Chat.Actions.Export}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
exportMessages(session.messages, session.topic);
|
exportMessages(
|
||||||
|
session.messages.filter((msg) => !msg.isError),
|
||||||
|
session.topic,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -524,7 +528,11 @@ export function Chat(props: {
|
|||||||
className={styles["chat-body"]}
|
className={styles["chat-body"]}
|
||||||
ref={scrollRef}
|
ref={scrollRef}
|
||||||
onScroll={(e) => onChatBodyScroll(e.currentTarget)}
|
onScroll={(e) => onChatBodyScroll(e.currentTarget)}
|
||||||
onTouchStart={() => inputRef.current?.blur()}
|
onWheel={() => setAutoScroll(false)}
|
||||||
|
onTouchStart={() => {
|
||||||
|
inputRef.current?.blur();
|
||||||
|
setAutoScroll(false);
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{messages.map((message, i) => {
|
{messages.map((message, i) => {
|
||||||
const isUser = message.role === "user";
|
const isUser = message.role === "user";
|
||||||
@ -585,7 +593,6 @@ export function Chat(props: {
|
|||||||
if (!isMobileScreen()) return;
|
if (!isMobileScreen()) return;
|
||||||
setUserInput(message.content);
|
setUserInput(message.content);
|
||||||
}}
|
}}
|
||||||
onMouseOver={() => inputRef.current?.blur()}
|
|
||||||
>
|
>
|
||||||
<Markdown content={message.content} />
|
<Markdown content={message.content} />
|
||||||
</div>
|
</div>
|
||||||
@ -620,9 +627,6 @@ export function Chat(props: {
|
|||||||
setAutoScroll(false);
|
setAutoScroll(false);
|
||||||
setTimeout(() => setPromptHints([]), 500);
|
setTimeout(() => setPromptHints([]), 500);
|
||||||
}}
|
}}
|
||||||
onMouseOver={() => {
|
|
||||||
inputRef.current?.focus();
|
|
||||||
}}
|
|
||||||
autoFocus={!props?.sideBarShowing}
|
autoFocus={!props?.sideBarShowing}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
|
@ -114,7 +114,7 @@ export async function requestChatStream(
|
|||||||
filterBot?: boolean;
|
filterBot?: boolean;
|
||||||
modelConfig?: ModelConfig;
|
modelConfig?: ModelConfig;
|
||||||
onMessage: (message: string, done: boolean) => void;
|
onMessage: (message: string, done: boolean) => void;
|
||||||
onError: (error: Error) => void;
|
onError: (error: Error, statusCode?: number) => void;
|
||||||
onController?: (controller: AbortController) => void;
|
onController?: (controller: AbortController) => void;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
@ -178,11 +178,10 @@ export async function requestChatStream(
|
|||||||
finish();
|
finish();
|
||||||
} else if (res.status === 401) {
|
} else if (res.status === 401) {
|
||||||
console.error("Anauthorized");
|
console.error("Anauthorized");
|
||||||
responseText = Locale.Error.Unauthorized;
|
options?.onError(new Error("Anauthorized"), res.status);
|
||||||
finish();
|
|
||||||
} else {
|
} else {
|
||||||
console.error("Stream Error", res.body);
|
console.error("Stream Error", res.body);
|
||||||
options?.onError(new Error("Stream Error"));
|
options?.onError(new Error("Stream Error"), res.status);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("NetWork Error", err);
|
console.error("NetWork Error", err);
|
||||||
|
@ -14,6 +14,7 @@ import Locale from "../locales";
|
|||||||
export type Message = ChatCompletionResponseMessage & {
|
export type Message = ChatCompletionResponseMessage & {
|
||||||
date: string;
|
date: string;
|
||||||
streaming?: boolean;
|
streaming?: boolean;
|
||||||
|
isError?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum SubmitKey {
|
export enum SubmitKey {
|
||||||
@ -351,9 +352,15 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
set(() => ({}));
|
set(() => ({}));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onError(error) {
|
onError(error, statusCode) {
|
||||||
|
if (statusCode === 401) {
|
||||||
|
botMessage.content = Locale.Error.Unauthorized;
|
||||||
|
} else {
|
||||||
botMessage.content += "\n\n" + Locale.Store.Error;
|
botMessage.content += "\n\n" + Locale.Store.Error;
|
||||||
|
}
|
||||||
botMessage.streaming = false;
|
botMessage.streaming = false;
|
||||||
|
userMessage.isError = true;
|
||||||
|
botMessage.isError = true;
|
||||||
set(() => ({}));
|
set(() => ({}));
|
||||||
ControllerPool.remove(sessionIndex, messageIndex);
|
ControllerPool.remove(sessionIndex, messageIndex);
|
||||||
},
|
},
|
||||||
@ -383,7 +390,8 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
getMessagesWithMemory() {
|
getMessagesWithMemory() {
|
||||||
const session = get().currentSession();
|
const session = get().currentSession();
|
||||||
const config = get().config;
|
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();
|
const context = session.context.slice();
|
||||||
|
|
||||||
@ -393,7 +401,7 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const recentMessages = context.concat(
|
const recentMessages = context.concat(
|
||||||
session.messages.slice(Math.max(0, n - config.historyMessageCount)),
|
messages.slice(Math.max(0, n - config.historyMessageCount)),
|
||||||
);
|
);
|
||||||
|
|
||||||
return recentMessages;
|
return recentMessages;
|
||||||
|
Loading…
Reference in New Issue
Block a user