Skip to content

More information about HFInference #87

Closed

Description

@hpssjellis

When I show HFInference I get this output:


class { constructor(apiKey = "", defaultOptions = {}) { __publicField(this, "apiKey"); __publicField(this, "defaultOptions"); this.apiKey = apiKey; this.defaultOptions = defaultOptions; } async fillMask(args, options) { return this.request(args, options); } async summarization(args, options) { var _a; return (_a = await this.request(args, options)) == null ? void 0 : _a[0]; } async questionAnswer(args, options) { return await this.request(args, options); } async tableQuestionAnswer(args, options) { return await this.request(args, options); } async textClassification(args, options) { var _a; return (_a = await this.request(args, options)) == null ? void 0 : _a[0]; } async textGeneration(args, options) { var _a; return (_a = await this.request(args, options)) == null ? void 0 : _a[0]; } async tokenClassification(args, options) { return HfInference.toArray(await this.request(args, options)); } async translation(args, options) { var _a; return (_a = await this.request(args, options)) == null ? void 0 : _a[0]; } async zeroShotClassification(args, options) { return HfInference.toArray(await this.request(args, options)); } async conversational(args, options) { return await this.request(args, options); } async featureExtraction(args, options) { return await this.request(args, options); } async automaticSpeechRecognition(args, options) { return await this.request(args, { ...options, binary: true }); } async audioClassification(args, options) { return await this.request(args, { ...options, binary: true }); } async imageClassification(args, options) { return await this.request(args, { ...options, binary: true }); } async objectDetection(args, options) { return await this.request(args, { ...options, binary: true }); } async imageSegmentation(args, options) { return await this.request(args, { ...options, binary: true }); } async textToImage(args, options) { return await this.request(args, { ...options, blob: true }); } async request(args, options) { const mergedOptions = {...this.defaultOptions, ...options}; const {model, ...otherArgs} = args; const headers = {}; if (this.apiKey) { headers["Authorization"] = `Bearer ${this.apiKey}`; } if (!(options == null ? void 0 : options.binary)) { headers["Content-Type"] = "application/json"; } if ((options == null ? void 0 : options.binary) && mergedOptions.wait_for_model) { headers["X-Wait-For-Model"] = "true"; } const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, { headers, method: "POST", body: (options == null ? void 0 : options.binary) ? args.data : JSON.stringify({ ...otherArgs, options: mergedOptions }) }); if (mergedOptions.retry_on_error !== false && response.status === 503 && !mergedOptions.wait_for_model) { return this.request(args, { ...mergedOptions, wait_for_model: true }); } let output; if (options == null ? void 0 : options.blob) { if (!response.ok) { throw new Error("An error occurred while fetching the blob"); } return await response.arrayBuffer(); } else { output = await response.json(); if (output.error) { throw new Error(output.error); } } return output; } static toArray(obj) { if (Array.isArray(obj)) { return obj; } return [obj]; } }

I want to be able to parse, stringify or call the seperate objects or methods, just to get data about them, but can't seem to get anything working. Any suggestions @coyotte508 @radames ? It is a class so I should be able to look at the individual methods and properties. example output here.

Activity

  1. coyotte508 commented on Mar 10, 2023

    @coyotte508
    Member

    https://stackoverflow.com/questions/31423573/how-to-enumerate-es6-class-methods no ?

    const {HfInference} = require("@huggingface/inference");
    
    const hf = new HfInference()
    
    for (const key of Object.getOwnPropertyNames(Object.getPrototypeOf(hf))) {
      console.log(key, typeof hf[key], hf[key]);
    }

    It's not really a HF inference question but a javascript question.

    Also, you have the sources available on github. And https://huggingface.co/docs/huggingface.js/inference/classes/HfInference .

  2. locked and limited conversation to collaborators on Mar 10, 2023
  3. converted this issue into a discussion #88 on Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions