* chore: expose fs apis * chore: correct electron import path * update download api Signed-off-by: James <james@jan.ai> * update chat_completion Signed-off-by: James <james@jan.ai> * fix electron import Signed-off-by: James <james@jan.ai> * feat: adding API support at 1337 (#991) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * feat: Add /chat/completion api and handler * chore: add todo for modelList * chore: read engine.json for openai chat_completion (#1030) Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> * refactor: move routes to shared node module * refactor: exported modules from core with types (#1172) * refactor: exported modules from core with types * fix: fix file reading args * refactor: fileManager handles * fix: app issues with server refactoring * refactor: shared server module (#1210) * chore: resolve main * chore: update makefile --------- Signed-off-by: James <james@jan.ai> Co-authored-by: James <james@jan.ai> Co-authored-by: NamH <NamNh0122@gmail.com> Co-authored-by: hiro <vuonghoainam.work@gmail.com>
30 lines
816 B
TypeScript
30 lines
816 B
TypeScript
import { fs, joinPath } from '@janhq/core'
|
|
|
|
export const useEngineSettings = () => {
|
|
const readOpenAISettings = async () => {
|
|
if (!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 }
|
|
}
|