import { ModelCard } from '@allenai/tugboat/lib/ModelCard' ; import { ModelInfo , ModelId } from './ModelInfo' ; class NoModelCardIdError extends Error { constructor ( info ) { super ( `Unable to determine id to use for fetching a model card for model ${ info . id }.` ) ; } } /**
 * Returns the id that should be used when fetching a model's model card.
 *
 * AllenNLP's identifiers are currently in the process of being migrated to a new format, where
 * the ids include the task that a model was trained for.
 *
 * For some models the demo already has the new id, which is stored in the `pretrained_model_id`
 * field. For models that don't have that, we'll need a mapping like that shown below.
 *
 * See: https://github.com/allenai/allennlp-demo/issues/732
 */ export function getModelCardId ( info ) { if ( info . pretrained_model_id ) { return info . pretrained_model_id ; } switch ( info . id ) { case ModelId . NMN : { return 'rc-nmn' ; } case ModelId . LERC : { return 'evaluate_rc-lerc' ; } case ModelId . VilbertVQA : { return 'vqa-vilbert' ; } case ModelId . ELMOSNLI : { return 'pair-classification-decomposable-attention-elmo' ; } default : { throw new NoModelCardIdError ( info ) ; } } } export type ModelCardsById = { [ id ] : ModelCard ; } ; export function fetchModelCards ( ) { return fetch ( '/api/model-cards/' ) . then ( ( r ) => r . json ( ) ) ; }