-
Notifications
You must be signed in to change notification settings - Fork 15
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
added backend implementation for model templating #1419
Changes from all commits
3cf00db
d823d49
1bae291
fde050b
c0811d6
5e66a16
7b462d6
0cebbac
78f05de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ import { isValidatorResultError } from '../types/ValidatorResultError.js' | |
import { toEntity } from '../utils/entity.js' | ||
import { BadReq, Forbidden, NotFound } from '../utils/error.js' | ||
import { convertStringToId } from '../utils/id.js' | ||
import { NotImplemented } from '../utils/result.js' | ||
import { findSchemaById } from './schema.js' | ||
|
||
export function checkModelRestriction(model: ModelInterface) { | ||
|
@@ -352,9 +351,28 @@ export async function createModelCardFromSchema( | |
} | ||
|
||
export async function createModelCardFromTemplate( | ||
_user: UserInterface, | ||
_modelId: string, | ||
_schemaId: string, | ||
user: UserInterface, | ||
modelId: string, | ||
templateId: string, | ||
): Promise<ModelCardRevisionDoc> { | ||
throw NotImplemented({}, 'This feature is not yet implemented') | ||
if (modelId === templateId) { | ||
throw BadReq('The model and template ID must be different', { modelId, templateId }) | ||
} | ||
const model = await getModelById(user, modelId) | ||
if (model.card?.schemaId) { | ||
throw BadReq('This model already has a model card.', { modelId }) | ||
} | ||
checkModelRestriction(model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. All it does is check to see if it's "mirrored" which is basically read only. As we're not editing the template in any way, I think it's fine to use it if it's read only. |
||
const template = await getModelById(user, templateId) | ||
// Check to make sure user can access the template. We already check for the model auth later on in _setModelCard | ||
const templateAuth = await authorisation.model(user, template, ModelAction.View) | ||
if (!templateAuth.success) { | ||
throw Forbidden(templateAuth.info, { userDn: user.dn, templateId }) | ||
} | ||
|
||
if (!template.card?.schemaId) { | ||
throw BadReq('The template model is missing a model card', { modelId, templateId }) | ||
} | ||
const revision = await _setModelCard(user, modelId, template.card.schemaId, 1, template.card.metadata) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything to stop a user from calling this with a |
||
return revision | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a unit test that covers this