forked from XiaoMo/ChatGPT-Next-Web
Merge pull request #346 from AprilNEA/reset
The Clear Data button on the Settings page is only clear for all dialog data.
This commit is contained in:
commit
d226090926
@ -5,7 +5,7 @@ async function makeRequest(req: NextRequest) {
|
|||||||
try {
|
try {
|
||||||
const api = await requestOpenai(req);
|
const api = await requestOpenai(req);
|
||||||
const res = new NextResponse(api.body);
|
const res = new NextResponse(api.body);
|
||||||
res.headers.set('Content-Type', 'application/json');
|
res.headers.set("Content-Type", "application/json");
|
||||||
return res;
|
return res;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("[OpenAI] ", req.body, e);
|
console.error("[OpenAI] ", req.body, e);
|
||||||
|
@ -108,7 +108,7 @@ export function ChatList() {
|
|||||||
state.currentSessionIndex,
|
state.currentSessionIndex,
|
||||||
state.selectSession,
|
state.selectSession,
|
||||||
state.removeSession,
|
state.removeSession,
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -134,7 +134,7 @@ function useSubmitHandler() {
|
|||||||
|
|
||||||
const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
const shouldSubmit = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
if (e.key !== "Enter") return false;
|
if (e.key !== "Enter") return false;
|
||||||
if(e.key==='Enter' && e.nativeEvent.isComposing) return false
|
if (e.key === "Enter" && e.nativeEvent.isComposing) return false;
|
||||||
return (
|
return (
|
||||||
(config.submitKey === SubmitKey.AltEnter && e.altKey) ||
|
(config.submitKey === SubmitKey.AltEnter && e.altKey) ||
|
||||||
(config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
|
(config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
|
||||||
@ -202,7 +202,7 @@ export function Chat(props: {
|
|||||||
setPromptHints(promptStore.search(text));
|
setPromptHints(promptStore.search(text));
|
||||||
},
|
},
|
||||||
100,
|
100,
|
||||||
{ leading: true, trailing: true }
|
{ leading: true, trailing: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
const onPromptSelect = (prompt: Prompt) => {
|
const onPromptSelect = (prompt: Prompt) => {
|
||||||
@ -216,7 +216,7 @@ export function Chat(props: {
|
|||||||
if (!dom) return;
|
if (!dom) return;
|
||||||
const paddingBottomNum: number = parseInt(
|
const paddingBottomNum: number = parseInt(
|
||||||
window.getComputedStyle(dom).paddingBottom,
|
window.getComputedStyle(dom).paddingBottom,
|
||||||
10
|
10,
|
||||||
);
|
);
|
||||||
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
|
dom.scrollTop = dom.scrollHeight - dom.offsetHeight + paddingBottomNum;
|
||||||
};
|
};
|
||||||
@ -304,7 +304,7 @@ export function Chat(props: {
|
|||||||
preview: true,
|
preview: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []
|
: [],
|
||||||
)
|
)
|
||||||
.concat(
|
.concat(
|
||||||
userInput.length > 0
|
userInput.length > 0
|
||||||
@ -316,7 +316,7 @@ export function Chat(props: {
|
|||||||
preview: true,
|
preview: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []
|
: [],
|
||||||
);
|
);
|
||||||
|
|
||||||
// auto scroll
|
// auto scroll
|
||||||
@ -354,7 +354,7 @@ export function Chat(props: {
|
|||||||
const newTopic = prompt(Locale.Chat.Rename, session.topic);
|
const newTopic = prompt(Locale.Chat.Rename, session.topic);
|
||||||
if (newTopic && newTopic !== session.topic) {
|
if (newTopic && newTopic !== session.topic) {
|
||||||
chatStore.updateCurrentSession(
|
chatStore.updateCurrentSession(
|
||||||
(session) => (session.topic = newTopic!)
|
(session) => (session.topic = newTopic!),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
@ -603,7 +603,7 @@ export function Home() {
|
|||||||
state.newSession,
|
state.newSession,
|
||||||
state.currentSessionIndex,
|
state.currentSessionIndex,
|
||||||
state.removeSession,
|
state.removeSession,
|
||||||
]
|
],
|
||||||
);
|
);
|
||||||
const loading = !useHasHydrated();
|
const loading = !useHasHydrated();
|
||||||
const [showSideBar, setShowSideBar] = useState(true);
|
const [showSideBar, setShowSideBar] = useState(true);
|
||||||
|
@ -49,14 +49,14 @@ function SettingItem(props: {
|
|||||||
|
|
||||||
export function Settings(props: { closeSettings: () => void }) {
|
export function Settings(props: { closeSettings: () => void }) {
|
||||||
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
const [showEmojiPicker, setShowEmojiPicker] = useState(false);
|
||||||
const [config, updateConfig, resetConfig, clearAllData] = useChatStore(
|
const [config, updateConfig, resetConfig, clearAllData, clearSessions] =
|
||||||
(state) => [
|
useChatStore((state) => [
|
||||||
state.config,
|
state.config,
|
||||||
state.updateConfig,
|
state.updateConfig,
|
||||||
state.resetConfig,
|
state.resetConfig,
|
||||||
state.clearAllData,
|
state.clearAllData,
|
||||||
],
|
state.clearSessions,
|
||||||
);
|
]);
|
||||||
|
|
||||||
const updateStore = useUpdateStore();
|
const updateStore = useUpdateStore();
|
||||||
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
const [checkingUpdate, setCheckingUpdate] = useState(false);
|
||||||
@ -120,7 +120,7 @@ export function Settings(props: { closeSettings: () => void }) {
|
|||||||
<div className={styles["window-action-button"]}>
|
<div className={styles["window-action-button"]}>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<ClearIcon />}
|
icon={<ClearIcon />}
|
||||||
onClick={clearAllData}
|
onClick={clearSessions}
|
||||||
bordered
|
bordered
|
||||||
title={Locale.Settings.Actions.ClearAll}
|
title={Locale.Settings.Actions.ClearAll}
|
||||||
/>
|
/>
|
||||||
|
@ -143,11 +143,13 @@ const es: LocaleType = {
|
|||||||
Summarize:
|
Summarize:
|
||||||
"Resuma nuestra discusión brevemente en 50 caracteres o menos para usarlo como un recordatorio para futuros contextos.",
|
"Resuma nuestra discusión brevemente en 50 caracteres o menos para usarlo como un recordatorio para futuros contextos.",
|
||||||
},
|
},
|
||||||
ConfirmClearAll: "¿Confirmar para borrar todos los datos de chat y configuración?",
|
ConfirmClearAll:
|
||||||
|
"¿Confirmar para borrar todos los datos de chat y configuración?",
|
||||||
},
|
},
|
||||||
Copy: {
|
Copy: {
|
||||||
Success: "Copiado al portapapeles",
|
Success: "Copiado al portapapeles",
|
||||||
Failed: "La copia falló, por favor concede permiso para acceder al portapapeles",
|
Failed:
|
||||||
|
"La copia falló, por favor concede permiso para acceder al portapapeles",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import { filterConfig, Message, ModelConfig, useAccessStore } from "./store";
|
|||||||
import Locale from "./locales";
|
import Locale from "./locales";
|
||||||
|
|
||||||
if (!Array.prototype.at) {
|
if (!Array.prototype.at) {
|
||||||
require('array.prototype.at/auto');
|
require("array.prototype.at/auto");
|
||||||
}
|
}
|
||||||
|
|
||||||
const TIME_OUT_MS = 30000;
|
const TIME_OUT_MS = 30000;
|
||||||
@ -13,7 +13,7 @@ const makeRequestParam = (
|
|||||||
options?: {
|
options?: {
|
||||||
filterBot?: boolean;
|
filterBot?: boolean;
|
||||||
stream?: boolean;
|
stream?: boolean;
|
||||||
}
|
},
|
||||||
): ChatRequest => {
|
): ChatRequest => {
|
||||||
let sendMessages = messages.map((v) => ({
|
let sendMessages = messages.map((v) => ({
|
||||||
role: v.role,
|
role: v.role,
|
||||||
@ -74,7 +74,7 @@ export async function requestChat(messages: Message[]) {
|
|||||||
|
|
||||||
export async function requestUsage() {
|
export async function requestUsage() {
|
||||||
const res = await requestOpenaiClient(
|
const res = await requestOpenaiClient(
|
||||||
"dashboard/billing/credit_grants?_vercel_no_cache=1"
|
"dashboard/billing/credit_grants?_vercel_no_cache=1",
|
||||||
)(null, "GET");
|
)(null, "GET");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -97,7 +97,7 @@ export async function requestChatStream(
|
|||||||
onMessage: (message: string, done: boolean) => void;
|
onMessage: (message: string, done: boolean) => void;
|
||||||
onError: (error: Error) => void;
|
onError: (error: Error) => void;
|
||||||
onController?: (controller: AbortController) => void;
|
onController?: (controller: AbortController) => void;
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
const req = makeRequestParam(messages, {
|
const req = makeRequestParam(messages, {
|
||||||
stream: true,
|
stream: true,
|
||||||
@ -192,7 +192,7 @@ export const ControllerPool = {
|
|||||||
addController(
|
addController(
|
||||||
sessionIndex: number,
|
sessionIndex: number,
|
||||||
messageIndex: number,
|
messageIndex: number,
|
||||||
controller: AbortController
|
controller: AbortController,
|
||||||
) {
|
) {
|
||||||
const key = this.key(sessionIndex, messageIndex);
|
const key = this.key(sessionIndex, messageIndex);
|
||||||
this.controllers[key] = controller;
|
this.controllers[key] = controller;
|
||||||
|
@ -12,7 +12,7 @@ import { trimTopic } from "../utils";
|
|||||||
import Locale from "../locales";
|
import Locale from "../locales";
|
||||||
|
|
||||||
if (!Array.prototype.at) {
|
if (!Array.prototype.at) {
|
||||||
require('array.prototype.at/auto');
|
require("array.prototype.at/auto");
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Message = ChatCompletionResponseMessage & {
|
export type Message = ChatCompletionResponseMessage & {
|
||||||
@ -189,6 +189,7 @@ interface ChatStore {
|
|||||||
config: ChatConfig;
|
config: ChatConfig;
|
||||||
sessions: ChatSession[];
|
sessions: ChatSession[];
|
||||||
currentSessionIndex: number;
|
currentSessionIndex: number;
|
||||||
|
clearSessions: () => void;
|
||||||
removeSession: (index: number) => void;
|
removeSession: (index: number) => void;
|
||||||
selectSession: (index: number) => void;
|
selectSession: (index: number) => void;
|
||||||
newSession: () => void;
|
newSession: () => void;
|
||||||
@ -227,6 +228,13 @@ export const useChatStore = create<ChatStore>()(
|
|||||||
...DEFAULT_CONFIG,
|
...DEFAULT_CONFIG,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearSessions() {
|
||||||
|
set(() => ({
|
||||||
|
sessions: [createEmptySession()],
|
||||||
|
currentSessionIndex: 0,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
resetConfig() {
|
resetConfig() {
|
||||||
set(() => ({ config: { ...DEFAULT_CONFIG } }));
|
set(() => ({ config: { ...DEFAULT_CONFIG } }));
|
||||||
},
|
},
|
||||||
|
@ -99,19 +99,19 @@ export const usePromptStore = create<PromptStore>()(
|
|||||||
({
|
({
|
||||||
title,
|
title,
|
||||||
content,
|
content,
|
||||||
} as Prompt)
|
} as Prompt),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.concat([...(state?.prompts?.values() ?? [])]);
|
.concat([...(state?.prompts?.values() ?? [])]);
|
||||||
|
|
||||||
const allPromptsForSearch = builtinPrompts.reduce(
|
const allPromptsForSearch = builtinPrompts.reduce(
|
||||||
(pre, cur) => pre.concat(cur),
|
(pre, cur) => pre.concat(cur),
|
||||||
[]
|
[],
|
||||||
);
|
);
|
||||||
SearchService.count.builtin = res.en.length + res.cn.length;
|
SearchService.count.builtin = res.en.length + res.cn.length;
|
||||||
SearchService.init(allPromptsForSearch);
|
SearchService.init(allPromptsForSearch);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user