From 1c025c3d2940b15346dd1f0f6d4a66aaad75dc5d Mon Sep 17 00:00:00 2001 From: josc146 Date: Sun, 4 Feb 2024 22:03:59 +0800 Subject: [PATCH] feat: load conversation --- frontend/src/_locales/ja/main.json | 3 +- frontend/src/_locales/zh-hans/main.json | 3 +- .../AudiotrackManager/AudiotrackEditor.tsx | 16 +---- frontend/src/pages/Chat.tsx | 58 +++++++++++++--- frontend/src/utils/index.tsx | 66 ++++++++++++++----- 5 files changed, 107 insertions(+), 39 deletions(-) diff --git a/frontend/src/_locales/ja/main.json b/frontend/src/_locales/ja/main.json index 62e00ec..549cf39 100644 --- a/frontend/src/_locales/ja/main.json +++ b/frontend/src/_locales/ja/main.json @@ -337,5 +337,6 @@ "Penalty Decay": "ペナルティ減衰", "If you don't know what it is, keep it default.": "何であるかわからない場合はデフォルトのままにしてください。", "Failed to find the base model, please try to change your base model.": "ベースモデルが見つかりませんでした、ベースモデルを変更してみてください。", - "Markdown Renderer": "Markdownレンダリング" + "Markdown Renderer": "Markdownレンダリング", + "Load Conversation": "会話を読み込む" } \ No newline at end of file diff --git a/frontend/src/_locales/zh-hans/main.json b/frontend/src/_locales/zh-hans/main.json index 04154b0..fc5a6eb 100644 --- a/frontend/src/_locales/zh-hans/main.json +++ b/frontend/src/_locales/zh-hans/main.json @@ -337,5 +337,6 @@ "Penalty Decay": "惩罚衰减", "If you don't know what it is, keep it default.": "如果你不知道这是什么,保持默认", "Failed to find the base model, please try to change your base model.": "未找到基底模型,请尝试更换基底模型", - "Markdown Renderer": "Markdown渲染" + "Markdown Renderer": "Markdown渲染", + "Load Conversation": "读取对话" } \ No newline at end of file diff --git a/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx b/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx index e47892f..c30f47d 100644 --- a/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx +++ b/frontend/src/pages/AudiotrackManager/AudiotrackEditor.tsx @@ -29,14 +29,14 @@ import { } from '../../types/composition'; import { toast } from 'react-toastify'; import { - absPathAsset, flushMidiRecordingContent, getMidiRawContentMainInstrument, getMidiRawContentTime, getServerRoot, + OpenFileDialog, refreshTracksTotalTime } from '../../utils'; -import { OpenOpenFileDialog, PlayNote } from '../../../wailsjs/go/backend_golang/App'; +import { PlayNote } from '../../../wailsjs/go/backend_golang/App'; const snapValue = 25; const minimalMoveTime = 8; // 1000/125=8ms wait_events=125 @@ -471,15 +471,7 @@ const AudiotrackEditor: FC<{ setPrompt: (prompt: string) => void }> = observer(( return; } - OpenOpenFileDialog('*.mid').then(async filePath => { - if (!filePath) - return; - - let blob: Blob; - if (commonStore.platform === 'web') - blob = (filePath as unknown as { blob: Blob }).blob; - else - blob = await fetch(absPathAsset(filePath)).then(r => r.blob()); + OpenFileDialog('*.mid').then(async blob => { const bodyForm = new FormData(); bodyForm.append('file_data', blob); fetch(getServerRoot(commonStore.getCurrentModelConfig().apiParameters.apiPort) + '/midi-to-text', { @@ -510,8 +502,6 @@ const AudiotrackEditor: FC<{ setPrompt: (prompt: string) => void }> = observer(( ).catch(e => { toast(t('Error') + ' - ' + (e.message || e), { type: 'error', autoClose: 2500 }); }); - }).catch(e => { - toast(t('Error') + ' - ' + (e.message || e), { type: 'error', autoClose: 2500 }); }); }}> {t('Import MIDI')} diff --git a/frontend/src/pages/Chat.tsx b/frontend/src/pages/Chat.tsx index f1fe03a..68bf8dd 100644 --- a/frontend/src/pages/Chat.tsx +++ b/frontend/src/pages/Chat.tsx @@ -26,6 +26,7 @@ import { Delete28Regular, Dismiss16Regular, Dismiss24Regular, + FolderOpenVerticalRegular, RecordStop28Regular, SaveRegular, TextAlignJustify24Regular, @@ -37,9 +38,17 @@ import { toast } from 'react-toastify'; import { WorkHeader } from '../components/WorkHeader'; import { DialogButton } from '../components/DialogButton'; import { OpenFileFolder, OpenOpenFileDialog, OpenSaveFileDialog } from '../../wailsjs/go/backend_golang/App'; -import { absPathAsset, bytesToReadable, getServerRoot, setActivePreset, toastWithButton } from '../utils'; +import { + absPathAsset, + bytesToReadable, + getServerRoot, + newChatConversation, + OpenFileDialog, + setActivePreset, + toastWithButton +} from '../utils'; import { useMediaQuery } from 'usehooks-ts'; -import { botName, ConversationMessage, MessageType, userName, welcomeUuid } from '../types/chat'; +import { botName, ConversationMessage, MessageType, Role, userName, welcomeUuid } from '../types/chat'; import { Labeled } from '../components/Labeled'; import { ValuedSlider } from '../components/ValuedSlider'; import { PresetsButton } from './PresetsManager/PresetsButton'; @@ -302,12 +311,45 @@ const SidePanel: FC = observer(() => { }); }} /> } /> - {/*}*/} - {/* onClick={() => {*/} - {/* }}>*/} - {/* {t('Load Conversation')}*/} - {/**/} +