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

Function useChatModel

ChatGPT/src/hooks/useChatModel.ts:8–26  ·  view source on GitHub ↗
(key: string, file = CHAT_MODEL_JSON)

Source from the content-addressed store, hash-verified

6import useInit from '@/hooks/useInit';
7
8export default function useChatModel(key: string, file = CHAT_MODEL_JSON) {
9 const [modelJson, setModelJson] = useState<Record<string, any>>({});
10
11 useInit(async () => {
12 const data = await readJSON(file, {
13 defaultVal: { name: 'ChatGPT Model', [key]: null },
14 });
15 setModelJson(data);
16 });
17
18 const modelSet = async (data: Record<string, any>[] | Record<string, any>) => {
19 const oData = clone(modelJson);
20 oData[key] = data;
21 await writeJSON(file, oData);
22 setModelJson(oData);
23 };
24
25 return { modelJson, modelSet, modelData: modelJson?.[key] || [] };
26}
27
28export function useCacheModel(file = '') {
29 const [modelCacheJson, setModelCacheJson] = useState<Record<string, any>[]>([]);

Callers 3

SyncCustomFunction · 0.85
UserCustomFunction · 0.85
SyncPromptsFunction · 0.85

Calls 2

readJSONFunction · 0.90
useInitFunction · 0.85

Tested by

no test coverage detected