import { useMemo } from 'react' ; import { HttpFetchQuery } from 'kibana/public' ; import { HttpService } from '../http_service' ; import { basePath } from './index' ; import { useMlKibana } from '../../contexts/kibana' ; import { TrainedModelConfigResponse , ModelPipelines , TrainedModelStat , NodesOverviewResponse , } from '../../../../common/types/trained_models' ; export interface InferenceQueryParams { decompress_definition ? : boolean ; from ? : number ; include_model_definition ? : boolean ; size ? : number ; tags ? : string ; with_pipelines ? : boolean ; include ? : 'total_feature_importance' | 'feature_importance_baseline' | string ; } export interface InferenceStatsQueryParams { from ? : number ; size ? : number ; } export interface IngestStats { count : number ; time_in_millis : number ; current : number ; failed : number ; } export interface InferenceStatsResponse { count : number ; trained_model_stats : TrainedModelStat [ ] ; } param httpService export function trainedModelsApiProvider ( httpService ) { const apiBasePath = basePath ( ) ; return { param modelId param params getTrainedModels ( modelId ? , params ? ) { let model = modelId ?? '' ; if ( Array . isArray ( modelId ) ) { model = modelId . join ( ',' ) ; } return httpService . http < TrainedModelConfigResponse [ ] > ( { path : `${ apiBasePath }/trained_models${ model && `/${ model }` }` , method : 'GET' , ... ( params ? { query : params as HttpFetchQuery } : { } ) , } ) ; } , param modelId param params getTrainedModelStats ( modelId ? , params ? ) { let model = modelId ?? '_all' ; if ( Array . isArray ( modelId ) ) { model = modelId . join ( ',' ) ; } return httpService . http < InferenceStatsResponse > ( { path : `${ apiBasePath }/trained_models/${ model }/_stats` , method : 'GET' , } ) ; } , param modelId getTrainedModelPipelines ( modelId ) { let model = modelId ; if ( Array . isArray ( modelId ) ) { model = modelId . join ( ',' ) ; } return httpService . http < ModelPipelines [ ] > ( { path : `${ apiBasePath }/trained_models/${ model }/pipelines` , method : 'GET' , } ) ; } , param modelId deleteTrainedModel ( modelId ) { return httpService . http < { acknowledge : boolean ; } > ( { path : `${ apiBasePath }/trained_models/${ modelId }` , method : 'DELETE' , } ) ; } , getTrainedModelsNodesOverview ( ) { return httpService . http < NodesOverviewResponse > ( { path : `${ apiBasePath }/trained_models/nodes_overview` , method : 'GET' , } ) ; } , startModelAllocation ( modelId ) { return httpService . http < { acknowledge : boolean ; } > ( { path : `${ apiBasePath }/trained_models/${ modelId }/deployment/_start` , method : 'POST' , } ) ; } , stopModelAllocation ( modelId , options = { force : false } ) { const force = options ?. force ; return httpService . http < { acknowledge : boolean ; } > ( { path : `${ apiBasePath }/trained_models/${ modelId }/deployment/_stop` , method : 'POST' , query : { force } , } ) ; } , } ; } type TrainedModelsApiService = ReturnType < typeof trainedModelsApiProvider > ; /**
 * Hooks for accessing  TrainedModelsApiService in React components.
  export function useTrainedModelsApiService ( ) { const { services : { mlServices : { httpService } , } , } = useMlKibana ( ) ; return useMemo ( ( ) => trainedModelsApiProvider ( httpService ) , [ httpService ] ) ; }