From fb34fc70bcfbef7ec3aaf6ca0311713e0a154d9c Mon Sep 17 00:00:00 2001 From: Sander Philipse <94373878+sphilipse@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:13:30 +0200 Subject: [PATCH] [Search] Fixes a bug where third-party models could not be saved (#189098) ## Summary This enables saving a third-party model mappings in the UI with semantic text. --- .../application/components/mappings_editor/lib/utils.ts | 2 +- .../details_page/details_page_mappings_content.tsx | 2 +- .../details_page/trained_models_deployment_modal.tsx | 9 +++++++-- .../hooks/use_details_page_mappings_model_management.ts | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts index 972c56677398..4b882e5bc495 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts @@ -789,5 +789,5 @@ export const getFieldByPathName = (fields: NormalizedFields, name: string) => { export function isLocalModel( model: InferenceServiceSettings ): model is LocalInferenceServiceSettings { - return Boolean((model as LocalInferenceServiceSettings).service_settings.model_id); + return ['elser', 'elasticsearch'].includes((model as LocalInferenceServiceSettings).service); } diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings_content.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings_content.tsx index 38035990a8ec..1b1cafc9880b 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings_content.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings_content.tsx @@ -231,7 +231,7 @@ export const DetailsPageMappingsContent: FunctionComponent<{ .map((field) => field.inference_id) .filter( (inferenceId: string) => - state.inferenceToModelIdMap?.[inferenceId] && + state.inferenceToModelIdMap?.[inferenceId].trainedModelId && // third-party inference models don't have trainedModelId !state.inferenceToModelIdMap?.[inferenceId].isDeployed ); setHasSavedFields(true); diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/trained_models_deployment_modal.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/trained_models_deployment_modal.tsx index 6472b1d384e0..e91ef6c88021 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/trained_models_deployment_modal.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/trained_models_deployment_modal.tsx @@ -101,9 +101,14 @@ export function TrainedModelsDeploymentModal({ useEffect(() => { const models = inferenceIdsInPendingList.map( (inferenceId) => inferenceToModelIdMap?.[inferenceId] - ); + ); // filter out third-party models for (const model of models) { - if (model && !model.isDownloading && !model.isDeployed) { + if ( + model?.trainedModelId && + model.isDeployable && + !model.isDownloading && + !model.isDeployed + ) { // Sometimes the model gets stuck in a ready to deploy state, so we need to trigger deployment manually startModelAllocation(model.trainedModelId); } diff --git a/x-pack/plugins/index_management/public/hooks/use_details_page_mappings_model_management.ts b/x-pack/plugins/index_management/public/hooks/use_details_page_mappings_model_management.ts index e4cc3fa31dc1..79d4c8f79cf3 100644 --- a/x-pack/plugins/index_management/public/hooks/use_details_page_mappings_model_management.ts +++ b/x-pack/plugins/index_management/public/hooks/use_details_page_mappings_model_management.ts @@ -32,7 +32,7 @@ const getCustomInferenceIdMap = ( const inferenceIdMap = models.reduce((inferenceMap, model) => { const inferenceEntry = isLocalModel(model) ? { - trainedModelId: model.service_settings.model_id, // third-party models don't have trained model ids + trainedModelId: model.service_settings.model_id, isDeployable: model.service === Service.elser || model.service === Service.elasticsearch, isDeployed: modelStatsById[model.service_settings.model_id]?.state === 'started', isDownloading: Boolean(downloadStates[model.service_settings.model_id]),