mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
feat: chatgpt prompts
This commit is contained in:
23
src/hooks/useChatModel.ts
vendored
Normal file
23
src/hooks/useChatModel.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useState } from 'react';
|
||||
import { clone } from 'lodash';
|
||||
|
||||
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
||||
import useInit from '@/hooks/useInit';
|
||||
|
||||
export default function useChatModel() {
|
||||
const [modelJson, setModelJson] = useState<Record<string, any>>({});
|
||||
|
||||
useInit(async () => {
|
||||
const data = await readJSON(CHAT_MODEL_JSON, { name: 'ChatGPT Model', data: [] });
|
||||
setModelJson(data);
|
||||
});
|
||||
|
||||
const modelSet = async (data: Record<string, any>[]) => {
|
||||
const oData = clone(modelJson);
|
||||
oData.data = data;
|
||||
await writeJSON(CHAT_MODEL_JSON, oData);
|
||||
setModelJson(oData);
|
||||
}
|
||||
|
||||
return { modelJson, modelSet, modelData: modelJson?.data || [] }
|
||||
}
|
||||
Reference in New Issue
Block a user