From f6a2300f8ae9e8db3f7b3f46a17619b62b0f5421 Mon Sep 17 00:00:00 2001 From: JTangCoveo <113382897+JTangCoveo@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:40:34 -0400 Subject: [PATCH] feat(ml): add new ml model listing endpoint to platform client (#736) * feat(ml): add new ml model listing endpoint to platform client Add new ml model lsiting endpoint (/rest/organizations/{organizationId}/machinelearning/configuration/modelslisting) to platform client with interfaces --- .../MachineLearning/MachineLearning.ts | 8 +- .../ModelListing/ModelListing.ts | 11 ++ .../ModelListing/ModelListingInterfaces.ts | 105 ++++++++++++++++++ .../MachineLearning/ModelListing/index.ts | 2 + .../ModelListing/tests/ModelListing.spec.ts | 42 +++++++ src/resources/MachineLearning/index.ts | 1 + 6 files changed, 165 insertions(+), 4 deletions(-) create mode 100644 src/resources/MachineLearning/ModelListing/ModelListing.ts create mode 100644 src/resources/MachineLearning/ModelListing/ModelListingInterfaces.ts create mode 100644 src/resources/MachineLearning/ModelListing/index.ts create mode 100644 src/resources/MachineLearning/ModelListing/tests/ModelListing.spec.ts diff --git a/src/resources/MachineLearning/MachineLearning.ts b/src/resources/MachineLearning/MachineLearning.ts index 1655ad924..02b8762cc 100644 --- a/src/resources/MachineLearning/MachineLearning.ts +++ b/src/resources/MachineLearning/MachineLearning.ts @@ -8,6 +8,7 @@ import Models from './Models/Models.js'; import PQSConfiguration from './PQSConfiguration/PQSConfiguration.js'; import UserActionHistoryConfiguration from './UserActionHistoryConfiguration/UserActionHistoryConfiguration.js'; import IAPRConfiguration from './IAPRConfiguration/IAPRConfiguration.js'; +import ModelListing from './ModelListing/ModelListing.js'; export default class MachineLearning extends Resource { static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning`; @@ -19,11 +20,9 @@ export default class MachineLearning extends Resource { userActionHistoryConfig: UserActionHistoryConfiguration; pqsConfig: PQSConfiguration; iaprConfig: IAPRConfiguration; + modelListing: ModelListing; - constructor( - protected api: API, - protected serverlessApi: API, - ) { + constructor(protected api: API, protected serverlessApi: API) { super(api, serverlessApi); this.models = new Models(api, serverlessApi); @@ -33,6 +32,7 @@ export default class MachineLearning extends Resource { this.pqsConfig = new PQSConfiguration(api, serverlessApi); this.iaprConfig = new IAPRConfiguration(api, serverlessApi); this.userActionHistoryConfig = new UserActionHistoryConfiguration(api, serverlessApi); + this.modelListing = new ModelListing(api, serverlessApi); } register(registration: RegistrationModel) { diff --git a/src/resources/MachineLearning/ModelListing/ModelListing.ts b/src/resources/MachineLearning/ModelListing/ModelListing.ts new file mode 100644 index 000000000..d7132e6ee --- /dev/null +++ b/src/resources/MachineLearning/ModelListing/ModelListing.ts @@ -0,0 +1,11 @@ +import API from '../../../APICore.js'; +import Resource from '../../Resource.js'; +import {MLListingModel} from './ModelListingInterfaces.js'; + +export default class ModelListing extends Resource { + static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning/configuration/modellisting`; + + list(engineIds?: string[]) { + return this.api.get(this.buildPath(ModelListing.baseUrl, {engineIds})); + } +} diff --git a/src/resources/MachineLearning/ModelListing/ModelListingInterfaces.ts b/src/resources/MachineLearning/ModelListing/ModelListingInterfaces.ts new file mode 100644 index 000000000..887ef4402 --- /dev/null +++ b/src/resources/MachineLearning/ModelListing/ModelListingInterfaces.ts @@ -0,0 +1,105 @@ +export interface MLListingModel { + /** + * The model display name in the Coveo Administration console. + * + * @Example `MyModelDisplayName` + */ + modelDisplayName: string; + /** + * The unique identifier of the target machine learning model. + * + * @Example `My_Model_ID` + */ + modelId: string; + /** + * The id of the engine. + * + * @Example `topclicks` + */ + engineId: string; + /** + * The date and time the model was last updated. + * + * @Example `1691762520000` + **/ + estimatedPreviousModelUpdateTime: number; + /** + * The date and time the model is scheduled to start its next update. + * + * @Example `1691762520000` + */ + nextModelUpdateTime: number; + /** + * Version of the platform. + * + * @Example `2` + */ + platformVersion: 1 | 2; + /** + * The model size statistic. Depending on the model type, this value represents the number of items or queries on which the model was built. + * + * @Example `5` + */ + modelSizeStatistic: number; + readyForAssociation: boolean; + /** + * The current status of the model + */ + modelStatusInfo: MLModelStatusInfo; + /** + * The associations related to this model + * + */ + modelAssociations: MLModelAssociation[]; +} + +export interface MLModelStatusInfo { + /** + * The status of the model. + * + * @Example `ACTIVE` + */ + modelStatus: + | 'ARCHIVED' + | 'SOON_TO_BE_ARCHIVED' + | 'BUILD_IN_PROGRESS' + | 'ERROR' + | 'ERROR_INTERNAL' + | 'LIMITED' + | 'NOT_ASSOCIATED' + | 'ACTIVE' + | 'INACTIVE'; + /** + * The remaining days until the model is archived. + * + * @Example `4` + */ + daysUntilArchival?: number; +} + +export interface MLModelAssociation { + /** + * The unique identifier of the query pipeline to which the model is associated. + * + * @Example `38b08160-d7d4-4626-8e03-53587c23415d` + */ + parentId: string; + /** + * The unique identifier of the model association. + * + * @Example `917af358-13fd-4c8e-94af-7cf649bddc48` + */ + id: string; + /** + * The name of the query pipeline or case assist configuration the model is associated with. + * + * @Example `association name` + */ + name: string; + /** + * The type of the association. + * + * @Example `QUERY_PIPELINE` + */ + associationType: 'QUERY_PIPELINE' | 'CASE_ASSIST'; +} diff --git a/src/resources/MachineLearning/ModelListing/index.ts b/src/resources/MachineLearning/ModelListing/index.ts new file mode 100644 index 000000000..6267f06ed --- /dev/null +++ b/src/resources/MachineLearning/ModelListing/index.ts @@ -0,0 +1,2 @@ +export * from './ModelListing.js'; +export * from './ModelListingInterfaces.js'; diff --git a/src/resources/MachineLearning/ModelListing/tests/ModelListing.spec.ts b/src/resources/MachineLearning/ModelListing/tests/ModelListing.spec.ts new file mode 100644 index 000000000..cf501ca42 --- /dev/null +++ b/src/resources/MachineLearning/ModelListing/tests/ModelListing.spec.ts @@ -0,0 +1,42 @@ +import API from '../../../../APICore.js'; +import ModelListing from '../ModelListing.js'; + +jest.mock('../../../../APICore.js'); + +const APIMock: jest.Mock = API as any; + +describe('ModelListing', () => { + let modelListing: ModelListing; + const api = new APIMock() as jest.Mocked; + const serverlessApi = new APIMock() as jest.Mocked; + + beforeEach(() => { + jest.clearAllMocks(); + modelListing = new ModelListing(api, serverlessApi); + }); + + describe('list', () => { + it('should make a GET call to the ModelListing base url', () => { + modelListing.list(); + + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(ModelListing.baseUrl); + }); + + it('should make a GET call to the ModelListing base url if empty array is passed', () => { + modelListing.list([]); + + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(ModelListing.baseUrl); + }); + + it('should make a GET call to the ModelListing base url with provided list of engineIds', () => { + const engines = ['first', 'second']; + const expectedUrl = `${ModelListing.baseUrl}?engineIds=${engines[0]}&engineIds=${engines[1]}`; + modelListing.list(engines); + + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith(expectedUrl); + }); + }); +}); diff --git a/src/resources/MachineLearning/index.ts b/src/resources/MachineLearning/index.ts index 9d07c23b9..3ecc061a4 100644 --- a/src/resources/MachineLearning/index.ts +++ b/src/resources/MachineLearning/index.ts @@ -3,6 +3,7 @@ export * from './MachineLearningInterfaces.js'; export * from './FilterConditions.js'; export * from './Models/index.js'; export * from './ModelInformation/index.js'; +export * from './ModelListing/index.js'; export * from './DNEConfiguration/index.js'; export * from './CaseClassificationConfiguration/index.js'; export * from './SmartSnippetsConfiguration/index.js';