license import * as tfliteWebAPIClient from '../tflite_web_api_client' ; import { BertQuestionAnswerer as TaskLibraryBertQuestionAnswerer } from '../types/bert_qa' ; import { BaseTaskLibraryClient } from './common' ; /** A single answer. */ export interface QaAnswer { /** The text of the answer. */ text : string ; /** The position and logit of the answer. */ pos : Pos ; } /** Answer position. */ export interface Pos { /** The start position. */ start : number ; /** The end position. */ end : number ; /** The logit. */ logit : number ; } /**
 * Client for BertQA TFLite Task Library.
 *
 * It is a wrapper around the underlying javascript API to make it more
 * convenient to use. See comments in the corresponding type declaration file in
 * src/types for more info.
 */ export class BertQuestionAnswerer extends BaseTaskLibraryClient { constructor ( protected instance ) { super ( instance ) ; } static async create ( model ) { const instance = await tfliteWebAPIClient . tfweb . BertQuestionAnswerer . create ( model ) ; return new BertQuestionAnswerer ( instance ) ; } answer ( context , question ) { const result = this . instance . answer ( context , question ) ; if ( ! result ) { return [ ] ; } return result . map ( answer => { return { text : answer . text , pos : answer . pos , } ; } ) ; } }