fix: race condition issue - reading settings.json file (#2683)

* fix: race condition issue - reading settings.json file

* fix: cannot reset data while starting model

* chore: remove extension suffix
This commit is contained in:
Louis 2024-04-11 15:37:46 +07:00 committed by GitHub
parent 9e7bdc7f2a
commit 02c49e796d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 35 additions and 41 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/assistant-extension", "name": "@janhq/assistant-extension",
"productName": "Jan Assistant Extension", "productName": "Jan Assistant",
"version": "1.0.1", "version": "1.0.1",
"description": "This extension enables assistants, including Jan, a default assistant that can call all downloaded models", "description": "This extension enables assistants, including Jan, a default assistant that can call all downloaded models",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/conversational-extension", "name": "@janhq/conversational-extension",
"productName": "Conversational Extension", "productName": "Conversational",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension enables conversations and state persistence via your filesystem", "description": "This extension enables conversations and state persistence via your filesystem",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/huggingface-extension", "name": "@janhq/huggingface-extension",
"productName": "HuggingFace Extension", "productName": "HuggingFace",
"version": "1.0.0", "version": "1.0.0",
"description": "Hugging Face extension for converting HF models to GGUF", "description": "Hugging Face extension for converting HF models to GGUF",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/inference-groq-extension", "name": "@janhq/inference-groq-extension",
"productName": "Groq Inference Engine Extension", "productName": "Groq Inference Engine",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension enables fast Groq chat completion API calls", "description": "This extension enables fast Groq chat completion API calls",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/inference-mistral-extension", "name": "@janhq/inference-mistral-extension",
"productName": "Mistral AI Inference Engine Extension", "productName": "MistralAI Inference Engine",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension enables Mistral chat completion API calls", "description": "This extension enables Mistral chat completion API calls",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/inference-nitro-extension", "name": "@janhq/inference-nitro-extension",
"productName": "Nitro Inference Engine Extension", "productName": "Nitro Inference Engine",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension embeds Nitro, a lightweight (3mb) inference engine written in C++. See https://nitro.jan.ai.\nUse this setting if you encounter errors related to **CUDA toolkit** during application execution.", "description": "This extension embeds Nitro, a lightweight (3mb) inference engine written in C++. See https://nitro.jan.ai.\nUse this setting if you encounter errors related to **CUDA toolkit** during application execution.",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/inference-openai-extension", "name": "@janhq/inference-openai-extension",
"productName": "OpenAI Inference Engine Extension", "productName": "OpenAI Inference Engine",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension enables OpenAI chat completion API calls", "description": "This extension enables OpenAI chat completion API calls",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/inference-triton-trt-llm-extension", "name": "@janhq/inference-triton-trt-llm-extension",
"productName": "Triton-TRT-LLM Inference Engine Extension", "productName": "Triton-TRT-LLM Inference Engine",
"version": "1.0.0", "version": "1.0.0",
"description": "This extension enables Nvidia's TensorRT-LLM as an inference engine option", "description": "This extension enables Nvidia's TensorRT-LLM as an inference engine option",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/model-extension", "name": "@janhq/model-extension",
"productName": "Model Management Extension", "productName": "Model Management",
"version": "1.0.30", "version": "1.0.30",
"description": "Model Management Extension provides model exploration and seamless downloads", "description": "Model Management Extension provides model exploration and seamless downloads",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/monitoring-extension", "name": "@janhq/monitoring-extension",
"productName": "System Monitoring Extension", "productName": "System Monitoring",
"version": "1.0.10", "version": "1.0.10",
"description": "This extension provides system health and OS level data", "description": "This extension provides system health and OS level data",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -49,7 +49,9 @@ const DEFAULT_SETTINGS: GpuSetting = {
export const getGpuConfig = async (): Promise<GpuSetting | undefined> => { export const getGpuConfig = async (): Promise<GpuSetting | undefined> => {
if (process.platform === 'darwin') return undefined if (process.platform === 'darwin') return undefined
return JSON.parse(readFileSync(GPU_INFO_FILE, 'utf-8')) if (existsSync(GPU_INFO_FILE))
return JSON.parse(readFileSync(GPU_INFO_FILE, 'utf-8'))
return DEFAULT_SETTINGS
} }
export const getResourcesInfo = async (): Promise<ResourceInfo> => { export const getResourcesInfo = async (): Promise<ResourceInfo> => {

View File

@ -1,6 +1,6 @@
{ {
"name": "@janhq/tensorrt-llm-extension", "name": "@janhq/tensorrt-llm-extension",
"productName": "TensorRT-LLM Inference Engine Extension", "productName": "TensorRT-LLM Inference Engine",
"version": "0.0.3", "version": "0.0.3",
"description": "This extension enables Nvidia's TensorRT-LLM for the fastest GPU acceleration. See the [setup guide](https://jan.ai/guides/providers/tensorrt-llm/) for next steps.", "description": "This extension enables Nvidia's TensorRT-LLM for the fastest GPU acceleration. See the [setup guide](https://jan.ai/guides/providers/tensorrt-llm/) for next steps.",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -126,33 +126,27 @@ export function useActiveModel() {
}) })
} }
const stopModel = useCallback( const stopModel = useCallback(async () => {
async (model?: Model) => { const stoppingModel = activeModel || stateModel.model
const stoppingModel = activeModel || model if (!stoppingModel || (stateModel.state === 'stop' && stateModel.loading))
if ( return
!stoppingModel ||
(!model && stateModel.state === 'stop' && stateModel.loading)
)
return
setStateModel({ state: 'stop', loading: true, model: stoppingModel }) setStateModel({ state: 'stop', loading: true, model: stoppingModel })
const engine = EngineManager.instance().get(stoppingModel.engine) const engine = EngineManager.instance().get(stoppingModel.engine)
return engine return engine
?.unloadModel(stoppingModel) ?.unloadModel(stoppingModel)
.catch() .catch()
.then(() => { .then(() => {
setActiveModel(undefined) setActiveModel(undefined)
setStateModel({ state: 'start', loading: false, model: undefined }) setStateModel({ state: 'start', loading: false, model: undefined })
loadModelController?.abort() loadModelController?.abort()
}) })
}, }, [activeModel, setActiveModel, setStateModel, stateModel])
[activeModel, setActiveModel, setStateModel, stateModel]
)
const stopInference = useCallback(async () => { const stopInference = useCallback(async () => {
// Loading model // Loading model
if (stateModel.loading) { if (stateModel.loading) {
stopModel(stateModel.model) stopModel()
return return
} }
if (!activeModel) return if (!activeModel) return

View File

@ -19,7 +19,7 @@ export const factoryResetStateAtom = atom(FactoryResetState.Idle)
export default function useFactoryReset() { export default function useFactoryReset() {
const defaultJanDataFolder = useAtomValue(defaultJanDataFolderAtom) const defaultJanDataFolder = useAtomValue(defaultJanDataFolderAtom)
const { activeModel, stopModel } = useActiveModel() const { stopModel } = useActiveModel()
const setFactoryResetState = useSetAtom(factoryResetStateAtom) const setFactoryResetState = useSetAtom(factoryResetStateAtom)
const resetAll = useCallback( const resetAll = useCallback(
@ -44,11 +44,9 @@ export default function useFactoryReset() {
await window.core?.api?.updateAppConfiguration(configuration) await window.core?.api?.updateAppConfiguration(configuration)
} }
if (activeModel) { setFactoryResetState(FactoryResetState.StoppingModel)
setFactoryResetState(FactoryResetState.StoppingModel) await stopModel()
await stopModel() await new Promise((resolve) => setTimeout(resolve, 4000))
await new Promise((resolve) => setTimeout(resolve, 4000))
}
setFactoryResetState(FactoryResetState.DeletingData) setFactoryResetState(FactoryResetState.DeletingData)
await fs.rm(janDataFolderPath) await fs.rm(janDataFolderPath)
@ -59,7 +57,7 @@ export default function useFactoryReset() {
await window.core?.api?.relaunch() await window.core?.api?.relaunch()
}, },
[defaultJanDataFolder, activeModel, stopModel, setFactoryResetState] [defaultJanDataFolder, stopModel, setFactoryResetState]
) )
return { return {