* feat: Deprecate model.json ready state in favor of .download ext * refactor: resolve ts ignore * chore: fix warning * fix: path polyfill on Windows
27 lines
646 B
TypeScript
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 }
|
|
}
|