@huggingface/inference 1.5.0 → 1.5.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.
package/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
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
4
 
5
+ Check out the [full documentation](https://huggingface.co/docs/huggingface.js/inference/README).
6
+
7
+
5
8
  ## Install
6
9
 
7
10
  ```console
@@ -180,600 +183,3 @@ await hf.textToImage({
180
183
  ```console
181
184
  HF_ACCESS_TOKEN="your access token" npm run test
182
185
  ```
183
-
184
- ## Options
185
-
186
- ```typescript
187
- export declare class HfInference {
188
- private readonly apiKey
189
- private readonly defaultOptions
190
- constructor(apiKey: string, defaultOptions?: Options)
191
- /**
192
- * Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.
193
- */
194
- fillMask(args: FillMaskArgs, options?: Options): Promise<FillMaskReturn>
195
- /**
196
- * 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.
197
- */
198
- summarization(
199
- args: SummarizationArgs,
200
- options?: Options
201
- ): Promise<SummarizationReturn>
202
- /**
203
- * Want to have a nice know-it-all bot that can answer any question?. Recommended model: deepset/roberta-base-squad2
204
- */
205
- questionAnswer(
206
- args: QuestionAnswerArgs,
207
- options?: Options
208
- ): Promise<QuestionAnswerReturn>
209
- /**
210
- * 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.
211
- */
212
- tableQuestionAnswer(
213
- args: TableQuestionAnswerArgs,
214
- options?: Options
215
- ): Promise<TableQuestionAnswerReturn>
216
- /**
217
- * Usually used for sentiment-analysis this will output the likelihood of classes of an input. Recommended model: distilbert-base-uncased-finetuned-sst-2-english
218
- */
219
- textClassification(
220
- args: TextClassificationArgs,
221
- options?: Options
222
- ): Promise<TextClassificationReturn>
223
- /**
224
- * 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).
225
- */
226
- textGeneration(
227
- args: TextGenerationArgs,
228
- options?: Options
229
- ): Promise<TextGenerationReturn>
230
- /**
231
- * 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
232
- */
233
- tokenClassification(
234
- args: TokenClassificationArgs,
235
- options?: Options
236
- ): Promise<TokenClassificationReturn>
237
- /**
238
- * This task is well known to translate text from one language to another. Recommended model: Helsinki-NLP/opus-mt-ru-en.
239
- */
240
- translation(
241
- args: TranslationArgs,
242
- options?: Options
243
- ): Promise<TranslationReturn>
244
- /**
245
- * 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.
246
- */
247
- zeroShotClassification(
248
- args: ZeroShotClassificationArgs,
249
- options?: Options
250
- ): Promise<ZeroShotClassificationReturn>
251
- /**
252
- * 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.
253
- *
254
- */
255
- conversational(
256
- args: ConversationalArgs,
257
- options?: Options
258
- ): Promise<ConversationalReturn>
259
- /**
260
- * This task reads some text and outputs raw float values, that are usually consumed as part of a semantic database/semantic search.
261
- */
262
- featureExtraction(
263
- args: FeatureExtractionArgs,
264
- options?: Options
265
- ): Promise<FeatureExtractionReturn>
266
- /**
267
- * This task reads some audio input and outputs the said words within the audio files.
268
- * Recommended model (english language): facebook/wav2vec2-large-960h-lv60-self
269
- */
270
- automaticSpeechRecognition(
271
- args: AutomaticSpeechRecognitionArgs,
272
- options?: Options
273
- ): Promise<AutomaticSpeechRecognitionReturn>
274
- /**
275
- * This task reads some audio input and outputs the likelihood of classes.
276
- * Recommended model: superb/hubert-large-superb-er
277
- */
278
- audioClassification(
279
- args: AudioClassificationArgs,
280
- options?: Options
281
- ): Promise<AudioClassificationReturn>
282
- /**
283
- * This task reads some image input and outputs the likelihood of classes.
284
- * Recommended model: google/vit-base-patch16-224
285
- */
286
- imageClassification(
287
- args: ImageClassificationArgs,
288
- options?: Options
289
- ): Promise<ImageClassificationReturn>
290
- /**
291
- * This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
292
- * Recommended model: facebook/detr-resnet-50
293
- */
294
- objectDetection(
295
- args: ObjectDetectionArgs,
296
- options?: Options
297
- ): Promise<ObjectDetectionReturn>
298
- /**
299
- * This task reads some image input and outputs the likelihood of classes & bounding boxes of detected objects.
300
- * Recommended model: facebook/detr-resnet-50-panoptic
301
- */
302
- imageSegmentation(
303
- args: ImageSegmentationArgs,
304
- options?: Options
305
- ): Promise<ImageSegmentationReturn>
306
-
307
- /**
308
- * This task reads some text input and outputs an image.
309
- * Recommended model: stabilityai/stable-diffusion-2
310
- */
311
- textToImage(args: TextToImageArgs, options?: Options): Promise<TextToImageReturn>;
312
- request(
313
- args: Args & {
314
- data?: any
315
- },
316
- options?: Options & {
317
- binary?: boolean
318
- }
319
- ): Promise<any>
320
- private static toArray
321
- }
322
-
323
- export declare type Options = {
324
- /**
325
- * (Default: false). Boolean to use GPU instead of CPU for inference (requires Startup plan at least).
326
- */
327
- use_gpu?: boolean
328
- /**
329
- * (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.
330
- */
331
- use_cache?: boolean
332
- /**
333
- * (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.
334
- */
335
- wait_for_model?: boolean
336
- /**
337
- * (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.
338
- */
339
- retry_on_error?: boolean
340
- }
341
- export declare type Args = {
342
- model: string
343
- }
344
- export declare type FillMaskArgs = Args & {
345
- inputs: string
346
- }
347
- export declare type FillMaskReturn = {
348
- /**
349
- * The probability for this token.
350
- */
351
- score: number
352
- /**
353
- * The id of the token
354
- */
355
- token: number
356
- /**
357
- * The string representation of the token
358
- */
359
- token_str: string
360
- /**
361
- * The actual sequence of tokens that ran against the model (may contain special tokens)
362
- */
363
- sequence: string
364
- }[]
365
- export declare type SummarizationArgs = Args & {
366
- /**
367
- * A string to be summarized
368
- */
369
- inputs: string
370
- parameters?: {
371
- /**
372
- * (Default: None). Integer to define the minimum length in tokens of the output summary.
373
- */
374
- min_length?: number
375
- /**
376
- * (Default: None). Integer to define the maximum length in tokens of the output summary.
377
- */
378
- max_length?: number
379
- /**
380
- * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
381
- */
382
- top_k?: number
383
- /**
384
- * (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.
385
- */
386
- top_p?: number
387
- /**
388
- * (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.
389
- */
390
- temperature?: number
391
- /**
392
- * (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.
393
- */
394
- repetition_penalty?: number
395
- /**
396
- * (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.
397
- */
398
- max_time?: number
399
- }
400
- }
401
- export declare type SummarizationReturn = {
402
- /**
403
- * The string after translation
404
- */
405
- summary_text: string
406
- }
407
- export declare type QuestionAnswerArgs = Args & {
408
- inputs: {
409
- question: string
410
- context: string
411
- }
412
- }
413
- export declare type QuestionAnswerReturn = {
414
- /**
415
- * A string that’s the answer within the text.
416
- */
417
- answer: string
418
- /**
419
- * A float that represents how likely that the answer is correct
420
- */
421
- score: number
422
- /**
423
- * The index (string wise) of the start of the answer within context.
424
- */
425
- start: number
426
- /**
427
- * The index (string wise) of the stop of the answer within context.
428
- */
429
- end: number
430
- }
431
- export declare type TableQuestionAnswerArgs = Args & {
432
- inputs: {
433
- /**
434
- * The query in plain text that you want to ask the table
435
- */
436
- query: string
437
- /**
438
- * 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.
439
- */
440
- table: Record<string, string[]>
441
- }
442
- }
443
- export declare type TableQuestionAnswerReturn = {
444
- /**
445
- * The plaintext answer
446
- */
447
- answer: string
448
- /**
449
- * a list of coordinates of the cells referenced in the answer
450
- */
451
- coordinates: number[][]
452
- /**
453
- * A list of coordinates of the cells contents
454
- */
455
- cells: string[]
456
- /**
457
- * The aggregator used to get the answer
458
- */
459
- aggregator: string
460
- }
461
- export declare type TextClassificationArgs = Args & {
462
- /**
463
- * A string to be classified
464
- */
465
- inputs: string
466
- }
467
- export declare type TextClassificationReturn = {
468
- /**
469
- * The label for the class (model specific)
470
- */
471
- label: string
472
- /**
473
- * A floats that represents how likely is that the text belongs to this class.
474
- */
475
- score: number
476
- }[]
477
- export declare type TextGenerationArgs = Args & {
478
- /**
479
- * A string to be generated from
480
- */
481
- inputs: string
482
- parameters?: {
483
- /**
484
- * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
485
- */
486
- top_k?: number
487
- /**
488
- * (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.
489
- */
490
- top_p?: number
491
- /**
492
- * (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.
493
- */
494
- temperature?: number
495
- /**
496
- * (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.
497
- */
498
- repetition_penalty?: number
499
- /**
500
- * (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.
501
- */
502
- max_new_tokens?: number
503
- /**
504
- * (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.
505
- */
506
- max_time?: number
507
- /**
508
- * (Default: True). Bool. If set to False, the return results will not contain the original query making it easier for prompting.
509
- */
510
- return_full_text?: boolean
511
- /**
512
- * (Default: 1). Integer. The number of proposition you want to be returned.
513
- */
514
- num_return_sequences?: number
515
- /**
516
- * (Optional: True). Bool. Whether or not to use sampling, use greedy decoding otherwise.
517
- */
518
- do_sample?: boolean
519
- }
520
- }
521
- export declare type TextGenerationReturn = {
522
- /**
523
- * The continuated string
524
- */
525
- generated_text: string
526
- }
527
- export declare type TokenClassificationArgs = Args & {
528
- /**
529
- * A string to be classified
530
- */
531
- inputs: string
532
- parameters?: {
533
- /**
534
- * (Default: simple). There are several aggregation strategies:
535
- *
536
- * none: Every token gets classified without further aggregation.
537
- *
538
- * simple: Entities are grouped according to the default schema (B-, I- tags get merged when the tag is similar).
539
- *
540
- * 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.
541
- *
542
- * 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.
543
- *
544
- * max: Same as the simple strategy except words cannot end up with different tags. Word entity will be the token with the maximum score.
545
- */
546
- aggregation_strategy?: 'none' | 'simple' | 'first' | 'average' | 'max'
547
- }
548
- }
549
- export declare type TokenClassificationReturnValue = {
550
- /**
551
- * The type for the entity being recognized (model specific).
552
- */
553
- entity_group: string
554
- /**
555
- * How likely the entity was recognized.
556
- */
557
- score: number
558
- /**
559
- * The string that was captured
560
- */
561
- word: string
562
- /**
563
- * The offset stringwise where the answer is located. Useful to disambiguate if word occurs multiple times.
564
- */
565
- start: number
566
- /**
567
- * The offset stringwise where the answer is located. Useful to disambiguate if word occurs multiple times.
568
- */
569
- end: number
570
- }
571
- export declare type TokenClassificationReturn = TokenClassificationReturnValue[]
572
- export declare type TranslationArgs = Args & {
573
- /**
574
- * A string to be translated
575
- */
576
- inputs: string
577
- }
578
- export declare type TranslationReturn = {
579
- /**
580
- * The string after translation
581
- */
582
- translation_text: string
583
- }
584
- export declare type ZeroShotClassificationArgs = Args & {
585
- /**
586
- * a string or list of strings
587
- */
588
- inputs: string | string[]
589
- parameters: {
590
- /**
591
- * 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.
592
- */
593
- candidate_labels: string[]
594
- /**
595
- * (Default: false) Boolean that is set to True if classes can overlap
596
- */
597
- multi_label?: boolean
598
- }
599
- }
600
- export declare type ZeroShotClassificationReturnValue = {
601
- sequence: string
602
- labels: string[]
603
- scores: number[]
604
- }
605
- export declare type ZeroShotClassificationReturn =
606
- ZeroShotClassificationReturnValue[]
607
- export declare type ConversationalArgs = Args & {
608
- inputs: {
609
- /**
610
- * The last input from the user in the conversation.
611
- */
612
- text: string
613
- /**
614
- * A list of strings corresponding to the earlier replies from the model.
615
- */
616
- generated_responses?: string[]
617
- /**
618
- * A list of strings corresponding to the earlier replies from the user. Should be of the same length of generated_responses.
619
- */
620
- past_user_inputs?: string[]
621
- }
622
- parameters?: {
623
- /**
624
- * (Default: None). Integer to define the minimum length in tokens of the output summary.
625
- */
626
- min_length?: number
627
- /**
628
- * (Default: None). Integer to define the maximum length in tokens of the output summary.
629
- */
630
- max_length?: number
631
- /**
632
- * (Default: None). Integer to define the top tokens considered within the sample operation to create new text.
633
- */
634
- top_k?: number
635
- /**
636
- * (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.
637
- */
638
- top_p?: number
639
- /**
640
- * (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.
641
- */
642
- temperature?: number
643
- /**
644
- * (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.
645
- */
646
- repetition_penalty?: number
647
- /**
648
- * (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.
649
- */
650
- max_time?: number
651
- }
652
- }
653
- export declare type ConversationalReturn = {
654
- generated_text: string
655
- conversation: {
656
- generated_responses: string[]
657
- past_user_inputs: string[]
658
- }
659
- warnings: string[]
660
- }
661
- export declare type FeatureExtractionArgs = Args & {
662
- /**
663
- * The inputs vary based on the model. For example when using sentence-transformers/paraphrase-xlm-r-multilingual-v1 the inputs will look like this:
664
- *
665
- * inputs: {
666
- * "source_sentence": "That is a happy person",
667
- * "sentences": ["That is a happy dog", "That is a very happy person", "Today is a sunny day"]
668
- */
669
- inputs: Record<string, any> | Record<string, any>[]
670
- }
671
- /**
672
- * 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.
673
- */
674
- export declare type FeatureExtractionReturn = (number | number[])[]
675
- export declare type ImageClassificationArgs = Args & {
676
- /**
677
- * Binary image data
678
- */
679
- data: any
680
- }
681
- export declare type ImageClassificationReturnValue = {
682
- /**
683
- * The label for the class (model specific)
684
- */
685
- score: number
686
- /**
687
- * A float that represents how likely it is that the image file belongs to this class.
688
- */
689
- label: string
690
- }
691
- export declare type ImageClassificationReturn = ImageClassificationReturnValue[]
692
- export declare type ObjectDetectionArgs = Args & {
693
- /**
694
- * Binary image data
695
- */
696
- data: any
697
- }
698
- export declare type ObjectDetectionReturnValue = {
699
- /**
700
- * A float that represents how likely it is that the detected object belongs to the given class.
701
- */
702
- score: number
703
- /**
704
- * The label for the class (model specific) of a detected object.
705
- */
706
- label: string
707
- /**
708
- * A dict (with keys [xmin,ymin,xmax,ymax]) representing the bounding box of a detected object.
709
- */
710
- box: {
711
- xmin: number
712
- ymin: number
713
- xmax: number
714
- ymax: number
715
- }
716
- }
717
- export declare type ObjectDetectionReturn = ObjectDetectionReturnValue[]
718
- export declare type ImageSegmentationArgs = Args & {
719
- /**
720
- * Binary image data
721
- */
722
- data: any
723
- }
724
- export declare type ImageSegmentationReturnValue = {
725
- /**
726
- * A float that represents how likely it is that the detected object belongs to the given class.
727
- */
728
- score: number
729
- /**
730
- * The label for the class (model specific) of a segment.
731
- */
732
- label: string
733
- /**
734
- * A str (base64 str of a single channel black-and-white img) representing the mask of a segment.
735
- */
736
- mask: string
737
- }
738
- export declare type ImageSegmentationReturn = ImageSegmentationReturnValue[]
739
- export declare type AutomaticSpeechRecognitionArgs = Args & {
740
- /**
741
- * Binary audio data
742
- */
743
- data: any
744
- }
745
- export declare type AutomaticSpeechRecognitionReturn = {
746
- /**
747
- * The text that was recognized from the audio
748
- */
749
- text: string
750
- }
751
- export declare type AudioClassificationArgs = Args & {
752
- /**
753
- * Binary audio data
754
- */
755
- data: any
756
- }
757
- export declare type AudioClassificationReturnValue = {
758
- /**
759
- * The label for the class (model specific)
760
- */
761
- label: string
762
- /**
763
- * A float that represents how likely it is that the audio file belongs to this class.
764
- */
765
- score: number
766
- }
767
- export declare type AudioClassificationReturn = AudioClassificationReturnValue[]
768
- type TextToImageArgs = Args & {
769
- /**
770
- * The text to generate an image from
771
- */
772
- inputs: string
773
- /**
774
- * An optional negative prompt for the image generation
775
- */
776
- negative_prompt?: string
777
- };
778
- type TextToImageReturn = ArrayBuffer
779
- ```
package/dist/index.d.ts CHANGED
@@ -339,9 +339,10 @@ type FeatureExtractionArgs = Args & {
339
339
  /**
340
340
  * The inputs vary based on the model. For example when using sentence-transformers/paraphrase-xlm-r-multilingual-v1 the inputs will look like this:
341
341
  *
342
- * inputs: {
342
+ * inputs: &#123;
343
343
  * "source_sentence": "That is a happy person",
344
344
  * "sentences": ["That is a happy dog", "That is a very happy person", "Today is a sunny day"]
345
+ * &#125;
345
346
  */
346
347
  inputs: Record<string, any> | Record<string, any>[];
347
348
  };
@@ -456,7 +457,7 @@ type TextToImageReturn = ArrayBuffer;
456
457
  declare class HfInference {
457
458
  private readonly apiKey;
458
459
  private readonly defaultOptions;
459
- constructor(apiKey: string, defaultOptions?: Options);
460
+ constructor(apiKey?: string, defaultOptions?: Options);
460
461
  /**
461
462
  * Tries to fill in a hole with a missing word (token to be precise). That’s the base task for BERT models.
462
463
  */
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(src_exports);
27
27
  var HfInference = class {
28
28
  apiKey;
29
29
  defaultOptions;
30
- constructor(apiKey, defaultOptions = {}) {
30
+ constructor(apiKey = "", defaultOptions = {}) {
31
31
  this.apiKey = apiKey;
32
32
  this.defaultOptions = defaultOptions;
33
33
  }
@@ -161,9 +161,13 @@ var HfInference = class {
161
161
  async request(args, options) {
162
162
  const mergedOptions = { ...this.defaultOptions, ...options };
163
163
  const { model, ...otherArgs } = args;
164
- const headers = {
165
- Authorization: `Bearer ${this.apiKey}`
166
- };
164
+ const headers = {};
165
+ if (this.apiKey) {
166
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
167
+ }
168
+ if (!options?.binary) {
169
+ headers["Content-Type"] = "application/json";
170
+ }
167
171
  if (options?.binary && mergedOptions.wait_for_model) {
168
172
  headers["X-Wait-For-Model"] = "true";
169
173
  }
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  var HfInference = class {
3
3
  apiKey;
4
4
  defaultOptions;
5
- constructor(apiKey, defaultOptions = {}) {
5
+ constructor(apiKey = "", defaultOptions = {}) {
6
6
  this.apiKey = apiKey;
7
7
  this.defaultOptions = defaultOptions;
8
8
  }
@@ -136,9 +136,13 @@ var HfInference = class {
136
136
  async request(args, options) {
137
137
  const mergedOptions = { ...this.defaultOptions, ...options };
138
138
  const { model, ...otherArgs } = args;
139
- const headers = {
140
- Authorization: `Bearer ${this.apiKey}`
141
- };
139
+ const headers = {};
140
+ if (this.apiKey) {
141
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
142
+ }
143
+ if (!options?.binary) {
144
+ headers["Content-Type"] = "application/json";
145
+ }
142
146
  if (options?.binary && mergedOptions.wait_for_model) {
143
147
  headers["X-Wait-For-Model"] = "true";
144
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "license": "MIT",
5
5
  "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript wrapper for the Hugging Face Inference API",
@@ -364,9 +364,10 @@ export type FeatureExtractionArgs = Args & {
364
364
  /**
365
365
  * The inputs vary based on the model. For example when using sentence-transformers/paraphrase-xlm-r-multilingual-v1 the inputs will look like this:
366
366
  *
367
- * inputs: {
367
+ * inputs: &#123;
368
368
  * "source_sentence": "That is a happy person",
369
369
  * "sentences": ["That is a happy dog", "That is a very happy person", "Today is a sunny day"]
370
+ * &#125;
370
371
  */
371
372
  inputs: Record<string, any> | Record<string, any>[];
372
373
  };
@@ -503,7 +504,7 @@ export class HfInference {
503
504
  private readonly apiKey: string;
504
505
  private readonly defaultOptions: Options;
505
506
 
506
- constructor(apiKey: string, defaultOptions: Options = {}) {
507
+ constructor(apiKey = "", defaultOptions: Options = {}) {
507
508
  this.apiKey = apiKey;
508
509
  this.defaultOptions = defaultOptions;
509
510
  }
@@ -680,13 +681,18 @@ export class HfInference {
680
681
  const mergedOptions = { ...this.defaultOptions, ...options };
681
682
  const { model, ...otherArgs } = args;
682
683
 
683
- const headers = {
684
- Authorization: `Bearer ${this.apiKey}`,
685
- }
684
+ const headers: Record<string, string> = {};
685
+ if (this.apiKey) {
686
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
687
+ }
688
+
689
+ if (!options?.binary) {
690
+ headers["Content-Type"] = "application/json";
691
+ }
686
692
 
687
- if (options?.binary && mergedOptions.wait_for_model) {
688
- headers["X-Wait-For-Model"] = "true";
689
- }
693
+ if (options?.binary && mergedOptions.wait_for_model) {
694
+ headers["X-Wait-For-Model"] = "true";
695
+ }
690
696
 
691
697
  const response = await fetch(`https://api-inference.huggingface.co/models/${model}`, {
692
698
  headers,