Skip to content

Commit

Permalink
Merge pull request #25 from lehors/relax-fields
Browse files Browse the repository at this point in the history
Limit the number of required fields on model form to name and org
  • Loading branch information
lehors authored Oct 21, 2024
2 parents 4583ef8 + 28c60f3 commit 8dacf46
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
52 changes: 26 additions & 26 deletions web/modules/mof/src/Entity/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,25 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', FALSE);

$fields['organization'] = BaseFieldDefinition::create('string')
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setLabel(t('Organization'))
->setDescription(t('The organization that developed the model.'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -95,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -95,
])
->setDisplayConfigurable('view', TRUE);

$fields['description'] = BaseFieldDefinition::create('string_long')
->setRevisionable(TRUE)
->setTranslatable(TRUE)
Expand All @@ -303,7 +322,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
'weight' => -90,
])
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
->setRequired(FALSE);

$fields['version'] = BaseFieldDefinition::create('string')
->setRevisionable(TRUE)
Expand All @@ -321,33 +340,14 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
'weight' => -80,
])
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);

$fields['organization'] = BaseFieldDefinition::create('string')
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setLabel(t('Organization'))
->setDescription(t('The organization that developed the model.'))
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -75,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'string',
'weight' => -75,
])
->setDisplayConfigurable('view', TRUE);
->setRequired(FALSE);

$fields['type'] = BaseFieldDefinition::create('list_string')
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setLabel(t('Type'))
->setDescription(t('Type of model, generally its modality.'))
->setRequired(TRUE)
->setRequired(FALSE)
->setSetting('allowed_values', [
'language' => t('Language model'),
'vision' => t('Vision model'),
Expand Down Expand Up @@ -376,7 +376,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
->setTranslatable(TRUE)
->setLabel(t('Architecture'))
->setDescription(t('The model\'s architecture.'))
->setRequired(TRUE)
->setRequired(FALSE)
->setSetting('allowed_values', [
'transformer' => t('Transformer'),
'transformer decoder' => t('Transformer (Decoder-only)'),
Expand Down Expand Up @@ -409,7 +409,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
->setTranslatable(TRUE)
->setLabel(t('Treatment'))
->setDescription(t('The training treatment, includes pre-training, fine-tuning, RLHF or other training techniques.'))
->setRequired(TRUE)
->setRequired(FALSE)
->setSetting('allowed_values', [
'pre-trained' => t('Pre-trained'),
'instruct fine-tuned' => t('Instruct fine-tuned'),
Expand All @@ -432,7 +432,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
->setTranslatable(TRUE)
->setLabel(t('Base model'))
->setDescription(t('The pretrained version of the model which this model is based on, reference itself if this is the pre-trained model.'))
->setRequired(TRUE)
->setRequired(FALSE)
->setSetting('max_length', 255)
->setDisplayOptions('form', [
'type' => 'string_textfield',
Expand Down Expand Up @@ -534,7 +534,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setDescription(t('Model status'))
->setRequired(TRUE)
->setRequired(FALSE)
->setDefaultValue(static::STATUS_UNAPPROVED)
->setSetting('allowed_values', [
static::STATUS_UNAPPROVED => t('Unapproved'),
Expand Down
26 changes: 2 additions & 24 deletions web/modules/mof/src/Form/ModelSubmitForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function form(array $form, FormStateInterface $form_state): array {

$model_details = [
'label',
'organization',
'description',
'version',
'organization',
'type',
'architecture',
'treatment',
Expand Down Expand Up @@ -90,7 +90,7 @@ public function form(array $form, FormStateInterface $form_state): array {

// Open when ajax rebuilds the form.
if ($form_state->isRebuilding()) {
$form['details']['#open'] = TRUE;
$form['details']['#open'] = FALSE;
}

// Add fields to capture license and component paths.
Expand All @@ -111,11 +111,6 @@ public function form(array $form, FormStateInterface $form_state): array {
'class' => ['license-path'],
'autocomplete' => 'off',
],
'#states' => [
'optional' => [
':input[name="components['.$id.'][license]"]' => ['empty' => TRUE],
],
],
],
'component_path' => [
'#type' => 'textfield',
Expand All @@ -130,11 +125,6 @@ public function form(array $form, FormStateInterface $form_state): array {
'class' => ['component-path'],
'autocomplete' => 'off',
],
'#states' => [
'optional' => [
':input[name="components['.$id.'][license]"]' => ['empty' => TRUE],
],
],
],
'#type' => 'container',
'#attributes' => [
Expand Down Expand Up @@ -166,18 +156,6 @@ public function validateForm(array &$form, FormStateInterface $form_state): void

$extra = array_column($this->licenseHandler->getExtraOptions(), 'licenseId');

// Ensure a license and component path is entered.
foreach ($form_state->getValue('components') as $cid => $component) {
if ($component['license'] !== '' && !in_array($component['license'], $extra)) {
if (!trim($component['license_path'])) {
$form_state->setErrorByName("components][{$cid}][license_path", $this->t('License path is required.'));
}
if (!trim($component['component_path'])) {
$form_state->setErrorByName("components][{$cid}][component_path", $this->t('Component path is required.'));
}
}
}

// Re-populate git repo tree datalist.
if (($repo_name = $form_state->getValue('github')) && !empty($repo_name)) {

Expand Down

0 comments on commit 8dacf46

Please sign in to comment.