MCPcopy Create free account
hub / github.com/NsLearning/LangHelper / useCacheModel

Function useCacheModel

ChatGPT/src/hooks/useChatModel.ts:28–58  ·  view source on GitHub ↗
(file = '')

Source from the content-addressed store, hash-verified

26}
27
28export function useCacheModel(file = '') {
29 const [modelCacheJson, setModelCacheJson] = useState<Record<string, any>[]>([]);
30
31 useEffect(() => {
32 if (!file) return;
33 (async () => {
34 const data = await readJSON(file, { isRoot: true, isList: true });
35 setModelCacheJson(data);
36 })();
37 }, [file]);
38
39 const modelCacheSet = async (data: Record<string, any>[], newFile = '') => {
40 await writeJSON(newFile ? newFile : file, data, { isRoot: true });
41 setModelCacheJson(data);
42 await modelCacheCmd();
43 };
44
45 const modelCacheCmd = async () => {
46 // Generate the `chat.model.cmd.json` file and refresh the page for the slash command to take effect.
47 const list = await invoke('cmd_list');
48 await writeJSON(CHAT_MODEL_CMD_JSON, {
49 name: 'ChatGPT CMD',
50 last_updated: Date.now(),
51 data: list,
52 });
53 await invoke('window_reload', { label: 'core' });
54 await invoke('window_reload', { label: 'tray' });
55 };
56
57 return { modelCacheJson, modelCacheSet, modelCacheCmd };
58}

Callers 4

SyncRecordFunction · 0.90
SyncCustomFunction · 0.90
UserCustomFunction · 0.90
SyncPromptsFunction · 0.90

Calls 1

readJSONFunction · 0.90

Tested by

no test coverage detected