-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ml): add model configuration resource (#64)
* feat(ml): add model configuration resource * feat(modelconfiguration): apply review * feat(modelconfig): minor fix
- Loading branch information
1 parent
c07b1b5
commit 98a14f9
Showing
7 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/resources/MachineLearning/ModelConfiguration/ModelConfiguration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import API from '../../../APICore'; | ||
import {ModelConfigFileType} from '../../Enums'; | ||
import Resource from '../../Resource'; | ||
import { | ||
AdvancedRegistrationConfigFile, | ||
AdvancedRegistrationConfigFileCreationResponse, | ||
ModelConfigurationUpdateArgs, | ||
} from './ModelConfigurationInterfaces'; | ||
|
||
export default class ModelConfiguration extends Resource { | ||
static getBaseUrl = (modelId: string, modelConfigFileType: ModelConfigFileType) => | ||
`/rest/organizations/${API.orgPlaceholder}/machinelearning/models/${modelId}/configs/${modelConfigFileType}`; | ||
|
||
get(modelId: string, modelConfigFileType: ModelConfigFileType, languageCode?: string) { | ||
return this.api.get<AdvancedRegistrationConfigFile>( | ||
this.buildPath(ModelConfiguration.getBaseUrl(modelId, modelConfigFileType), {languageCode}) | ||
); | ||
} | ||
|
||
update( | ||
modelId: string, | ||
modelConfigFileType: ModelConfigFileType, | ||
{modelConfigFileContents, languageCode}: ModelConfigurationUpdateArgs | ||
) { | ||
return this.api.put<AdvancedRegistrationConfigFileCreationResponse>( | ||
this.buildPath(ModelConfiguration.getBaseUrl(modelId, modelConfigFileType), {languageCode}), | ||
modelConfigFileContents | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/resources/MachineLearning/ModelConfiguration/ModelConfigurationInterfaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface AdvancedRegistrationConfigFile { | ||
fileContents?: string; | ||
lastModified?: string; | ||
modelId?: RegistrationId; | ||
orgId?: Record<string, string>; | ||
} | ||
|
||
export interface RegistrationId { | ||
modelId?: string; | ||
} | ||
|
||
export interface AdvancedRegistrationConfigFileCreationResponse { | ||
filePath?: Record<string, string>; | ||
modelId?: RegistrationId; | ||
} | ||
|
||
export interface ModelConfigurationUpdateArgs { | ||
modelConfigFileContents: string; | ||
languageCode?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ModelConfiguration'; | ||
export * from './ModelConfigurationInterfaces'; |
43 changes: 43 additions & 0 deletions
43
src/resources/MachineLearning/ModelConfiguration/tests/ModelConfiguration.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import API from '../../../../APICore'; | ||
import {ModelConfigFileType} from '../../../Enums'; | ||
import ModelConfiguration from '../ModelConfiguration'; | ||
|
||
jest.mock('../../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('ModelConfiguration', () => { | ||
let modelConfig: ModelConfiguration; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
modelConfig = new ModelConfiguration(api); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call to the specific ModelConfiguration url', () => { | ||
const modelId = '💀Papyrus'; | ||
const modelConfigFileType = ModelConfigFileType.ADVANCED_CONFIGURATION; | ||
|
||
modelConfig.get(modelId, modelConfigFileType); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(ModelConfiguration.getBaseUrl(modelId, modelConfigFileType)); | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should make a PUT call to the specific ModelConfiguration url', () => { | ||
const modelId = '💀Sans'; | ||
const modelConfigFileType = ModelConfigFileType.FACET_ID_MAPPING; | ||
const modelConfigFileContents = '🦴🦴🦴'; | ||
|
||
modelConfig.update(modelId, modelConfigFileType, {modelConfigFileContents}); | ||
expect(api.put).toBeCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith( | ||
ModelConfiguration.getBaseUrl(modelId, modelConfigFileType), | ||
modelConfigFileContents | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters