@huggingface/inference 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +755 -0
  3. package/package.json +64 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 TimMikeladze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,755 @@
1
+ # 🤗 Hugging Face Inference API
2
+
3
+ A Typescript powered wrapper for the Hugging Face Inference API. Learn more about the Inference API at [Hugging Face](https://huggingface.co/docs/api-inference/index).
4
+
5
+ ## Install
6
+
7
+ ```console
8
+ npm install @huggingface/inference
9
+
10
+ yarn add @huggingface/inference
11
+
12
+ pnpm add @huggingface/inference
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ❗**Important note:** Using an API key is optional to get started (simply provide a random string), however you will be rate limited eventually. Join [Hugging Face](https://huggingface.co/join) and then visit [access tokens](https://huggingface.co/settings/tokens) to generate your API key.
18
+
19
+ ### Basic examples
20
+
21
+ ```typescript
22
+ import HuggingFace from 'huggingface'
23
+
24
+ const hf = new HuggingFace('your api key')
25
+
26
+ // Natural Language
27
+
28
+ await hf.fillMask({
29
+ model: 'bert-base-uncased',
30
+ inputs: '[MASK] world!'
31
+ })
32
+
33
+ await hf.summarization({
34
+ model: 'facebook/bart-large-cnn',
35
+ inputs:
36
+ 'The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930.',
37
+ parameters: {
38
+ max_length: 100
39
+ }
40
+ })
41
+
42
+ await hf.questionAnswer({
43
+ model: 'deepset/roberta-base-squad2',
44
+ inputs: {
45
+ question: 'What is the capital of France?',
46
+ context: 'The capital of France is Paris.'
47
+ }
48
+ })
49
+
50
+ await hf.tableQuestionAnswer({
51
+ model: 'google/tapas-base-finetuned-wtq',
52
+ inputs: {
53
+ query: 'How many stars does the transformers repository have?',
54
+ table: {
55
+ Repository: ['Transformers', 'Datasets', 'Tokenizers'],
56
+ Stars: ['36542', '4512', '3934'],
57
+ Contributors: ['651', '77', '34'],
58
+ 'Programming language': ['Python', 'Python', 'Rust, Python and NodeJS']
59
+ }
60
+ }
61
+ })
62
+
63
+ await hf.textClassification({
64
+ model: 'distilbert-base-uncased-finetuned-sst-2-english',
65
+ inputs: 'I like you. I love you.'
66
+ })
67
+
68
+ await hf.textGeneration({
69
+ model: 'gpt2',
70
+ inputs: 'The answer to the universe is'
71
+ })
72
+
73
+ await hf.tokenClassification({
74
+ model: 'dbmdz/bert-large-cased-finetuned-conll03-english',
75
+ inputs: 'My name is Sarah Jessica Parker but you can call me Jessica'
76
+ })
77
+
78
+ await hf.translation({
79
+ model: 't5-base',
80
+ inputs: 'My name is Wolfgang and I live in Berlin'
81
+ })
82
+
83
+ await hf.zeroShotClassification({
84
+ model: 'facebook/bart-large-mnli',
85
+ inputs: [
86
+ 'Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!'
87
+ ],
88
+ parameters: { candidate_labels: ['refund', 'legal', 'faq'] }
89
+ })
90
+
91
+ await hf.conversational({
92
+ model: 'microsoft/DialoGPT-large',
93
+ inputs: {
94
+ past_user_inputs: ['Which movie is the best ?'],
95
+ generated_responses: ['It is Die Hard for sure.'],
96
+ text: 'Can you explain why ?'
97
+ }
98
+ })
99
+
100
+ await hf.featureExtraction({
101
+ model: 'sentence-transformers/paraphrase-xlm-r-multilingual-v1',
102
+ inputs: {
103
+ source_sentence: 'That is a happy person',
104
+ sentences: [
105
+ 'That is a happy dog',
106
+ 'That is a very happy person',
107
+ 'Today is a sunny day'
108
+ ]
109
+ }
110
+ })
111
+
112
+ // Audio
113
+
114
+ await hf.automaticSpeechRecognition({
115
+ model: 'facebook/wav2vec2-large-960h-lv60-self',
116
+ data: readFileSync('test/sample1.flac')
117
+ })
118
+
119
+ await hf.audioClassification({
120
+ model: 'superb/hubert-large-superb-er',
121
+ data: readFileSync('test/sample1.flac')
122
+ })
123
+
124
+ // Computer Vision
125
+
126
+ await hf.imageClassification({
127
+ data: readFileSync('test/cheetah.png'),
128
+ model: 'google/vit-base-patch16-224'
129
+ })
130
+
131
+ await hf.objectDetection({
132
+ data: readFileSync('test/cats.png'),
133
+ model: 'facebook/detr-resnet-50'
134
+ })
135
+
136
+ await hf.imageSegmentation({
137
+ data: readFileSync('test/cats.png'),
138
+ model: 'facebook/detr-resnet-50-panoptic'
139
+ })
140
+ ```
141
+
142
+ ## Supported APIs
143
+
144
+ ### Natural Language Processing
145
+
146
+ - [x] Fill mask
147
+ - [x] Summarization
148
+ - [x] Question answering
149
+ - [x] Table question answering
150
+ - [x] Text classification
151
+ - [x] Text generation
152
+ - [x] Text2Text generation
153
+ - [x] Token classification
154
+ - [x] Named entity recognition
155
+ - [x] Translation
156
+ - [x] Zero-shot classification
157
+ - [x] Conversational
158
+ - [x] Feature extraction
159
+
160
+ ### Audio
161
+
162
+ - [x] Automatic speech recognition
163
+ - [x] Audio classification
164
+
165
+ ### Computer Vision
166
+
167
+ - [x] Image classification
168
+ - [x] Object detection
169
+ - [x] Image segmentation
170
+
171
+ ## Running tests
172
+
173
+ ```console
174
+ HF_ACCESS_TOKEN="your access token" npm run test
175
+ ```
176
+
177
+ ## Options
178
+
179
+ ```typescript
180
+ export declare class HuggingFace {
181
+ private readonly apiKey
182
+ private readonly defaultOptions
183
+ constructor(apiKey: string, defaultOptions?: Options)
184
+ /**
185
+ * Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.
186
+ */
187
+ fillMask(args: FillMaskArgs, options?: Options): Promise<FillMaskReturn>
188
+ /**
189
+ * This task is well known to summarize longer text into shorter text. Be careful, some models have a maximum length of input. That means that the summary cannot handle full books for instance. Be careful when choosing your model.
190
+ */
191
+ summarization(
192
+ args: SummarizationArgs,
193
+ options?: Options
194
+ ): Promise<SummarizationReturn>
195
+ /**
196
+ * Want to have a nice know-it-all bot that can answer any question?. Recommended model: deepset/roberta-base-squad2
197
+ */
198
+ questionAnswer(
199
+ args: QuestionAnswerArgs,
200
+ options?: Options
201
+ ): Promise<QuestionAnswerReturn>
202
+ /**
203
+ * Don’t know SQL? Don’t want to dive into a large spreadsheet? Ask questions in plain english! Recommended model: google/tapas-base-finetuned-wtq.
204
+ */
205
+ tableQuestionAnswer(
206
+ args: TableQuestionAnswerArgs,
207
+ options?: Options
208
+ ): Promise<TableQuestionAnswerReturn>
209
+ /**
210
+ * Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english
211
+ */
212
+ textClassification(
213
+ args: TextClassificationArgs,
214
+ options?: Options
215
+ ): Promise<TextClassificationReturn>
216
+ /**
217
+ * Use to continue text from a prompt. This is a very generic task. Recommended model: gpt2 (it’s a simple model, but fun to play with).
218
+ */
219
+ textGeneration(
220
+ args: TextGenerationArgs,
221
+ options?: Options
222
+ ): Promise<TextGenerationReturn>
223
+ /**
224
+ * Usually used for sentence parsing, either grammatical, or Named Entity Recognition (NER) to understand keywords contained within text. Recommended model: dbmdz/bert-large-cased-finetuned-conll03-english
225
+ */
226
+ tokenClassification(
227
+ args: TokenClassificationArgs,
228
+ options?: Options
229
+ ): Promise<TokenClassificationReturn>
230
+ /**
231
+ * This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.
232
+ */
233
+ translation(
234
+ args: TranslationArgs,
235
+ options?: Options
236
+ ): Promise<TranslationReturn>
237
+ /**
238
+ * This task is super useful to try out classification with zero code, you simply pass a sentence/paragraph and the possible labels for that sentence, and you get a result. Recommended model: facebook/bart-large-mnli.
239
+ */
240
+ zeroShotClassification(
241
+ args: ZeroShotClassificationArgs,
242
+ options?: Options
243
+ ): Promise<ZeroShotClassificationReturn>
244
+ /**
245
+ * This task corresponds to any chatbot like structure. Models tend to have shorter max_length, so please check with caution when using a given model if you need long range dependency or not. Recommended model: microsoft/DialoGPT-large.
246
+ *
247
+ */
248
+ conversational(
249
+ args: ConversationalArgs,
250
+ options?: Options
251
+ ): Promise<ConversationalReturn>
252
+ /**
253
+ * This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
254
+ */
255
+ featureExtraction(
256
+ args: FeatureExtractionArgs,
257
+ options?: Options
258
+ ): Promise<FeatureExtractionReturn>
259
+ /**
260
+ * This task reads some audio input and outputs the said words within the audio files.
261
+ * Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
262
+ */
263
+ automaticSpeechRecognition(
264
+ args: AutomaticSpeechRecognitionArgs,
265
+ options?: Options
266
+ ): Promise<AutomaticSpeechRecognitionReturn>
267
+ /**
268
+ * This task reads some audio input and outputs the likelihood of classes.
269
+ * Recommended model: superb/hubert-large-superb-er
270
+ */
271
+ audioClassification(
272
+ args: AudioClassificationArgs,
273
+ options?: Options
274
+ ): Promise<AudioClassificationReturn>
275
+ /**
276
+ * This task reads some image input and outputs the likelihood of classes.
277
+ * Recommended model: google/vit-base-patch16-224
278
+ */
279
+ imageClassification(
280
+ args: ImageClassificationArgs,
281
+ options?: Options
282
+ ): Promise<ImageClassificationReturn>
283
+ /**
284
+ * This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
285
+ * Recommended model: facebook/detr-resnet-50
286
+ */
287
+ objectDetection(
288
+ args: ObjectDetectionArgs,
289
+ options?: Options
290
+ ): Promise<ObjectDetectionReturn>
291
+ /**
292
+ * This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
293
+ * Recommended model: facebook/detr-resnet-50-panoptic
294
+ */
295
+ imageSegmentation(
296
+ args: ImageSegmentationArgs,
297
+ options?: Options
298
+ ): Promise<ImageSegmentationReturn>
299
+ request(
300
+ args: Args & {
301
+ data?: any
302
+ },
303
+ options?: Options & {
304
+ binary?: boolean
305
+ }
306
+ ): Promise<any>
307
+ private static toArray
308
+ }
309
+
310
+ export declare type Options = {
311
+ /**
312
+ * (Default: false). Boolean to use GPU instead of CPU for inference (requires Startup plan at least).
313
+ */
314
+ use_gpu?: boolean
315
+ /**
316
+ * (Default: true). Boolean. There is a cache layer on the inference API to speedup requests we have already seen. Most models can use those results as is as models are deterministic (meaning the results will be the same anyway). However if you use a non deterministic model, you can set this parameter to prevent the caching mechanism from being used resulting in a real new query.
317
+ */
318
+ use_cache?: boolean
319
+ /**
320
+ * (Default: false) Boolean. If the model is not ready, wait for it instead of receiving 503. It limits the number of requests required to get your inference done. It is advised to only set this flag to true after receiving a 503 error as it will limit hanging in your application to known places.
321
+ */
322
+ wait_for_model?: boolean
323
+ /**
324
+ * (Default: true) Boolean. If a request 503s and wait_for_model is set to false, the request will be retried with the same parameters but with wait_for_model set to true.
325
+ */
326
+ retry_on_error?: boolean
327
+ }
328
+ export declare type Args = {
329
+ model: string
330
+ }
331
+ export declare type FillMaskArgs = Args & {
332
+ inputs: string
333
+ }
334
+ export declare type FillMaskReturn = {
335
+ /**
336
+ * The probability for this token.
337
+ */
338
+ score: number
339
+ /**
340
+ * The id of the token
341
+ */
342
+ token: number
343
+ /**
344
+ * The string representation of the token
345
+ */
346
+ token_str: string
347
+ /**
348
+ * The actual sequence of tokens that ran against the model (may contain special tokens)
349
+ */
350
+ sequence: string
351
+ }[]
352
+ export declare type SummarizationArgs = Args & {
353
+ /**
354
+ * A string to be summarized
355
+ */
356
+ inputs: string
357
+ parameters?: {
358
+ /**
359
+ * (Default: None). Integer to define the minimum length in tokens of the output summary.
360
+ */
361
+ min_length?: number
362
+ /**
363
+ * (Default: None). Integer to define the maximum length in tokens of the output summary.
364
+ */
365
+ max_length?: number
366
+ /**
367
+ * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
368
+ */
369
+ top_k?: number
370
+ /**
371
+ * (Default: None). Float to define the tokens that are within the sample operation of text generation. Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
372
+ */
373
+ top_p?: number
374
+ /**
375
+ * (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.
376
+ */
377
+ temperature?: number
378
+ /**
379
+ * (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized to not be picked in successive generation passes.
380
+ */
381
+ repetition_penalty?: number
382
+ /**
383
+ * (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. Network can cause some overhead so it will be a soft limit.
384
+ */
385
+ max_time?: number
386
+ }
387
+ }
388
+ export declare type SummarizationReturn = {
389
+ /**
390
+ * The string after translation
391
+ */
392
+ summary_text: string
393
+ }
394
+ export declare type QuestionAnswerArgs = Args & {
395
+ inputs: {
396
+ question: string
397
+ context: string
398
+ }
399
+ }
400
+ export declare type QuestionAnswerReturn = {
401
+ /**
402
+ * A string that’s the answer within the text.
403
+ */
404
+ answer: string
405
+ /**
406
+ * A float that represents how likely that the answer is correct
407
+ */
408
+ score: number
409
+ /**
410
+ * The index (string wise) of the start of the answer within context.
411
+ */
412
+ start: number
413
+ /**
414
+ * The index (string wise) of the stop of the answer within context.
415
+ */
416
+ end: number
417
+ }
418
+ export declare type TableQuestionAnswerArgs = Args & {
419
+ inputs: {
420
+ /**
421
+ * The query in plain text that you want to ask the table
422
+ */
423
+ query: string
424
+ /**
425
+ * A table of data represented as a dict of list where entries are headers and the lists are all the values, all lists must have the same size.
426
+ */
427
+ table: Record<string, string[]>
428
+ }
429
+ }
430
+ export declare type TableQuestionAnswerReturn = {
431
+ /**
432
+ * The plaintext answer
433
+ */
434
+ answer: string
435
+ /**
436
+ * a list of coordinates of the cells referenced in the answer
437
+ */
438
+ coordinates: number[][]
439
+ /**
440
+ * A list of coordinates of the cells contents
441
+ */
442
+ cells: string[]
443
+ /**
444
+ * The aggregator used to get the answer
445
+ */
446
+ aggregator: string
447
+ }
448
+ export declare type TextClassificationArgs = Args & {
449
+ /**
450
+ * A string to be classified
451
+ */
452
+ inputs: string
453
+ }
454
+ export declare type TextClassificationReturn = {
455
+ /**
456
+ * The label for the class (model specific)
457
+ */
458
+ label: string
459
+ /**
460
+ * A floats that represents how likely is that the text belongs to this class.
461
+ */
462
+ score: number
463
+ }[]
464
+ export declare type TextGenerationArgs = Args & {
465
+ /**
466
+ * A string to be generated from
467
+ */
468
+ inputs: string
469
+ parameters?: {
470
+ /**
471
+ * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
472
+ */
473
+ top_k?: number
474
+ /**
475
+ * (Default: None). Float to define the tokens that are within the sample operation of text generation. Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
476
+ */
477
+ top_p?: number
478
+ /**
479
+ * (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.
480
+ */
481
+ temperature?: number
482
+ /**
483
+ * (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized to not be picked in successive generation passes.
484
+ */
485
+ repetition_penalty?: number
486
+ /**
487
+ * (Default: None). Int (0-250). The amount of new tokens to be generated, this does not include the input length it is a estimate of the size of generated text you want. Each new tokens slows down the request, so look for balance between response times and length of text generated.
488
+ */
489
+ max_new_tokens?: number
490
+ /**
491
+ * (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. Network can cause some overhead so it will be a soft limit. Use that in combination with max_new_tokens for best results.
492
+ */
493
+ max_time?: number
494
+ /**
495
+ * (Default: True). Bool. If set to False, the return results will not contain the original query making it easier for prompting.
496
+ */
497
+ return_full_text?: boolean
498
+ /**
499
+ * (Default: 1). Integer. The number of proposition you want to be returned.
500
+ */
501
+ num_return_sequences?: number
502
+ /**
503
+ * (Optional: True). Bool. Whether or not to use sampling, use greedy decoding otherwise.
504
+ */
505
+ do_sample?: boolean
506
+ }
507
+ }
508
+ export declare type TextGenerationReturn = {
509
+ /**
510
+ * The continuated string
511
+ */
512
+ generated_text: string
513
+ }
514
+ export declare type TokenClassificationArgs = Args & {
515
+ /**
516
+ * A string to be classified
517
+ */
518
+ inputs: string
519
+ parameters?: {
520
+ /**
521
+ * (Default: simple). There are several aggregation strategies:
522
+ *
523
+ * none: Every token gets classified without further aggregation.
524
+ *
525
+ * simple: Entities are grouped according to the default schema (B-, I- tags get merged when the tag is similar).
526
+ *
527
+ * first: Same as the simple strategy except words cannot end up with different tags. Words will use the tag of the first token when there is ambiguity.
528
+ *
529
+ * average: Same as the simple strategy except words cannot end up with different tags. Scores are averaged across tokens and then the maximum label is applied.
530
+ *
531
+ * max: Same as the simple strategy except words cannot end up with different tags. Word entity will be the token with the maximum score.
532
+ */
533
+ aggregation_strategy?: 'none' | 'simple' | 'first' | 'average' | 'max'
534
+ }
535
+ }
536
+ export declare type TokenClassificationReturnValue = {
537
+ /**
538
+ * The type for the entity being recognized (model specific).
539
+ */
540
+ entity_group: string
541
+ /**
542
+ * How likely the entity was recognized.
543
+ */
544
+ score: number
545
+ /**
546
+ * The string that was captured
547
+ */
548
+ word: string
549
+ /**
550
+ * The offset stringwise where the answer is located. Useful to disambiguate if word occurs multiple times.
551
+ */
552
+ start: number
553
+ /**
554
+ * The offset stringwise where the answer is located. Useful to disambiguate if word occurs multiple times.
555
+ */
556
+ end: number
557
+ }
558
+ export declare type TokenClassificationReturn = TokenClassificationReturnValue[]
559
+ export declare type TranslationArgs = Args & {
560
+ /**
561
+ * A string to be translated
562
+ */
563
+ inputs: string
564
+ }
565
+ export declare type TranslationReturn = {
566
+ /**
567
+ * The string after translation
568
+ */
569
+ translation_text: string
570
+ }
571
+ export declare type ZeroShotClassificationArgs = Args & {
572
+ /**
573
+ * a string or list of strings
574
+ */
575
+ inputs: string | string[]
576
+ parameters: {
577
+ /**
578
+ * a list of strings that are potential classes for inputs. (max 10 candidate_labels, for more, simply run multiple requests, results are going to be misleading if using too many candidate_labels anyway. If you want to keep the exact same, you can simply run multi_label=True and do the scaling on your end.
579
+ */
580
+ candidate_labels: string[]
581
+ /**
582
+ * (Default: false) Boolean that is set to True if classes can overlap
583
+ */
584
+ multi_label?: boolean
585
+ }
586
+ }
587
+ export declare type ZeroShotClassificationReturnValue = {
588
+ sequence: string
589
+ labels: string[]
590
+ scores: number[]
591
+ }
592
+ export declare type ZeroShotClassificationReturn =
593
+ ZeroShotClassificationReturnValue[]
594
+ export declare type ConversationalArgs = Args & {
595
+ inputs: {
596
+ /**
597
+ * The last input from the user in the conversation.
598
+ */
599
+ text: string
600
+ /**
601
+ * A list of strings corresponding to the earlier replies from the model.
602
+ */
603
+ generated_responses?: string[]
604
+ /**
605
+ * A list of strings corresponding to the earlier replies from the user. Should be of the same length of generated_responses.
606
+ */
607
+ past_user_inputs?: string[]
608
+ }
609
+ parameters?: {
610
+ /**
611
+ * (Default: None). Integer to define the minimum length in tokens of the output summary.
612
+ */
613
+ min_length?: number
614
+ /**
615
+ * (Default: None). Integer to define the maximum length in tokens of the output summary.
616
+ */
617
+ max_length?: number
618
+ /**
619
+ * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
620
+ */
621
+ top_k?: number
622
+ /**
623
+ * (Default: None). Float to define the tokens that are within the sample operation of text generation. Add tokens in the sample for more probable to least probable until the sum of the probabilities is greater than top_p.
624
+ */
625
+ top_p?: number
626
+ /**
627
+ * (Default: 1.0). Float (0.0-100.0). The temperature of the sampling operation. 1 means regular sampling, 0 means always take the highest score, 100.0 is getting closer to uniform probability.
628
+ */
629
+ temperature?: number
630
+ /**
631
+ * (Default: None). Float (0.0-100.0). The more a token is used within generation the more it is penalized to not be picked in successive generation passes.
632
+ */
633
+ repetition_penalty?: number
634
+ /**
635
+ * (Default: None). Float (0-120.0). The amount of time in seconds that the query should take maximum. Network can cause some overhead so it will be a soft limit.
636
+ */
637
+ max_time?: number
638
+ }
639
+ }
640
+ export declare type ConversationalReturn = {
641
+ generated_text: string
642
+ conversation: {
643
+ generated_responses: string[]
644
+ past_user_inputs: string[]
645
+ }
646
+ warnings: string[]
647
+ }
648
+ export declare type FeatureExtractionArgs = Args & {
649
+ /**
650
+ * The inputs vary based on the model. For example when using sentence-transformers/paraphrase-xlm-r-multilingual-v1 the inputs will look like this:
651
+ *
652
+ * inputs: {
653
+ * "source_sentence": "That is a happy person",
654
+ * "sentences": ["That is a happy dog", "That is a very happy person", "Today is a sunny day"]
655
+ */
656
+ inputs: Record<string, any> | Record<string, any>[]
657
+ }
658
+ /**
659
+ * Returned values are a list of floats, or a list of list of floats (depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README.
660
+ */
661
+ export declare type FeatureExtractionReturn = (number | number[])[]
662
+ export declare type ImageClassificationArgs = Args & {
663
+ /**
664
+ * Binary image data
665
+ */
666
+ data: any
667
+ }
668
+ export declare type ImageClassificationReturnValue = {
669
+ /**
670
+ * The label for the class (model specific)
671
+ */
672
+ score: number
673
+ /**
674
+ * A float that represents how likely it is that the image file belongs to this class.
675
+ */
676
+ label: string
677
+ }
678
+ export declare type ImageClassificationReturn = ImageClassificationReturnValue[]
679
+ export declare type ObjectDetectionArgs = Args & {
680
+ /**
681
+ * Binary image data
682
+ */
683
+ data: any
684
+ }
685
+ export declare type ObjectDetectionReturnValue = {
686
+ /**
687
+ * A float that represents how likely it is that the detected object belongs to the given class.
688
+ */
689
+ score: number
690
+ /**
691
+ * The label for the class (model specific) of a detected object.
692
+ */
693
+ label: string
694
+ /**
695
+ * A dict (with keys [xmin,ymin,xmax,ymax]) representing the bounding box of a detected object.
696
+ */
697
+ box: {
698
+ xmin: number
699
+ ymin: number
700
+ xmax: number
701
+ ymax: number
702
+ }
703
+ }
704
+ export declare type ObjectDetectionReturn = ObjectDetectionReturnValue[]
705
+ export declare type ImageSegmentationArgs = Args & {
706
+ /**
707
+ * Binary image data
708
+ */
709
+ data: any
710
+ }
711
+ export declare type ImageSegmentationReturnValue = {
712
+ /**
713
+ * A float that represents how likely it is that the detected object belongs to the given class.
714
+ */
715
+ score: number
716
+ /**
717
+ * The label for the class (model specific) of a segment.
718
+ */
719
+ label: string
720
+ /**
721
+ * A str (base64 str of a single channel black-and-white img) representing the mask of a segment.
722
+ */
723
+ mask: string
724
+ }
725
+ export declare type ImageSegmentationReturn = ImageSegmentationReturnValue[]
726
+ export declare type AutomaticSpeechRecognitionArgs = Args & {
727
+ /**
728
+ * Binary audio data
729
+ */
730
+ data: any
731
+ }
732
+ export declare type AutomaticSpeechRecognitionReturn = {
733
+ /**
734
+ * The text that was recognized from the audio
735
+ */
736
+ text: string
737
+ }
738
+ export declare type AudioClassificationArgs = Args & {
739
+ /**
740
+ * Binary audio data
741
+ */
742
+ data: any
743
+ }
744
+ export declare type AudioClassificationReturnValue = {
745
+ /**
746
+ * The label for the class (model specific)
747
+ */
748
+ label: string
749
+ /**
750
+ * A float that represents how likely it is that the audio file belongs to this class.
751
+ */
752
+ score: number
753
+ }
754
+ export declare type AudioClassificationReturn = AudioClassificationReturnValue[]
755
+ ```
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@huggingface/inference",
3
+ "version": "1.4.1",
4
+ "license": "MIT",
5
+ "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
6
+ "description": "Typescript wrapper for the Hugging Face Inference API",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/huggingface/huggingface.js.git"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "keywords": [
15
+ "hugging face",
16
+ "hugging face typescript",
17
+ "huggingface",
18
+ "huggingface-inference-api",
19
+ "huggingface-inference-api-typescript",
20
+ "inference",
21
+ "ai"
22
+ ],
23
+ "engines": {
24
+ "node": ">=14"
25
+ },
26
+ "files": [
27
+ "./dist",
28
+ "./src"
29
+ ],
30
+ "source": "src/index.ts",
31
+ "types": "dist/index.d.ts",
32
+ "main": "./dist/index.js",
33
+ "module": "./dist/index.mjs",
34
+ "exports": {
35
+ ".": {
36
+ "require": "./dist/index.js",
37
+ "import": "./dist/index.mjs",
38
+ "types": "./dist/index.d.ts"
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "@types/jest": "29.4.0",
43
+ "@types/node": "18.13.0",
44
+ "@typescript-eslint/eslint-plugin": "^5.51.0",
45
+ "@typescript-eslint/parser": "^5.51.0",
46
+ "eslint": "8.34.0",
47
+ "eslint-config-prettier": "^8.6.0",
48
+ "eslint-plugin-prettier": "^4.2.1",
49
+ "eslint-plugin-typescript-sort-keys": "^2.1.0",
50
+ "jest": "29.4.3",
51
+ "prettier": "2.8.4",
52
+ "ts-jest": "29.0.5",
53
+ "tsup": "^6.6.3",
54
+ "typescript": "4.9.5"
55
+ },
56
+ "resolutions": {},
57
+ "scripts": {
58
+ "build": "tsup src/index.ts --format cjs,esm --clean --dts",
59
+ "format": "prettier --write . && eslint --quiet --fix --ext .cjs,.ts .",
60
+ "test": "jest --passWithNoTests",
61
+ "test:ci": "npm run test -- --ci --coverage",
62
+ "type-check": "tsc"
63
+ }
64
+ }