jan/web/hooks/useEngineSettings.ts
Louis 7feaf9694d
feat: Deprecate model.json ready state in favor of .download ext (#1238)
* feat: Deprecate model.json ready state in favor of .download ext

* refactor: resolve ts ignore

* chore: fix warning

* fix: path polyfill on Windows
2023-12-28 14:06:13 +07:00

27 lines
646 B
TypeScript

import { fs, joinPath } from '@janhq/core'
export const useEngineSettings = () => {
const readOpenAISettings = async () => {
const settings = await fs.readFile(
await joinPath(['engines', 'openai.json'])
)
if (settings) {
return JSON.parse(settings)
}
return {}
}
const saveOpenAISettings = async ({
apiKey,
}: {
apiKey: string | undefined
}) => {
const settings = await readOpenAISettings()
settings.api_key = apiKey
await fs.writeFile(
await joinPath(['engines', 'openai.json']),
JSON.stringify(settings)
)
}
return { readOpenAISettings, saveOpenAISettings }
}