always reset to activePreset

This commit is contained in:
josc146 2023-12-08 17:10:23 +08:00
parent 0b339ad0f6
commit 51e162970e
4 changed files with 52 additions and 37 deletions

View File

@ -28,7 +28,7 @@ import { toast } from 'react-toastify';
import { WorkHeader } from '../components/WorkHeader'; import { WorkHeader } from '../components/WorkHeader';
import { DialogButton } from '../components/DialogButton'; import { DialogButton } from '../components/DialogButton';
import { OpenFileFolder, OpenOpenFileDialog, OpenSaveFileDialog } from '../../wailsjs/go/backend_golang/App'; import { OpenFileFolder, OpenOpenFileDialog, OpenSaveFileDialog } from '../../wailsjs/go/backend_golang/App';
import { absPathAsset, bytesToReadable, getServerRoot, toastWithButton } from '../utils'; import { absPathAsset, bytesToReadable, getServerRoot, setActivePreset, toastWithButton } from '../utils';
import { useMediaQuery } from 'usehooks-ts'; import { useMediaQuery } from 'usehooks-ts';
import { botName, ConversationMessage, MessageType, userName, welcomeUuid } from '../types/chat'; import { botName, ConversationMessage, MessageType, userName, welcomeUuid } from '../types/chat';
import { Labeled } from '../components/Labeled'; import { Labeled } from '../components/Labeled';
@ -536,8 +536,7 @@ const ChatPanel: FC = observer(() => {
} }
chatSseControllers = {}; chatSseControllers = {};
} }
commonStore.setConversation({}); setActivePreset(commonStore.activePreset);
commonStore.setConversationOrder([]);
}} /> }} />
<div className="relative flex grow"> <div className="relative flex grow">
<Textarea <Textarea

View File

@ -33,10 +33,8 @@ import { observer } from 'mobx-react-lite';
import { ClipboardGetText, ClipboardSetText } from '../../../wailsjs/runtime'; import { ClipboardGetText, ClipboardSetText } from '../../../wailsjs/runtime';
import { toast } from 'react-toastify'; import { toast } from 'react-toastify';
import { CustomToastContainer } from '../../components/CustomToastContainer'; import { CustomToastContainer } from '../../components/CustomToastContainer';
import { v4 as uuid } from 'uuid'; import { absPathAsset, setActivePreset } from '../../utils';
import { absPathAsset } from '../../utils';
import { Preset, PresetsNavigationItem } from '../../types/presets'; import { Preset, PresetsNavigationItem } from '../../types/presets';
import { botName, Conversation, MessageType, userName } from '../../types/chat';
import { LazyImportComponent } from '../../components/LazyImportComponent'; import { LazyImportComponent } from '../../components/LazyImportComponent';
const defaultPreset: Preset = { const defaultPreset: Preset = {
@ -60,29 +58,6 @@ const defaultPreset: Preset = {
const MessagesEditor = lazy(() => import('./MessagesEditor')); const MessagesEditor = lazy(() => import('./MessagesEditor'));
const setActivePreset = (preset: Preset) => {
commonStore.setActivePreset(preset);
//TODO if (preset.displayPresetMessages) {
const conversation: Conversation = {};
const conversationOrder: string[] = [];
for (const message of preset.messages) {
const newUuid = uuid();
conversationOrder.push(newUuid);
conversation[newUuid] = {
sender: message.role === 'user' ? userName : botName,
type: MessageType.Normal,
color: message.role === 'user' ? 'brand' : 'colorful',
time: new Date().toISOString(),
content: message.content,
side: message.role === 'user' ? 'right' : 'left',
done: true
};
}
commonStore.setConversation(conversation);
commonStore.setConversationOrder(conversationOrder);
//}
};
const PresetCardFrame: FC<PropsWithChildren & { const PresetCardFrame: FC<PropsWithChildren & {
onClick?: React.MouseEventHandler<HTMLButtonElement> onClick?: React.MouseEventHandler<HTMLButtonElement>
}> = (props) => { }> = (props) => {
@ -380,7 +355,9 @@ const ChatPresets: FC = observer(() => {
</div>; </div>;
}); });
const pages: { [label: string]: PresetsNavigationItem } = { const pages: {
[label: string]: PresetsNavigationItem
} = {
Chat: { Chat: {
icon: <Chat20Regular />, icon: <Chat20Regular />,
element: <ChatPresets /> element: <ChatPresets />
@ -395,7 +372,9 @@ const pages: { [label: string]: PresetsNavigationItem } = {
} }
}; };
const PresetsManager: FC<{ initTab: string }> = ({ initTab }) => { const PresetsManager: FC<{
initTab: string
}> = ({ initTab }) => {
const { t } = useTranslation(); const { t } = useTranslation();
const [tab, setTab] = useState(initTab); const [tab, setTab] = useState(initTab);

View File

@ -70,7 +70,9 @@ class CommonStore {
conversationOrder: string[] = []; conversationOrder: string[] = [];
activePreset: Preset | null = null; activePreset: Preset | null = null;
attachmentUploading: boolean = false; attachmentUploading: boolean = false;
attachments: { [uuid: string]: Attachment[] } = {}; attachments: {
[uuid: string]: Attachment[]
} = {};
currentTempAttachment: Attachment | null = null; currentTempAttachment: Attachment | null = null;
chatParams: ChatParams = { chatParams: ChatParams = {
maxResponseToken: 1000, maxResponseToken: 1000,
@ -327,7 +329,7 @@ class CommonStore {
savePresets(); savePresets();
} }
setActivePreset(value: Preset) { setActivePreset(value: Preset | null) {
this.activePreset = value; this.activePreset = value;
} }
@ -379,7 +381,9 @@ class CommonStore {
this.attachmentUploading = value; this.attachmentUploading = value;
} }
setAttachments(value: { [uuid: string]: Attachment[] }) { setAttachments(value: {
[uuid: string]: Attachment[]
}) {
this.attachments = value; this.attachments = value;
} }

View File

@ -24,6 +24,9 @@ import { Language, Languages, SettingsType } from '../types/settings';
import { DataProcessParameters, LoraFinetuneParameters } from '../types/train'; import { DataProcessParameters, LoraFinetuneParameters } from '../types/train';
import { InstrumentTypeNameMap, tracksMinimalTotalTime } from '../types/composition'; import { InstrumentTypeNameMap, tracksMinimalTotalTime } from '../types/composition';
import logo from '../assets/images/logo.png'; import logo from '../assets/images/logo.png';
import { Preset } from '../types/presets';
import { botName, Conversation, MessageType, userName } from '../types/chat';
import { v4 as uuid } from 'uuid';
export type Cache = { export type Cache = {
version: string version: string
@ -41,7 +44,9 @@ export type LocalConfig = {
} }
export async function refreshBuiltInModels(readCache: boolean = false) { export async function refreshBuiltInModels(readCache: boolean = false) {
let cache: { models: ModelSourceItem[] } = { models: [] }; let cache: {
models: ModelSourceItem[]
} = { models: [] };
if (readCache) if (readCache)
await ReadJson('cache.json').then((cacheData: Cache) => { await ReadJson('cache.json').then((cacheData: Cache) => {
if (cacheData.models) if (cacheData.models)
@ -133,7 +138,9 @@ function initLastUnfinishedModelDownloads() {
commonStore.setLastUnfinishedModelDownloads(list); commonStore.setLastUnfinishedModelDownloads(list);
} }
export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) { export async function refreshRemoteModels(cache: {
models: ModelSourceItem[]
}) {
const manifestUrls = commonStore.modelSourceManifestList.split(/[,;\n]/); const manifestUrls = commonStore.modelSourceManifestList.split(/[,;\n]/);
const requests = manifestUrls.filter(url => url.endsWith('.json')).map( const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
url => fetch(url, { cache: 'no-cache' }).then(r => r.json())); url => fetch(url, { cache: 'no-cache' }).then(r => r.json()));
@ -515,7 +522,9 @@ export function flushMidiRecordingContent() {
.filter(c => c.messageType === 'NoteOn') .filter(c => c.messageType === 'NoteOn')
.map(c => c.instrument) .map(c => c.instrument)
.reduce((frequencyCount, current) => (frequencyCount[current] = (frequencyCount[current] || 0) + 1, frequencyCount) .reduce((frequencyCount, current) => (frequencyCount[current] = (frequencyCount[current] || 0) + 1, frequencyCount)
, {} as { [key: string]: number })) , {} as {
[key: string]: number
}))
.sort((a, b) => b[1] - a[1]); .sort((a, b) => b[1] - a[1]);
let mainInstrument: string = ''; let mainInstrument: string = '';
if (sortedInstrumentFrequency.length > 0) if (sortedInstrumentFrequency.length > 0)
@ -551,6 +560,30 @@ export async function getSoundFont() {
return soundUrl; return soundUrl;
} }
export const setActivePreset = (preset: Preset | null) => {
commonStore.setActivePreset(preset);
//TODO if (preset.displayPresetMessages) {
const conversation: Conversation = {};
const conversationOrder: string[] = [];
if (preset)
for (const message of preset.messages) {
const newUuid = uuid();
conversationOrder.push(newUuid);
conversation[newUuid] = {
sender: message.role === 'user' ? userName : botName,
type: MessageType.Normal,
color: message.role === 'user' ? 'brand' : 'colorful',
time: new Date().toISOString(),
content: message.content,
side: message.role === 'user' ? 'right' : 'left',
done: true
};
}
commonStore.setConversation(conversation);
commonStore.setConversationOrder(conversationOrder);
//}
};
export function getSupportedCustomCudaFile(isBeta: boolean) { export function getSupportedCustomCudaFile(isBeta: boolean) {
if ([' 10', ' 16', ' 20', ' 30', 'MX', 'Tesla P', 'Quadro P', 'NVIDIA P', 'TITAN X', 'TITAN RTX', 'RTX A', if ([' 10', ' 16', ' 20', ' 30', 'MX', 'Tesla P', 'Quadro P', 'NVIDIA P', 'TITAN X', 'TITAN RTX', 'RTX A',
'Quadro RTX 4000', 'Quadro RTX 5000', 'Tesla T4', 'NVIDIA A10', 'NVIDIA A40'].some(v => commonStore.status.device_name.includes(v))) 'Quadro RTX 4000', 'Quadro RTX 5000', 'Tesla T4', 'NVIDIA A10', 'NVIDIA A40'].some(v => commonStore.status.device_name.includes(v)))