mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: sync
This commit is contained in:
8
src/hooks/useChatModel.ts
vendored
8
src/hooks/useChatModel.ts
vendored
@@ -5,18 +5,20 @@ import { invoke } from '@tauri-apps/api';
|
||||
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
||||
import useInit from '@/hooks/useInit';
|
||||
|
||||
export default function useChatModel(key: string) {
|
||||
export default function useChatModel(key: string, file = CHAT_MODEL_JSON) {
|
||||
const [modelJson, setModelJson] = useState<Record<string, any>>({});
|
||||
|
||||
useInit(async () => {
|
||||
const data = await readJSON(CHAT_MODEL_JSON, { name: 'ChatGPT Model', [key]: [] });
|
||||
const data = await readJSON(file, {
|
||||
defaultVal: { name: 'ChatGPT Model', [key]: [] },
|
||||
});
|
||||
setModelJson(data);
|
||||
});
|
||||
|
||||
const modelSet = async (data: Record<string, any>[]) => {
|
||||
const oData = clone(modelJson);
|
||||
oData[key] = data;
|
||||
await writeJSON(CHAT_MODEL_JSON, oData);
|
||||
await writeJSON(file, oData);
|
||||
await invoke('window_reload', { label: 'core' });
|
||||
setModelJson(oData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user