Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mlx): add the modelassociations call #905

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/resources/MachineLearning/MachineLearning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CaseClassificationConfiguration from './CaseClassificationConfiguration/C
import DNEConfiguration from './DNEConfiguration/DNEConfiguration.js';
import IAPRConfiguration from './IAPRConfiguration/IAPRConfiguration.js';
import {MLModelCreated, RegistrationModel} from './MachineLearningInterfaces.js';
import ModelAssociations from './ModelAssociations/ModelAssociations.js';
import ModelDetailedInfo from './ModelDetailedInfo/ModelDetailedInfo.js';
import ModelListing from './ModelListing/ModelListing.js';
import Models from './Models/Models.js';
Expand All @@ -27,6 +28,7 @@ export default class MachineLearning extends Resource {
relevanceGenerativeAnsweringConfig: RelevanceGenerativeAnsweringConfiguration;
semanticEncoderConfig: SemanticEncoderConfiguration;
modelDetailedInfo: ModelDetailedInfo;
modelAssociations: ModelAssociations;

constructor(
protected api: API,
Expand All @@ -45,6 +47,7 @@ export default class MachineLearning extends Resource {
this.relevanceGenerativeAnsweringConfig = new RelevanceGenerativeAnsweringConfiguration(api, serverlessApi);
this.semanticEncoderConfig = new SemanticEncoderConfiguration(api, serverlessApi);
this.modelDetailedInfo = new ModelDetailedInfo(api, serverlessApi);
this.modelAssociations = new ModelAssociations(api, serverlessApi);
paulgerold marked this conversation as resolved.
Show resolved Hide resolved
}

register(registration: RegistrationModel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import API from '../../../APICore.js';
import {PageModel} from '../../BaseInterfaces.js';
import Resource from '../../Resource.js';
import {AssociationItem, ModelAssociationsListParams} from './ModelAssociationsInterfaces.js';

export default class ModelAssociations extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/machinelearning/configuration/querypipelines`;

/**
* Lists the organization associations corresponding to the specified pipelineId.
* @param pipelineId The unique identifier of the query pipeline.
* @param params The pagination parameters.
* @returns A list of associated models
*/
list(pipelineId: string, params: ModelAssociationsListParams): Promise<PageModel<AssociationItem>> {
return this.api.get(this.buildPath(`${ModelAssociations.baseUrl}/${pipelineId}/associations`, params));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {ConditionModel} from '../../Pipelines/index.js';
import {MLModelStatus} from '../MachineLearningInterfaces.js';

export interface ModelAssociationsListParams {
/*
* The 0-based number of the page of results to list. Default: 0
*/
page: number;
/*
* The maximum number of results to include per page.. Default: 100
*/
pageSize: number;
}
export interface AssociationItem {
/**
* The unique identifier of the model association.
*/
associationId: string;
/**
* The unique identifier of the target machine learning model.
*/
modelId: string;
/**
* The id of the engine.
*/
engineId?: string;
/**
* The name of the model configuration.
*/
modelDisplayName?: string;
/**
* The current status of the model.
* @example { modelStatus: "BUILDING", daysUntilArchival : 3 }
*/
modelStatusInfo?: {
/**
* The status of the model.
* @example "ACTIVE"
*/
modelStatus: MLModelStatus;
/**
* The remaining days until the model is archived.
*/
daysUntilArchival?: number;
};
/**
* The condition that must be met to trigger the model association.
*/
condition?: ConditionModel;
/**
* The position at which this model association is evaluated in the query pipeline, relative to other model associations.
*/
position: number;
/**
* Whether the Coveo Administration Console should show the advanced configuration for this association.
*/
useAdvancedConfiguration?: boolean;
/**
* The additional parameters to send to Coveo ML.
*/
customQueryParameters?: {submodel: string};
}
2 changes: 2 additions & 0 deletions src/resources/MachineLearning/ModelAssociations/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ModelAssociations.js';
export * from './ModelAssociationsInterfaces.js';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import API from '../../../../APICore.js';
import ModelAssociations from '../ModelAssociations.js';

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

describe('ModelAssociations', () => {
let modelAssociations: ModelAssociations;
const api = new API({accessToken: 'some-token'});
const serverlessApi = new API({accessToken: 'some-token'});

beforeEach(() => {
jest.clearAllMocks();
modelAssociations = new ModelAssociations(api, serverlessApi);
});

describe('createPQSModel', () => {
it('should make a GET call to the specific IAPRConfiguration url', async () => {
const pipelineId = '123';
await modelAssociations.list(pipelineId, {page: 1, pageSize: 25});
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(
`${ModelAssociations.baseUrl}/${pipelineId}/associations?page=1&pageSize=25`,
);
});
});
});
1 change: 1 addition & 0 deletions src/resources/MachineLearning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './FilterConditions.js';
export * from './IAPRConfiguration/index.js';
export * from './MachineLearning.js';
export * from './MachineLearningInterfaces.js';
export * from './ModelAssociations/index.js';
export * from './ModelDetailedInfo/index.js';
export * from './ModelInformation/index.js';
export * from './ModelListing/index.js';
Expand Down
6 changes: 6 additions & 0 deletions src/resources/MachineLearning/tests/MachineLearning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DNEConfiguration from '../DNEConfiguration/DNEConfiguration.js';
import IAPRConfiguration from '../IAPRConfiguration/IAPRConfiguration.js';
import MachineLearning from '../MachineLearning.js';
import {RegistrationModel} from '../MachineLearningInterfaces.js';
import ModelAssociations from '../ModelAssociations/ModelAssociations.js';
import ModelDetailedInfo from '../ModelDetailedInfo/ModelDetailedInfo.js';
import Models from '../Models/Models.js';
import PQSConfiguration from '../PQSConfiguration/PQSConfiguration.js';
Expand Down Expand Up @@ -72,4 +73,9 @@ describe('MachineLearning', () => {
expect(ml.modelDetailedInfo).toBeDefined();
expect(ml.modelDetailedInfo).toBeInstanceOf(ModelDetailedInfo);
});

it('should register the modelAssociations resource', () => {
expect(ml.modelAssociations).toBeDefined();
expect(ml.modelAssociations).toBeInstanceOf(ModelAssociations);
});
});
Loading