Skip to content

Commit

Permalink
Fix style, linter issues and format
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed May 16, 2024
1 parent bddc8d7 commit 1520197
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 84 deletions.
13 changes: 3 additions & 10 deletions lib/huggingface/utils/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const defaultModels = DEFAULT_MODELS.audio;
//......Audio.......

const audio = (hf) => ({

// data = readFileSync('test/sample1.flac')
async automaticSpeechRecognition(
data,
Expand All @@ -20,20 +19,14 @@ const audio = (hf) => ({
},

// data = readFileSync('test/sample1.flac')
async audioClassification(
data,
model = defaultModels.audioClassification,
) {
async audioClassification(data, model = defaultModels.audioClassification) {
const args = { data, model };
const res = await callAPI(hf, 'hf.audioClassification', args);
return res;
},

// inputs = 'Hello world!'
async textToSpeech(
inputs,
model = defaultModels.textToSpeech,
) {
async textToSpeech(inputs, model = defaultModels.textToSpeech) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.textToSpeech', args);
return res;
Expand All @@ -44,7 +37,7 @@ const audio = (hf) => ({
const args = { data, model };
const res = await callAPI(hf, 'hf.audioToAudio', args);
return res;
}
},
});

module.exports = { audio };
15 changes: 3 additions & 12 deletions lib/huggingface/utils/computerVision.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const defaultModels = DEFAULT_MODELS.computerVision;

const computerVision = (hf) => ({
// data = readFileSync('test/cheetah.png')
async imageClassification(
data,
model = defaultModels.imageClassification,
) {
async imageClassification(data, model = defaultModels.imageClassification) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageClassification', args);
return res;
Expand All @@ -28,20 +25,14 @@ const computerVision = (hf) => ({
},

// data = readFileSync('test/cats.png')
async imageSegmentation(
data,
model = defaultModels.imageSegmentation,
) {
async imageSegmentation(data, model = defaultModels.imageSegmentation) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageSegmentation', args);
return res;
},

// data = await (await fetch('https://picsum.photos/300/300')).blob()
async imageToText(
data,
model = defaultModels.imageToText,
) {
async imageToText(data, model = defaultModels.imageToText) {
const args = { data, model };
const res = await callAPI(hf, 'hf.imageToText', args);
return res;
Expand Down
17 changes: 5 additions & 12 deletions lib/huggingface/utils/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const custom = (hf) => ({
custom_param: 'some magic',
}
*/
async customCall(
inputs,
parameters = {},
model,
) {
async customCall(inputs, parameters = {}, model) {
const args = { inputs, parameters, model };
const res = await callAPI(hf, 'hf.request', args);
return res;
Expand All @@ -27,11 +23,7 @@ const custom = (hf) => ({
custom_param: 'some magic',
}
*/
async customCallStreaming(
inputs,
parameters = {},
model,
) {
async customCallStreaming(inputs, parameters = {}, model) {
const args = { inputs, parameters, model };
return callAPI(hf, 'hf.streamingRequest', args);
},
Expand All @@ -51,9 +43,10 @@ const custom = (hf) => ({
'Error occured while triggering "textGeneration" method',
{
cause: err,
});
},
);
}
}
},
});

module.exports = { custom };
26 changes: 8 additions & 18 deletions lib/huggingface/utils/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ const language = (hf) => ({
context: 'The capital of France is Paris.'
},
*/
async questionAnswering(
inputs,
model = defaultModels.questionAnswering,
) {
async questionAnswering(inputs, model = defaultModels.questionAnswering) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.questionAnswering', args);
return res;
Expand All @@ -69,10 +66,7 @@ const language = (hf) => ({
},

// inputs = 'I like you. I love you.'
async textClassification(
inputs,
model = defaultModels.textClassification,
) {
async textClassification(inputs, model = defaultModels.textClassification) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.textClassification', args);
return res;
Expand All @@ -98,10 +92,7 @@ const language = (hf) => ({
},

// inputs = 'My name is Sarah Jessica Parker but you can call me Jessica'
async tokenClassification(
inputs,
model = defaultModels.tokenClassification,
) {
async tokenClassification(inputs, model = defaultModels.tokenClassification) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tokenClassification', args);
return res;
Expand All @@ -110,7 +101,9 @@ const language = (hf) => ({
// inputs = 'My name is Wolfgang and I live in Amsterdam',
// parameters = {"src_lang": "en_XX", "tgt_lang": "fr_XX"}
async translation(
inputs, parameters = {}, model = defaultModels.translation
inputs,
parameters = {},
model = defaultModels.translation,
) {
const args = { inputs, parameters, model };
const res = await callAPI(hf, 'hf.translation', args);
Expand Down Expand Up @@ -145,14 +138,11 @@ const language = (hf) => ({
}
*/

async sentenceSimilarity(
inputs,
model = defaultModels.sentenceSimilarity,
) {
async sentenceSimilarity(inputs, model = defaultModels.sentenceSimilarity) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.sentenceSimilarity', args);
return res;
}
},
});

module.exports = { language };
8 changes: 2 additions & 6 deletions lib/huggingface/utils/multimodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ const defaultModels = DEFAULT_MODELS.multimodal;
//......Multimodal.......

const multimodal = (hf) => ({

// inputs = "That is a happy person",
async featureExtraction(
inputs,
model = defaultModels.featureExtraction,
) {
async featureExtraction(inputs, model = defaultModels.featureExtraction) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.featureExtraction', args);
return res;
Expand Down Expand Up @@ -47,7 +43,7 @@ const multimodal = (hf) => ({
const args = { inputs, model };
const res = await callAPI(hf, 'hf.documentQuestionAnswering', args);
return res;
}
},
});

module.exports = { multimodal };
7 changes: 2 additions & 5 deletions lib/huggingface/utils/tabular.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ const tabular = (hf) => ({
},
},
*/
async tabularRegression(
inputs,
model = defaultModels.tabularRegression,
) {
async tabularRegression(inputs, model = defaultModels.tabularRegression) {
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tabularRegression', args);
return res;
Expand Down Expand Up @@ -53,7 +50,7 @@ const tabular = (hf) => ({
const args = { inputs, model };
const res = await callAPI(hf, 'hf.tabularClassification', args);
return res;
}
},
});

module.exports = { tabular };
4 changes: 1 addition & 3 deletions test/huggingface/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
audio: uAudio,
} = utils;
const { audio: uAudio } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const AUDIOS = FILES + 'audios';
Expand Down
10 changes: 4 additions & 6 deletions test/huggingface/computerVision.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
computerVision: uComputerVision,
} = utils;
const { computerVision: uComputerVision } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const IMAGES = FILES + 'images';
Expand Down Expand Up @@ -91,10 +89,10 @@ describe('computerVision', () => {

it('textToImage', async () => {
const inputs =
'award winning high resolution photo of a giant tortoise' +
'/((ladybird)) hybrid, [trending on artstation]';
'award winning high resolution photo of a giant tortoise' +
'/((ladybird)) hybrid, [trending on artstation]';
const res = await computerVision.textToImage(inputs, {
negative_prompt: 'blurry'
negative_prompt: 'blurry',
});

assert.ok(res instanceof Blob);
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
custom: uCustom,
} = utils;
const { custom: uCustom } = utils;

describe('custom', () => {
let custom;
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
language: uLanguage,
} = utils;
const { language: uLanguage } = utils;

describe('language', () => {
let language;
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/multimodal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
multimodal: uMultimodal,
} = utils;
const { multimodal: uMultimodal } = utils;

const FILES = process.cwd() + '/files/huggingface/';
const IMAGES = FILES + 'images';
Expand Down
4 changes: 1 addition & 3 deletions test/huggingface/tabular.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ const { Chat } = huggingface;

const API_KEY = process.env.HUGGINGFACE_API_KEY;

const {
tabular: uTabular,
} = utils;
const { tabular: uTabular } = utils;

describe('tabular', () => {
let tabular;
Expand Down

0 comments on commit 1520197

Please sign in to comment.