Skip to content

Commit

Permalink
feat(ml): add new ml model listing endpoint to platform client (#736)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JTangCoveo authored Oct 10, 2023
1 parent 4b39e9e commit f6a2300
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/resources/MachineLearning/MachineLearning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/resources/MachineLearning/ModelListing/ModelListing.ts
Original file line number Diff line number Diff line change
@@ -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<MLListingModel[]>(this.buildPath(ModelListing.baseUrl, {engineIds}));
}
}
105 changes: 105 additions & 0 deletions src/resources/MachineLearning/ModelListing/ModelListingInterfaces.ts
Original file line number Diff line number Diff line change
@@ -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';
}
2 changes: 2 additions & 0 deletions src/resources/MachineLearning/ModelListing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ModelListing.js';
export * from './ModelListingInterfaces.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import API from '../../../../APICore.js';
import ModelListing from '../ModelListing.js';

jest.mock('../../../../APICore.js');

const APIMock: jest.Mock<API> = API as any;

describe('ModelListing', () => {
let modelListing: ModelListing;
const api = new APIMock() as jest.Mocked<API>;
const serverlessApi = new APIMock() as jest.Mocked<API>;

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);
});
});
});
1 change: 1 addition & 0 deletions src/resources/MachineLearning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit f6a2300

Please sign in to comment.