@huggingface/inference 3.6.2 → 3.7.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 (140) hide show
  1. package/README.md +0 -25
  2. package/dist/index.cjs +1232 -898
  3. package/dist/index.js +1234 -900
  4. package/dist/src/config.d.ts +1 -0
  5. package/dist/src/config.d.ts.map +1 -1
  6. package/dist/src/lib/getProviderHelper.d.ts +37 -0
  7. package/dist/src/lib/getProviderHelper.d.ts.map +1 -0
  8. package/dist/src/lib/makeRequestOptions.d.ts +0 -2
  9. package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
  10. package/dist/src/providers/black-forest-labs.d.ts +14 -18
  11. package/dist/src/providers/black-forest-labs.d.ts.map +1 -1
  12. package/dist/src/providers/cerebras.d.ts +4 -2
  13. package/dist/src/providers/cerebras.d.ts.map +1 -1
  14. package/dist/src/providers/cohere.d.ts +5 -2
  15. package/dist/src/providers/cohere.d.ts.map +1 -1
  16. package/dist/src/providers/fal-ai.d.ts +50 -3
  17. package/dist/src/providers/fal-ai.d.ts.map +1 -1
  18. package/dist/src/providers/fireworks-ai.d.ts +5 -2
  19. package/dist/src/providers/fireworks-ai.d.ts.map +1 -1
  20. package/dist/src/providers/hf-inference.d.ts +125 -2
  21. package/dist/src/providers/hf-inference.d.ts.map +1 -1
  22. package/dist/src/providers/hyperbolic.d.ts +31 -2
  23. package/dist/src/providers/hyperbolic.d.ts.map +1 -1
  24. package/dist/src/providers/nebius.d.ts +20 -18
  25. package/dist/src/providers/nebius.d.ts.map +1 -1
  26. package/dist/src/providers/novita.d.ts +21 -18
  27. package/dist/src/providers/novita.d.ts.map +1 -1
  28. package/dist/src/providers/openai.d.ts +4 -2
  29. package/dist/src/providers/openai.d.ts.map +1 -1
  30. package/dist/src/providers/providerHelper.d.ts +182 -0
  31. package/dist/src/providers/providerHelper.d.ts.map +1 -0
  32. package/dist/src/providers/replicate.d.ts +23 -19
  33. package/dist/src/providers/replicate.d.ts.map +1 -1
  34. package/dist/src/providers/sambanova.d.ts +4 -2
  35. package/dist/src/providers/sambanova.d.ts.map +1 -1
  36. package/dist/src/providers/together.d.ts +32 -2
  37. package/dist/src/providers/together.d.ts.map +1 -1
  38. package/dist/src/snippets/getInferenceSnippets.d.ts.map +1 -1
  39. package/dist/src/tasks/audio/audioClassification.d.ts.map +1 -1
  40. package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
  41. package/dist/src/tasks/audio/textToSpeech.d.ts.map +1 -1
  42. package/dist/src/tasks/audio/utils.d.ts +2 -1
  43. package/dist/src/tasks/audio/utils.d.ts.map +1 -1
  44. package/dist/src/tasks/custom/request.d.ts +1 -2
  45. package/dist/src/tasks/custom/request.d.ts.map +1 -1
  46. package/dist/src/tasks/custom/streamingRequest.d.ts +1 -2
  47. package/dist/src/tasks/custom/streamingRequest.d.ts.map +1 -1
  48. package/dist/src/tasks/cv/imageClassification.d.ts.map +1 -1
  49. package/dist/src/tasks/cv/imageSegmentation.d.ts.map +1 -1
  50. package/dist/src/tasks/cv/imageToImage.d.ts.map +1 -1
  51. package/dist/src/tasks/cv/imageToText.d.ts.map +1 -1
  52. package/dist/src/tasks/cv/objectDetection.d.ts +1 -1
  53. package/dist/src/tasks/cv/objectDetection.d.ts.map +1 -1
  54. package/dist/src/tasks/cv/textToImage.d.ts.map +1 -1
  55. package/dist/src/tasks/cv/textToVideo.d.ts +1 -1
  56. package/dist/src/tasks/cv/textToVideo.d.ts.map +1 -1
  57. package/dist/src/tasks/cv/zeroShotImageClassification.d.ts +1 -1
  58. package/dist/src/tasks/cv/zeroShotImageClassification.d.ts.map +1 -1
  59. package/dist/src/tasks/index.d.ts +6 -6
  60. package/dist/src/tasks/index.d.ts.map +1 -1
  61. package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts +1 -1
  62. package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -1
  63. package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -1
  64. package/dist/src/tasks/nlp/chatCompletion.d.ts +1 -1
  65. package/dist/src/tasks/nlp/chatCompletion.d.ts.map +1 -1
  66. package/dist/src/tasks/nlp/chatCompletionStream.d.ts +1 -1
  67. package/dist/src/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
  68. package/dist/src/tasks/nlp/featureExtraction.d.ts.map +1 -1
  69. package/dist/src/tasks/nlp/fillMask.d.ts.map +1 -1
  70. package/dist/src/tasks/nlp/questionAnswering.d.ts.map +1 -1
  71. package/dist/src/tasks/nlp/sentenceSimilarity.d.ts.map +1 -1
  72. package/dist/src/tasks/nlp/summarization.d.ts.map +1 -1
  73. package/dist/src/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -1
  74. package/dist/src/tasks/nlp/textClassification.d.ts.map +1 -1
  75. package/dist/src/tasks/nlp/textGeneration.d.ts.map +1 -1
  76. package/dist/src/tasks/nlp/tokenClassification.d.ts.map +1 -1
  77. package/dist/src/tasks/nlp/translation.d.ts.map +1 -1
  78. package/dist/src/tasks/nlp/zeroShotClassification.d.ts.map +1 -1
  79. package/dist/src/tasks/tabular/tabularClassification.d.ts.map +1 -1
  80. package/dist/src/tasks/tabular/tabularRegression.d.ts.map +1 -1
  81. package/dist/src/types.d.ts +10 -13
  82. package/dist/src/types.d.ts.map +1 -1
  83. package/dist/src/utils/request.d.ts +27 -0
  84. package/dist/src/utils/request.d.ts.map +1 -0
  85. package/package.json +3 -3
  86. package/src/config.ts +1 -0
  87. package/src/lib/getProviderHelper.ts +270 -0
  88. package/src/lib/makeRequestOptions.ts +36 -90
  89. package/src/providers/black-forest-labs.ts +73 -22
  90. package/src/providers/cerebras.ts +6 -27
  91. package/src/providers/cohere.ts +9 -28
  92. package/src/providers/fal-ai.ts +195 -77
  93. package/src/providers/fireworks-ai.ts +8 -29
  94. package/src/providers/hf-inference.ts +555 -34
  95. package/src/providers/hyperbolic.ts +107 -29
  96. package/src/providers/nebius.ts +65 -29
  97. package/src/providers/novita.ts +68 -32
  98. package/src/providers/openai.ts +6 -32
  99. package/src/providers/providerHelper.ts +354 -0
  100. package/src/providers/replicate.ts +124 -34
  101. package/src/providers/sambanova.ts +5 -30
  102. package/src/providers/together.ts +92 -28
  103. package/src/snippets/getInferenceSnippets.ts +16 -9
  104. package/src/snippets/templates.exported.ts +2 -2
  105. package/src/tasks/audio/audioClassification.ts +6 -9
  106. package/src/tasks/audio/audioToAudio.ts +5 -28
  107. package/src/tasks/audio/automaticSpeechRecognition.ts +7 -6
  108. package/src/tasks/audio/textToSpeech.ts +6 -30
  109. package/src/tasks/audio/utils.ts +2 -1
  110. package/src/tasks/custom/request.ts +7 -34
  111. package/src/tasks/custom/streamingRequest.ts +5 -87
  112. package/src/tasks/cv/imageClassification.ts +5 -9
  113. package/src/tasks/cv/imageSegmentation.ts +5 -10
  114. package/src/tasks/cv/imageToImage.ts +5 -8
  115. package/src/tasks/cv/imageToText.ts +8 -13
  116. package/src/tasks/cv/objectDetection.ts +6 -21
  117. package/src/tasks/cv/textToImage.ts +10 -138
  118. package/src/tasks/cv/textToVideo.ts +11 -59
  119. package/src/tasks/cv/zeroShotImageClassification.ts +7 -12
  120. package/src/tasks/index.ts +6 -6
  121. package/src/tasks/multimodal/documentQuestionAnswering.ts +10 -26
  122. package/src/tasks/multimodal/visualQuestionAnswering.ts +6 -12
  123. package/src/tasks/nlp/chatCompletion.ts +7 -23
  124. package/src/tasks/nlp/chatCompletionStream.ts +4 -5
  125. package/src/tasks/nlp/featureExtraction.ts +5 -20
  126. package/src/tasks/nlp/fillMask.ts +5 -18
  127. package/src/tasks/nlp/questionAnswering.ts +5 -23
  128. package/src/tasks/nlp/sentenceSimilarity.ts +5 -18
  129. package/src/tasks/nlp/summarization.ts +5 -8
  130. package/src/tasks/nlp/tableQuestionAnswering.ts +5 -29
  131. package/src/tasks/nlp/textClassification.ts +8 -14
  132. package/src/tasks/nlp/textGeneration.ts +13 -80
  133. package/src/tasks/nlp/textGenerationStream.ts +2 -2
  134. package/src/tasks/nlp/tokenClassification.ts +8 -24
  135. package/src/tasks/nlp/translation.ts +5 -8
  136. package/src/tasks/nlp/zeroShotClassification.ts +8 -22
  137. package/src/tasks/tabular/tabularClassification.ts +5 -8
  138. package/src/tasks/tabular/tabularRegression.ts +5 -8
  139. package/src/types.ts +11 -14
  140. package/src/utils/request.ts +161 -0
@@ -1 +1 @@
1
- {"version":3,"file":"sentenceSimilarity.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/sentenceSimilarity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,uBAAuB,CAAC;AAExE;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,wBAAwB,CAAC,CAWnC"}
1
+ {"version":3,"file":"sentenceSimilarity.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/sentenceSimilarity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,uBAAuB,CAAC;AAExE;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,wBAAwB,CAAC,CAOnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"summarization.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/summarization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,kBAAkB,CAAC;AAE9D;;GAEG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAU5G"}
1
+ {"version":3,"file":"summarization.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/summarization.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,kBAAkB,CAAC;AAE9D;;GAEG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAO5G"}
@@ -1 +1 @@
1
- {"version":3,"file":"tableQuestionAnswering.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/tableQuestionAnswering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEpG,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,2BAA2B,CAAC;AAEhF;;GAEG;AACH,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,4BAA4B,CAAC,MAAM,CAAC,CAAC,CAY/C"}
1
+ {"version":3,"file":"tableQuestionAnswering.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/tableQuestionAnswering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEpG,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,2BAA2B,CAAC;AAEhF;;GAEG;AACH,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,4BAA4B,CAAC,MAAM,CAAC,CAAC,CAO/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"textClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/textClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,uBAAuB,CAAC;AAExE;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,wBAAwB,CAAC,CAanC"}
1
+ {"version":3,"file":"textClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/textClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAE5F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,uBAAuB,CAAC;AAExE;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,sBAAsB,EAC5B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,wBAAwB,CAAC,CAOnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"textGeneration.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/textGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,mBAAmB,EACnB,oBAAoB,EAEpB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAKrD,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;AAkB1D;;GAEG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,QAAQ,GAAG,mBAAmB,EACpC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,oBAAoB,CAAC,CAuD/B"}
1
+ {"version":3,"file":"textGeneration.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/textGeneration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAGpF,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,YAAY,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;AAE1D;;GAEG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,QAAQ,GAAG,mBAAmB,EACpC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,oBAAoB,CAAC,CAU/B"}
@@ -1 +1 @@
1
- {"version":3,"file":"tokenClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/tokenClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE9F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,wBAAwB,CAAC;AAE1E;;GAEG;AACH,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,uBAAuB,EAC7B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,yBAAyB,CAAC,CAuBpC"}
1
+ {"version":3,"file":"tokenClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/tokenClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE9F,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,wBAAwB,CAAC;AAE1E;;GAEG;AACH,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,uBAAuB,EAC7B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,yBAAyB,CAAC,CAOpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"translation.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/translation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAC1D;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUtG"}
1
+ {"version":3,"file":"translation.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/translation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,gBAAgB,CAAC;AAC1D;;GAEG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAOtG"}
@@ -1 +1 @@
1
- {"version":3,"file":"zeroShotClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/zeroShotClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEpG,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,2BAA2B,CAAC;AAEhF;;GAEG;AACH,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,4BAA4B,CAAC,CAqBvC"}
1
+ {"version":3,"file":"zeroShotClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/nlp/zeroShotClassification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEpG,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIrD,MAAM,MAAM,0BAA0B,GAAG,QAAQ,GAAG,2BAA2B,CAAC;AAEhF;;GAEG;AACH,wBAAsB,sBAAsB,CAC3C,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,4BAA4B,CAAC,CAOvC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tabularClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/tabular/tabularClassification.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,yBAAyB,GAAG,QAAQ,GAAG;IAClD,MAAM,EAAE;QACP;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,EAAE,CAAC;AAEnD;;;;GAIG;AACH,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,yBAAyB,EAC/B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,2BAA2B,CAAC,CAUtC"}
1
+ {"version":3,"file":"tabularClassification.d.ts","sourceRoot":"","sources":["../../../../src/tasks/tabular/tabularClassification.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,yBAAyB,GAAG,QAAQ,GAAG;IAClD,MAAM,EAAE;QACP;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GAAG,MAAM,EAAE,CAAC;AAEnD;;;;GAIG;AACH,wBAAsB,qBAAqB,CAC1C,IAAI,EAAE,yBAAyB,EAC/B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,2BAA2B,CAAC,CAOtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"tabularRegression.d.ts","sourceRoot":"","sources":["../../../../src/tasks/tabular/tabularRegression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG;IAC9C,MAAM,EAAE;QACP;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,EAAE,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,qBAAqB,EAC3B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,uBAAuB,CAAC,CAUlC"}
1
+ {"version":3,"file":"tabularRegression.d.ts","sourceRoot":"","sources":["../../../../src/tasks/tabular/tabularRegression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG;IAC9C,MAAM,EAAE;QACP;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;KAC/B,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,EAAE,CAAC;AAE/C;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,IAAI,EAAE,qBAAqB,EAC3B,OAAO,CAAC,EAAE,OAAO,GACf,OAAO,CAAC,uBAAuB,CAAC,CAOlC"}
@@ -20,8 +20,15 @@ export interface Options {
20
20
  * (Default: "same-origin"). String | Boolean. Credentials to use for the request. If this is a string, it will be passed straight on. If it's a boolean, true will be "include" and false will not send credentials at all.
21
21
  */
22
22
  includeCredentials?: string | boolean;
23
+ /**
24
+ * The billing account to use for the requests.
25
+ *
26
+ * By default the requests are billed on the user's account.
27
+ * Requests can only be billed to an organization the user is a member of, and which has subscribed to Enterprise Hub.
28
+ */
29
+ billTo?: string;
23
30
  }
24
- export type InferenceTask = Exclude<PipelineType, "other">;
31
+ export type InferenceTask = Exclude<PipelineType, "other"> | "conversational";
25
32
  export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "fireworks-ai", "hf-inference", "hyperbolic", "nebius", "novita", "openai", "replicate", "sambanova", "together"];
26
33
  export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
27
34
  export interface BaseArgs {
@@ -68,13 +75,6 @@ export type RequestArgs = BaseArgs & ({
68
75
  } | ChatCompletionInput) & {
69
76
  parameters?: Record<string, unknown>;
70
77
  };
71
- export interface ProviderConfig {
72
- makeBaseUrl: ((task?: InferenceTask) => string) | (() => string);
73
- makeBody: (params: BodyParams) => Record<string, unknown>;
74
- makeHeaders: (params: HeaderParams) => Record<string, string>;
75
- makeUrl: (params: UrlParams) => string;
76
- clientSideRoutingOnly?: boolean;
77
- }
78
78
  export type AuthMethod = "none" | "hf-token" | "credentials-include" | "provider-key";
79
79
  export interface HeaderParams {
80
80
  accessToken?: string;
@@ -82,14 +82,11 @@ export interface HeaderParams {
82
82
  }
83
83
  export interface UrlParams {
84
84
  authMethod: AuthMethod;
85
- baseUrl: string;
86
85
  model: string;
87
86
  task?: InferenceTask;
88
- chatCompletion?: boolean;
89
87
  }
90
- export interface BodyParams {
91
- args: Record<string, unknown>;
92
- chatCompletion?: boolean;
88
+ export interface BodyParams<T extends Record<string, unknown> = Record<string, unknown>> {
89
+ args: T;
93
90
  model: string;
94
91
  task?: InferenceTask;
95
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,OAAO;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAE3D,eAAO,MAAM,mBAAmB,kLActB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,WAAW,QAAQ;IACxB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GACjC,CACG;IAAE,IAAI,EAAE,IAAI,GAAG,WAAW,CAAA;CAAE,GAC5B;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACnB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB,mBAAmB,CACrB,GAAG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEH,MAAM,WAAW,cAAc;IAC9B,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,aAAa,KAAK,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IACjE,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,WAAW,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9D,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAC;IACvC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,qBAAqB,GAAG,cAAc,CAAC;AAEtF,MAAM,WAAW,YAAY;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE5E;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,OAAO;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAEtC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,gBAAgB,CAAC;AAE9E,eAAO,MAAM,mBAAmB,kLActB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,WAAW,QAAQ;IACxB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GACjC,CACG;IAAE,IAAI,EAAE,IAAI,GAAG,WAAW,CAAA;CAAE,GAC5B;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,GACnB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACrB,mBAAmB,CACrB,GAAG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,qBAAqB,GAAG,cAAc,CAAC;AAEtF,MAAM,WAAW,YAAY;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
@@ -0,0 +1,27 @@
1
+ import type { InferenceTask, Options, RequestArgs } from "../types";
2
+ export interface ResponseWrapper<T> {
3
+ data: T;
4
+ requestContext: {
5
+ url: string;
6
+ info: RequestInit;
7
+ };
8
+ }
9
+ /**
10
+ * Primitive to make custom calls to the inference provider
11
+ */
12
+ export declare function innerRequest<T>(args: RequestArgs, options?: Options & {
13
+ /** In most cases (unless we pass a endpointUrl) we know the task */
14
+ task?: InferenceTask;
15
+ /** Is chat completion compatible */
16
+ chatCompletion?: boolean;
17
+ }): Promise<ResponseWrapper<T>>;
18
+ /**
19
+ * Primitive to make custom inference calls that expect server-sent events, and returns the response through a generator
20
+ */
21
+ export declare function innerStreamingRequest<T>(args: RequestArgs, options?: Options & {
22
+ /** In most cases (unless we pass a endpointUrl) we know the task */
23
+ task?: InferenceTask;
24
+ /** Is chat completion compatible */
25
+ chatCompletion?: boolean;
26
+ }): AsyncGenerator<T>;
27
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/utils/request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIpE,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC;IACR,cAAc,EAAE;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KAClB,CAAC;CACF;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EACnC,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAoC7B;AAED;;GAEG;AACH,wBAAuB,qBAAqB,CAAC,CAAC,EAC7C,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,cAAc,CAAC,CAAC,CAAC,CAuFnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "3.6.2",
3
+ "version": "3.7.1",
4
4
  "packageManager": "pnpm@8.10.5",
5
5
  "license": "MIT",
6
6
  "author": "Hugging Face and Tim Mikeladze <tim.mikeladze@gmail.com>",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "type": "module",
42
42
  "dependencies": {
43
- "@huggingface/tasks": "^0.18.4",
44
- "@huggingface/jinja": "^0.3.3"
43
+ "@huggingface/jinja": "^0.3.3",
44
+ "@huggingface/tasks": "^0.18.7"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "18.13.0"
package/src/config.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export const HF_HUB_URL = "https://huggingface.co";
2
2
  export const HF_ROUTER_URL = "https://router.huggingface.co";
3
+ export const HF_HEADER_X_BILL_TO = "X-HF-Bill-To";
@@ -0,0 +1,270 @@
1
+ import * as BlackForestLabs from "../providers/black-forest-labs";
2
+ import * as Cerebras from "../providers/cerebras";
3
+ import * as Cohere from "../providers/cohere";
4
+ import * as FalAI from "../providers/fal-ai";
5
+ import * as Fireworks from "../providers/fireworks-ai";
6
+ import * as HFInference from "../providers/hf-inference";
7
+
8
+ import * as Hyperbolic from "../providers/hyperbolic";
9
+ import * as Nebius from "../providers/nebius";
10
+ import * as Novita from "../providers/novita";
11
+ import * as OpenAI from "../providers/openai";
12
+ import type {
13
+ AudioClassificationTaskHelper,
14
+ AudioToAudioTaskHelper,
15
+ AutomaticSpeechRecognitionTaskHelper,
16
+ ConversationalTaskHelper,
17
+ DocumentQuestionAnsweringTaskHelper,
18
+ FeatureExtractionTaskHelper,
19
+ FillMaskTaskHelper,
20
+ ImageClassificationTaskHelper,
21
+ ImageSegmentationTaskHelper,
22
+ ImageToImageTaskHelper,
23
+ ImageToTextTaskHelper,
24
+ ObjectDetectionTaskHelper,
25
+ QuestionAnsweringTaskHelper,
26
+ SentenceSimilarityTaskHelper,
27
+ SummarizationTaskHelper,
28
+ TableQuestionAnsweringTaskHelper,
29
+ TabularClassificationTaskHelper,
30
+ TabularRegressionTaskHelper,
31
+ TaskProviderHelper,
32
+ TextClassificationTaskHelper,
33
+ TextGenerationTaskHelper,
34
+ TextToAudioTaskHelper,
35
+ TextToImageTaskHelper,
36
+ TextToSpeechTaskHelper,
37
+ TextToVideoTaskHelper,
38
+ TokenClassificationTaskHelper,
39
+ TranslationTaskHelper,
40
+ VisualQuestionAnsweringTaskHelper,
41
+ ZeroShotClassificationTaskHelper,
42
+ ZeroShotImageClassificationTaskHelper,
43
+ } from "../providers/providerHelper";
44
+ import * as Replicate from "../providers/replicate";
45
+ import * as Sambanova from "../providers/sambanova";
46
+ import * as Together from "../providers/together";
47
+ import type { InferenceProvider, InferenceTask } from "../types";
48
+
49
+ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask, TaskProviderHelper>>> = {
50
+ "black-forest-labs": {
51
+ "text-to-image": new BlackForestLabs.BlackForestLabsTextToImageTask(),
52
+ },
53
+ cerebras: {
54
+ conversational: new Cerebras.CerebrasConversationalTask(),
55
+ },
56
+ cohere: {
57
+ conversational: new Cohere.CohereConversationalTask(),
58
+ },
59
+ "fal-ai": {
60
+ "text-to-image": new FalAI.FalAITextToImageTask(),
61
+ "text-to-speech": new FalAI.FalAITextToSpeechTask(),
62
+ "text-to-video": new FalAI.FalAITextToVideoTask(),
63
+ "automatic-speech-recognition": new FalAI.FalAIAutomaticSpeechRecognitionTask(),
64
+ },
65
+ "hf-inference": {
66
+ "text-to-image": new HFInference.HFInferenceTextToImageTask(),
67
+ conversational: new HFInference.HFInferenceConversationalTask(),
68
+ "text-generation": new HFInference.HFInferenceTextGenerationTask(),
69
+ "text-classification": new HFInference.HFInferenceTextClassificationTask(),
70
+ "question-answering": new HFInference.HFInferenceQuestionAnsweringTask(),
71
+ "audio-classification": new HFInference.HFInferenceAudioClassificationTask(),
72
+ "automatic-speech-recognition": new HFInference.HFInferenceAutomaticSpeechRecognitionTask(),
73
+ "fill-mask": new HFInference.HFInferenceFillMaskTask(),
74
+ "feature-extraction": new HFInference.HFInferenceFeatureExtractionTask(),
75
+ "image-classification": new HFInference.HFInferenceImageClassificationTask(),
76
+ "image-segmentation": new HFInference.HFInferenceImageSegmentationTask(),
77
+ "document-question-answering": new HFInference.HFInferenceDocumentQuestionAnsweringTask(),
78
+ "image-to-text": new HFInference.HFInferenceImageToTextTask(),
79
+ "object-detection": new HFInference.HFInferenceObjectDetectionTask(),
80
+ "audio-to-audio": new HFInference.HFInferenceAudioToAudioTask(),
81
+ "zero-shot-image-classification": new HFInference.HFInferenceZeroShotImageClassificationTask(),
82
+ "zero-shot-classification": new HFInference.HFInferenceZeroShotClassificationTask(),
83
+ "image-to-image": new HFInference.HFInferenceImageToImageTask(),
84
+ "sentence-similarity": new HFInference.HFInferenceSentenceSimilarityTask(),
85
+ "table-question-answering": new HFInference.HFInferenceTableQuestionAnsweringTask(),
86
+ "tabular-classification": new HFInference.HFInferenceTabularClassificationTask(),
87
+ "text-to-speech": new HFInference.HFInferenceTextToSpeechTask(),
88
+ "token-classification": new HFInference.HFInferenceTokenClassificationTask(),
89
+ translation: new HFInference.HFInferenceTranslationTask(),
90
+ summarization: new HFInference.HFInferenceSummarizationTask(),
91
+ "visual-question-answering": new HFInference.HFInferenceVisualQuestionAnsweringTask(),
92
+ "tabular-regression": new HFInference.HFInferenceTabularRegressionTask(),
93
+ "text-to-audio": new HFInference.HFInferenceTextToAudioTask(),
94
+ },
95
+ "fireworks-ai": {
96
+ conversational: new Fireworks.FireworksConversationalTask(),
97
+ },
98
+ hyperbolic: {
99
+ "text-to-image": new Hyperbolic.HyperbolicTextToImageTask(),
100
+ conversational: new Hyperbolic.HyperbolicConversationalTask(),
101
+ "text-generation": new Hyperbolic.HyperbolicTextGenerationTask(),
102
+ },
103
+ nebius: {
104
+ "text-to-image": new Nebius.NebiusTextToImageTask(),
105
+ conversational: new Nebius.NebiusConversationalTask(),
106
+ "text-generation": new Nebius.NebiusTextGenerationTask(),
107
+ },
108
+ novita: {
109
+ conversational: new Novita.NovitaConversationalTask(),
110
+ "text-generation": new Novita.NovitaTextGenerationTask(),
111
+ },
112
+ openai: {
113
+ conversational: new OpenAI.OpenAIConversationalTask(),
114
+ },
115
+ replicate: {
116
+ "text-to-image": new Replicate.ReplicateTextToImageTask(),
117
+ "text-to-speech": new Replicate.ReplicateTextToSpeechTask(),
118
+ "text-to-video": new Replicate.ReplicateTextToVideoTask(),
119
+ },
120
+ sambanova: {
121
+ conversational: new Sambanova.SambanovaConversationalTask(),
122
+ },
123
+ together: {
124
+ "text-to-image": new Together.TogetherTextToImageTask(),
125
+ conversational: new Together.TogetherConversationalTask(),
126
+ "text-generation": new Together.TogetherTextGenerationTask(),
127
+ },
128
+ };
129
+
130
+ /**
131
+ * Get provider helper instance by name and task
132
+ */
133
+ export function getProviderHelper(
134
+ provider: InferenceProvider,
135
+ task: "text-to-image"
136
+ ): TextToImageTaskHelper & TaskProviderHelper;
137
+ export function getProviderHelper(
138
+ provider: InferenceProvider,
139
+ task: "conversational"
140
+ ): ConversationalTaskHelper & TaskProviderHelper;
141
+ export function getProviderHelper(
142
+ provider: InferenceProvider,
143
+ task: "text-generation"
144
+ ): TextGenerationTaskHelper & TaskProviderHelper;
145
+ export function getProviderHelper(
146
+ provider: InferenceProvider,
147
+ task: "text-to-speech"
148
+ ): TextToSpeechTaskHelper & TaskProviderHelper;
149
+ export function getProviderHelper(
150
+ provider: InferenceProvider,
151
+ task: "text-to-audio"
152
+ ): TextToAudioTaskHelper & TaskProviderHelper;
153
+ export function getProviderHelper(
154
+ provider: InferenceProvider,
155
+ task: "automatic-speech-recognition"
156
+ ): AutomaticSpeechRecognitionTaskHelper & TaskProviderHelper;
157
+ export function getProviderHelper(
158
+ provider: InferenceProvider,
159
+ task: "text-to-video"
160
+ ): TextToVideoTaskHelper & TaskProviderHelper;
161
+ export function getProviderHelper(
162
+ provider: InferenceProvider,
163
+ task: "text-classification"
164
+ ): TextClassificationTaskHelper & TaskProviderHelper;
165
+ export function getProviderHelper(
166
+ provider: InferenceProvider,
167
+ task: "question-answering"
168
+ ): QuestionAnsweringTaskHelper & TaskProviderHelper;
169
+ export function getProviderHelper(
170
+ provider: InferenceProvider,
171
+ task: "audio-classification"
172
+ ): AudioClassificationTaskHelper & TaskProviderHelper;
173
+ export function getProviderHelper(
174
+ provider: InferenceProvider,
175
+ task: "audio-to-audio"
176
+ ): AudioToAudioTaskHelper & TaskProviderHelper;
177
+ export function getProviderHelper(
178
+ provider: InferenceProvider,
179
+ task: "fill-mask"
180
+ ): FillMaskTaskHelper & TaskProviderHelper;
181
+ export function getProviderHelper(
182
+ provider: InferenceProvider,
183
+ task: "feature-extraction"
184
+ ): FeatureExtractionTaskHelper & TaskProviderHelper;
185
+ export function getProviderHelper(
186
+ provider: InferenceProvider,
187
+ task: "image-classification"
188
+ ): ImageClassificationTaskHelper & TaskProviderHelper;
189
+ export function getProviderHelper(
190
+ provider: InferenceProvider,
191
+ task: "image-segmentation"
192
+ ): ImageSegmentationTaskHelper & TaskProviderHelper;
193
+ export function getProviderHelper(
194
+ provider: InferenceProvider,
195
+ task: "document-question-answering"
196
+ ): DocumentQuestionAnsweringTaskHelper & TaskProviderHelper;
197
+ export function getProviderHelper(
198
+ provider: InferenceProvider,
199
+ task: "image-to-text"
200
+ ): ImageToTextTaskHelper & TaskProviderHelper;
201
+ export function getProviderHelper(
202
+ provider: InferenceProvider,
203
+ task: "object-detection"
204
+ ): ObjectDetectionTaskHelper & TaskProviderHelper;
205
+ export function getProviderHelper(
206
+ provider: InferenceProvider,
207
+ task: "zero-shot-image-classification"
208
+ ): ZeroShotImageClassificationTaskHelper & TaskProviderHelper;
209
+ export function getProviderHelper(
210
+ provider: InferenceProvider,
211
+ task: "zero-shot-classification"
212
+ ): ZeroShotClassificationTaskHelper & TaskProviderHelper;
213
+ export function getProviderHelper(
214
+ provider: InferenceProvider,
215
+ task: "image-to-image"
216
+ ): ImageToImageTaskHelper & TaskProviderHelper;
217
+ export function getProviderHelper(
218
+ provider: InferenceProvider,
219
+ task: "sentence-similarity"
220
+ ): SentenceSimilarityTaskHelper & TaskProviderHelper;
221
+ export function getProviderHelper(
222
+ provider: InferenceProvider,
223
+ task: "table-question-answering"
224
+ ): TableQuestionAnsweringTaskHelper & TaskProviderHelper;
225
+ export function getProviderHelper(
226
+ provider: InferenceProvider,
227
+ task: "tabular-classification"
228
+ ): TabularClassificationTaskHelper & TaskProviderHelper;
229
+ export function getProviderHelper(
230
+ provider: InferenceProvider,
231
+ task: "tabular-regression"
232
+ ): TabularRegressionTaskHelper & TaskProviderHelper;
233
+ export function getProviderHelper(
234
+ provider: InferenceProvider,
235
+ task: "token-classification"
236
+ ): TokenClassificationTaskHelper & TaskProviderHelper;
237
+ export function getProviderHelper(
238
+ provider: InferenceProvider,
239
+ task: "translation"
240
+ ): TranslationTaskHelper & TaskProviderHelper;
241
+ export function getProviderHelper(
242
+ provider: InferenceProvider,
243
+ task: "summarization"
244
+ ): SummarizationTaskHelper & TaskProviderHelper;
245
+ export function getProviderHelper(
246
+ provider: InferenceProvider,
247
+ task: "visual-question-answering"
248
+ ): VisualQuestionAnsweringTaskHelper & TaskProviderHelper;
249
+ export function getProviderHelper(provider: InferenceProvider, task: InferenceTask | undefined): TaskProviderHelper;
250
+
251
+ export function getProviderHelper(provider: InferenceProvider, task: InferenceTask | undefined): TaskProviderHelper {
252
+ if (provider === "hf-inference") {
253
+ if (!task) {
254
+ return new HFInference.HFInferenceTask();
255
+ }
256
+ }
257
+ if (!task) {
258
+ throw new Error("you need to provide a task name when using an external provider, e.g. 'text-to-image'");
259
+ }
260
+ if (!(provider in PROVIDERS)) {
261
+ throw new Error(`Provider '${provider}' not supported. Available providers: ${Object.keys(PROVIDERS)}`);
262
+ }
263
+ const providerTasks = PROVIDERS[provider];
264
+ if (!providerTasks || !(task in providerTasks)) {
265
+ throw new Error(
266
+ `Task '${task}' not supported for provider '${provider}'. Available tasks: ${Object.keys(providerTasks ?? {})}`
267
+ );
268
+ }
269
+ return providerTasks[task] as TaskProviderHelper;
270
+ }
@@ -1,23 +1,9 @@
1
- import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
2
- import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
3
- import { CEREBRAS_CONFIG } from "../providers/cerebras";
4
- import { COHERE_CONFIG } from "../providers/cohere";
5
- import { FAL_AI_CONFIG } from "../providers/fal-ai";
6
- import { FIREWORKS_AI_CONFIG } from "../providers/fireworks-ai";
7
- import { HF_INFERENCE_CONFIG } from "../providers/hf-inference";
8
- import { HYPERBOLIC_CONFIG } from "../providers/hyperbolic";
9
- import { NEBIUS_CONFIG } from "../providers/nebius";
10
- import { NOVITA_CONFIG } from "../providers/novita";
11
- import { REPLICATE_CONFIG } from "../providers/replicate";
12
- import { SAMBANOVA_CONFIG } from "../providers/sambanova";
13
- import { TOGETHER_CONFIG } from "../providers/together";
14
- import { OPENAI_CONFIG } from "../providers/openai";
15
- import type { InferenceProvider, InferenceTask, Options, ProviderConfig, RequestArgs } from "../types";
16
- import { isUrl } from "./isUrl";
17
- import { version as packageVersion, name as packageName } from "../../package.json";
1
+ import { name as packageName, version as packageVersion } from "../../package.json";
2
+ import { HF_HEADER_X_BILL_TO, HF_HUB_URL } from "../config";
3
+ import type { InferenceTask, Options, RequestArgs } from "../types";
4
+ import { getProviderHelper } from "./getProviderHelper";
18
5
  import { getProviderModelId } from "./getProviderModelId";
19
-
20
- const HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;
6
+ import { isUrl } from "./isUrl";
21
7
 
22
8
  /**
23
9
  * Lazy-loaded from huggingface.co/api/tasks when needed
@@ -25,25 +11,6 @@ const HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;
25
11
  */
26
12
  let tasks: Record<string, { models: { id: string }[] }> | null = null;
27
13
 
28
- /**
29
- * Config to define how to serialize requests for each provider
30
- */
31
- const providerConfigs: Record<InferenceProvider, ProviderConfig> = {
32
- "black-forest-labs": BLACK_FOREST_LABS_CONFIG,
33
- cerebras: CEREBRAS_CONFIG,
34
- cohere: COHERE_CONFIG,
35
- "fal-ai": FAL_AI_CONFIG,
36
- "fireworks-ai": FIREWORKS_AI_CONFIG,
37
- "hf-inference": HF_INFERENCE_CONFIG,
38
- hyperbolic: HYPERBOLIC_CONFIG,
39
- openai: OPENAI_CONFIG,
40
- nebius: NEBIUS_CONFIG,
41
- novita: NOVITA_CONFIG,
42
- replicate: REPLICATE_CONFIG,
43
- sambanova: SAMBANOVA_CONFIG,
44
- together: TOGETHER_CONFIG,
45
- };
46
-
47
14
  /**
48
15
  * Helper that prepares request arguments.
49
16
  * This async version handle the model ID resolution step.
@@ -56,14 +23,11 @@ export async function makeRequestOptions(
56
23
  options?: Options & {
57
24
  /** In most cases (unless we pass a endpointUrl) we know the task */
58
25
  task?: InferenceTask;
59
- chatCompletion?: boolean;
60
26
  }
61
27
  ): Promise<{ url: string; info: RequestInit }> {
62
28
  const { provider: maybeProvider, model: maybeModel } = args;
63
29
  const provider = maybeProvider ?? "hf-inference";
64
- const providerConfig = providerConfigs[provider];
65
- const { task, chatCompletion } = options ?? {};
66
-
30
+ const { task } = options ?? {};
67
31
  // Validate inputs
68
32
  if (args.endpointUrl && provider !== "hf-inference") {
69
33
  throw new Error(`Cannot use endpointUrl with a third-party provider.`);
@@ -74,21 +38,20 @@ export async function makeRequestOptions(
74
38
  if (!maybeModel && !task) {
75
39
  throw new Error("No model provided, and no task has been specified.");
76
40
  }
77
- if (!providerConfig) {
78
- throw new Error(`No provider config found for provider ${provider}`);
79
- }
80
- if (providerConfig.clientSideRoutingOnly && !maybeModel) {
81
- throw new Error(`Provider ${provider} requires a model ID to be passed directly.`);
82
- }
83
41
 
84
42
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
85
43
  const hfModel = maybeModel ?? (await loadDefaultModel(task!));
86
- const resolvedModel = providerConfig.clientSideRoutingOnly
44
+ const providerHelper = getProviderHelper(provider, task);
45
+
46
+ if (providerHelper.clientSideRoutingOnly && !maybeModel) {
47
+ throw new Error(`Provider ${provider} requires a model ID to be passed directly.`);
48
+ }
49
+
50
+ const resolvedModel = providerHelper.clientSideRoutingOnly
87
51
  ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
88
52
  removeProviderPrefix(maybeModel!, provider)
89
53
  : await getProviderModelId({ model: hfModel, provider }, args, {
90
54
  task,
91
- chatCompletion,
92
55
  fetch: options?.fetch,
93
56
  });
94
57
 
@@ -108,19 +71,17 @@ export function makeRequestOptionsFromResolvedModel(
108
71
  },
109
72
  options?: Options & {
110
73
  task?: InferenceTask;
111
- chatCompletion?: boolean;
112
74
  }
113
75
  ): { url: string; info: RequestInit } {
114
76
  const { accessToken, endpointUrl, provider: maybeProvider, model, ...remainingArgs } = args;
115
77
  void model;
116
78
 
117
79
  const provider = maybeProvider ?? "hf-inference";
118
- const providerConfig = providerConfigs[provider];
119
-
120
- const { includeCredentials, task, chatCompletion, signal } = options ?? {};
121
80
 
81
+ const { includeCredentials, task, signal, billTo } = options ?? {};
82
+ const providerHelper = getProviderHelper(provider, task);
122
83
  const authMethod = (() => {
123
- if (providerConfig.clientSideRoutingOnly) {
84
+ if (providerHelper.clientSideRoutingOnly) {
124
85
  // Closed-source providers require an accessToken (cannot be routed).
125
86
  if (accessToken && accessToken.startsWith("hf_")) {
126
87
  throw new Error(`Provider ${provider} is closed-source and does not support HF tokens.`);
@@ -138,31 +99,23 @@ export function makeRequestOptionsFromResolvedModel(
138
99
  })();
139
100
 
140
101
  // Make URL
141
- const url = endpointUrl
142
- ? chatCompletion
143
- ? endpointUrl + `/v1/chat/completions`
144
- : endpointUrl
145
- : providerConfig.makeUrl({
146
- authMethod,
147
- baseUrl:
148
- authMethod !== "provider-key"
149
- ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider)
150
- : providerConfig.makeBaseUrl(task),
151
- model: resolvedModel,
152
- chatCompletion,
153
- task,
154
- });
155
102
 
156
- // Make headers
157
- const binary = "data" in args && !!args.data;
158
- const headers = providerConfig.makeHeaders({
159
- accessToken,
103
+ const modelId = endpointUrl ?? resolvedModel;
104
+ const url = providerHelper.makeUrl({
160
105
  authMethod,
106
+ model: modelId,
107
+ task,
161
108
  });
162
-
163
- // Add content-type to headers
164
- if (!binary) {
165
- headers["Content-Type"] = "application/json";
109
+ // Make headers
110
+ const headers = providerHelper.prepareHeaders(
111
+ {
112
+ accessToken,
113
+ authMethod,
114
+ },
115
+ "data" in args && !!args.data
116
+ );
117
+ if (billTo) {
118
+ headers[HF_HEADER_X_BILL_TO] = billTo;
166
119
  }
167
120
 
168
121
  // Add user-agent to headers
@@ -174,17 +127,11 @@ export function makeRequestOptionsFromResolvedModel(
174
127
  headers["User-Agent"] = userAgent;
175
128
 
176
129
  // Make body
177
- const body = binary
178
- ? args.data
179
- : JSON.stringify(
180
- providerConfig.makeBody({
181
- args: remainingArgs as Record<string, unknown>,
182
- model: resolvedModel,
183
- task,
184
- chatCompletion,
185
- })
186
- );
187
-
130
+ const body = providerHelper.makeBody({
131
+ args: remainingArgs as Record<string, unknown>,
132
+ model: resolvedModel,
133
+ task,
134
+ });
188
135
  /**
189
136
  * For edge runtimes, leave 'credentials' undefined, otherwise cloudflare workers will error
190
137
  */
@@ -198,11 +145,10 @@ export function makeRequestOptionsFromResolvedModel(
198
145
  const info: RequestInit = {
199
146
  headers,
200
147
  method: "POST",
201
- body,
148
+ body: body,
202
149
  ...(credentials ? { credentials } : undefined),
203
150
  signal,
204
151
  };
205
-
206
152
  return { url, info };
207
153
  }
208
154