import { LayersModel , loadLayersModel } from '@tensorflow/tfjs' ; import axios , { AxiosPromise } from 'axios' ; import { fetch } from 'cross-fetch' ; import { NlpTaskConfig } from '../storage' ; import { Locale } from '../types' ; export class ModelInfo < C extends NlpTaskConfig > { public static readonly CONFIG_FILENAME = 'config.json' ; public static readonly MODEL_FILENAME = 'model.json' ; private readonly config : AxiosPromise < C > ; private readonly model : Promise < LayersModel > ; constructor ( readonly locale , readonly uri ) { this . config = axios ( { url : `${ this . uri }/${ ModelInfo . CONFIG_FILENAME }` } ) ; this . model = loadLayersModel ( `${ this . uri }/${ ModelInfo . MODEL_FILENAME }` , { fetchFunc : fetch , } ) ; } async getConfig ( ) { return ( await this . config ) . data ; } async getModel ( ) { return await this . model ; } }