jan/web/hooks/useEngineSettings.ts
hiento09 1ec8174700
Feature GPU detection for Jan on Windows and Linux (#1242)
* Add js function to generate gpu and cuda detection

* inference nitro manage via json file instead of bash and bat script

* Add /usr/lib/x86_64-linux-gnu/ to linux check gpu

* chore: add CPU - GPU toggle

* correct file path

* fix: exist file sync check

* fix: get resources path

* Fix error jan/engines create existed error

* Seting sync to file

* Fix error show notification for GPU

* Set notify default to true

---------

Co-authored-by: Hien To <tominhhien97@gmail.com>
Co-authored-by: Louis <louis@jan.ai>
2023-12-29 15:56:36 +07:00

32 lines
836 B
TypeScript

import { fs, joinPath } from '@janhq/core'
export const useEngineSettings = () => {
const readOpenAISettings = async () => {
if (
!(await fs.existsSync(await joinPath(['file://engines', 'openai.json'])))
)
return {}
const settings = await fs.readFileSync(
await joinPath(['file://engines', 'openai.json']),
'utf-8'
)
if (settings) {
return typeof settings === 'object' ? settings : JSON.parse(settings)
}
return {}
}
const saveOpenAISettings = async ({
apiKey,
}: {
apiKey: string | undefined
}) => {
const settings = await readOpenAISettings()
settings.api_key = apiKey
await fs.writeFileSync(
await joinPath(['file://engines', 'openai.json']),
JSON.stringify(settings)
)
}
return { readOpenAISettings, saveOpenAISettings }
}