Skip to content

Commit

Permalink
chore: model id is optional on import
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Nov 4, 2024
1 parent a986c6d commit b913af9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions web/hooks/useImportModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import {
ExtensionTypeEnum,
ImportingModel,
Model,
ModelEvent,
ModelExtension,
OptionType,
events,
fs,
} from '@janhq/core'

Expand Down Expand Up @@ -58,18 +60,19 @@ const useImportModel = () => {

const importModels = useCallback(
(models: ImportingModel[], optionType: OptionType) => {
models
.filter((e) => !!e.modelId)
.map((model) => {
if (model.modelId) {
const modelId = model.modelId
addDownloadingModel(modelId)
extensionManager
.get<ModelExtension>(ExtensionTypeEnum.Model)
?.importModel(model.modelId, model.path, model.name)
.finally(() => removeDownloadingModel(modelId))
}
})
models.map((model) => {
const modelId = model.modelId ?? model.path.split('/').pop()
if (modelId) {
addDownloadingModel(modelId)
extensionManager
.get<ModelExtension>(ExtensionTypeEnum.Model)
?.importModel(modelId, model.path, model.name)
.finally(() => {
removeDownloadingModel(modelId)
events.emit(ModelEvent.OnModelsUpdate, {})
})
}
})
},
[addDownloadingModel, removeDownloadingModel]
)
Expand Down

0 comments on commit b913af9

Please sign in to comment.