Skip to content

Commit

Permalink
Update MLModel input verification
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 6, 2023
1 parent 53f726f commit 748bb4d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/api/db/models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Project from '../schemas/Project.js';
import { UserModel } from './User.js';
import Image from '../schemas/Image.js';
import { sortDeps, hasRole, idMatch } from './utils.js';
import { MLModelModel } from './MLModel.js';
import retry from 'async-retry';
import {
WRITE_DEPLOYMENTS_ROLES,
Expand Down Expand Up @@ -50,6 +51,15 @@ export class ProjectModel {
throw new Error('Projects must be created by an authenticated user');
}

if (!input.availableMLModels.length) throw new Error('At least 1 MLModel must be enabled for a project');
const models = (await MLModelModel.getMLModels({
_ids: input.availableMLModels
})).map((model) => { return model._id });

for (const m of input.availableMLModels) {
if (!models.includes(m)) throw new Error(`${m} is not a valid model identifier`);
}

try {
const _id = input.name.toLowerCase().replace(/\s/g, '_').replace(/[^0-9a-z_]/gi, '');
const project = await operation({
Expand All @@ -61,7 +71,6 @@ export class ProjectModel {
description: 'Default view of all images. This view is not editable.',
editable: false
}],
availableMLModels: ['megadetector_v5a', 'megadetector_v5b', 'mirav2']
});

await UserModel.createGroups({ name: _id }, context);
Expand Down
1 change: 1 addition & 0 deletions src/api/type-defs/inputs/CreateProjectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default `
name: String!
description: String!
timezone: String!
availableMLModels: [String]!
}
`;

0 comments on commit 748bb4d

Please sign in to comment.