Repository navigation
More information about HFInference #87
Copy link
Copy link
Closed
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
coyotte508 commentedon Mar 10, 2023
https://stackoverflow.com/questions/31423573/how-to-enumerate-es6-class-methods no ?
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 .