Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: retrieves the exact model running status upon message error #3976

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/src/browser/extensions/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
* Model extension type.
*/
type(): ExtensionTypeEnum | undefined {
return ExtensionTypeEnum.Model

Check warning on line 12 in core/src/browser/extensions/model.ts

View workflow job for this annotation

GitHub Actions / coverage-check

12 line is not covered with tests
}

abstract getModels(): Promise<Model[]>
abstract pullModel(model: string, id?: string, name?: string): Promise<void>
abstract cancelModelPull(modelId: string): Promise<void>
abstract importModel(model: string, modePath: string, name?: string, optionType?: OptionType): Promise<void>
abstract importModel(
model: string,
modePath: string,
name?: string,
optionType?: OptionType
): Promise<void>
abstract updateModel(modelInfo: Partial<Model>): Promise<Model>
abstract deleteModel(model: string): Promise<void>
abstract isModelLoaded(model: string): Promise<boolean>
}
20 changes: 18 additions & 2 deletions extensions/model-extension/src/cortex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ interface ICortexAPI {
getModel(model: string): Promise<Model>
getModels(): Promise<Model[]>
pullModel(model: string, id?: string, name?: string): Promise<void>
importModel(path: string, modelPath: string, name?: string, option?: string): Promise<void>
importModel(
path: string,
modelPath: string,
name?: string,
option?: string
): Promise<void>
deleteModel(model: string): Promise<void>
updateModel(model: object): Promise<void>
cancelModelPull(model: string): Promise<void>
Expand Down Expand Up @@ -141,6 +146,17 @@ export class CortexAPI implements ICortexAPI {
)
}

/**
* Check model status
* @param model
*/
async getModelStatus(model: string): Promise<boolean> {
return this.queue
.add(() => ky.get(`${API_URL}/models/status/${model}`))
.then((e) => true)
.catch(() => false)
}

/**
* Do health check on cortex.cpp
* @returns
Expand Down Expand Up @@ -215,7 +231,7 @@ export class CortexAPI implements ICortexAPI {
}
model.metadata = model.metadata ?? {
tags: [],
size: model.size ?? model.metadata?.size ?? 0
size: model.size ?? model.metadata?.size ?? 0,
}
return model as Model
}
Expand Down
8 changes: 8 additions & 0 deletions extensions/model-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ export default class JanModelExtension extends ModelExtension {
return this.cortexAPI.importModel(model, modelPath, name, option)
}

/**
* Check model status
* @param model
*/
async isModelLoaded(model: string): Promise<boolean> {
return this.cortexAPI.getModelStatus(model)
}

/**
* Handle download state from main app
*/
Expand Down
13 changes: 11 additions & 2 deletions web/containers/Providers/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EngineManager,
InferenceEngine,
extractInferenceParams,
ModelExtension,
} from '@janhq/core'
import { useAtomValue, useSetAtom } from 'jotai'
import { ulid } from 'ulidx'
Expand Down Expand Up @@ -180,8 +181,16 @@ export default function EventHandler({ children }: { children: ReactNode }) {
}
return
} else if (message.status === MessageStatus.Error) {
setActiveModel(undefined)
setStateModel({ state: 'start', loading: false, model: undefined })
;(async () => {
if (
!(await extensionManager
.get<ModelExtension>(ExtensionTypeEnum.Model)
?.isModelLoaded(activeModelRef.current?.id as string))
) {
setActiveModel(undefined)
setStateModel({ state: 'start', loading: false, model: undefined })
}
})()
}
// Mark the thread as not waiting for response
updateThreadWaiting(message.thread_id, false)
Expand Down
Loading