From b56a55e81ded056ee8222689f523d57ca7b21738 Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 28 Jun 2023 20:46:21 +0800 Subject: [PATCH] Completion Regenerate Button --- frontend/src/_locales/zh-hans/main.json | 3 ++- frontend/src/pages/Completion.tsx | 16 +++++++++++++++- frontend/src/stores/commonStore.ts | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 43f4abf..e011b60 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -188,5 +188,6 @@ "New": "新建", "user": "用户", "assistant": "AI", - "system": "系统" + "system": "系统", + "Regenerate": "重新生成" } \ No newline at end of file diff --git a/frontend/src/pages/Completion.tsx b/frontend/src/pages/Completion.tsx index f9911b6..6cb5fe7 100644 --- a/frontend/src/pages/Completion.tsx +++ b/frontend/src/pages/Completion.tsx @@ -11,6 +11,8 @@ import { fetchEventSource } from '@microsoft/fetch-event-source'; import { toast } from 'react-toastify'; import { DialogButton } from '../components/DialogButton'; import { PresetsButton } from './PresetsManager/PresetsButton'; +import { ToolTipButton } from '../components/ToolTipButton'; +import { ArrowSync20Regular } from '@fluentui/react-icons'; export type CompletionParams = Omit & { stop: string, @@ -150,6 +152,7 @@ const CompletionPanel: FC = observer(() => { }, []); const setPreset = (preset: CompletionPreset) => { + commonStore.setCompletionSubmittedPrompt(t(preset.prompt)); commonStore.setCompletionPreset({ ...preset, prompt: t(preset.prompt) @@ -181,6 +184,8 @@ const CompletionPanel: FC = observer(() => { }; const onSubmit = (prompt: string) => { + commonStore.setCompletionSubmittedPrompt(prompt); + if (commonStore.status.status === ModelStatus.Offline && !commonStore.settings.apiUrl) { toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' }); commonStore.setCompletionGenerating(false); @@ -259,7 +264,10 @@ const CompletionPanel: FC = observer(() => { ref={inputRef} className="grow" value={prompt} - onChange={(e) => setPrompt(e.target.value)} + onChange={(e) => { + commonStore.setCompletionSubmittedPrompt(e.target.value); + setPrompt(e.target.value); + }} />
@@ -368,6 +376,12 @@ const CompletionPanel: FC = observer(() => {
+ } onClick={() => { + completionSseController?.abort(); + commonStore.setCompletionGenerating(true); + setPrompt(commonStore.completionSubmittedPrompt); + onSubmit(commonStore.completionSubmittedPrompt); + }} /> { diff --git a/frontend/src/stores/commonStore.ts b/frontend/src/stores/commonStore.ts index 5fb996a..a474e5d 100644 --- a/frontend/src/stores/commonStore.ts +++ b/frontend/src/stores/commonStore.ts @@ -52,6 +52,7 @@ class CommonStore { // completion completionPreset: CompletionPreset | null = null; completionGenerating: boolean = false; + completionSubmittedPrompt: string = ''; // configs currentModelConfigIndex: number = 0; modelConfigs: ModelConfig[] = []; @@ -221,6 +222,10 @@ class CommonStore { setActivePreset(value: Preset) { this.activePreset = value; } + + setCompletionSubmittedPrompt(value: string) { + this.completionSubmittedPrompt = value; + } } export default new CommonStore(); \ No newline at end of file