@huggingface/inference 3.13.2 → 3.14.0
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/dist/{src → commonjs}/InferenceClient.d.ts +2 -2
- package/dist/commonjs/InferenceClient.d.ts.map +1 -0
- package/dist/commonjs/InferenceClient.js +83 -0
- package/dist/commonjs/config.js +6 -0
- package/dist/commonjs/index.d.ts +7 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +49 -0
- package/dist/commonjs/lib/InferenceOutputError.js +10 -0
- package/dist/commonjs/lib/getDefaultTask.js +48 -0
- package/dist/{src → commonjs}/lib/getInferenceProviderMapping.d.ts +1 -1
- package/dist/{src → commonjs}/lib/getInferenceProviderMapping.d.ts.map +1 -1
- package/dist/commonjs/lib/getInferenceProviderMapping.js +81 -0
- package/dist/{src → commonjs}/lib/getProviderHelper.d.ts +2 -2
- package/dist/{src → commonjs}/lib/getProviderHelper.d.ts.map +1 -1
- package/dist/commonjs/lib/getProviderHelper.js +168 -0
- package/dist/commonjs/lib/isUrl.js +6 -0
- package/dist/{src → commonjs}/lib/makeRequestOptions.d.ts +3 -3
- package/dist/{src → commonjs}/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/commonjs/lib/makeRequestOptions.js +161 -0
- package/dist/commonjs/package.d.ts +3 -0
- package/dist/commonjs/package.d.ts.map +1 -0
- package/dist/commonjs/package.js +6 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/{src → commonjs}/providers/black-forest-labs.d.ts +2 -2
- package/dist/{src → commonjs}/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/commonjs/providers/black-forest-labs.js +82 -0
- package/dist/{src → commonjs}/providers/cerebras.d.ts +1 -1
- package/dist/{src → commonjs}/providers/cerebras.d.ts.map +1 -1
- package/dist/commonjs/providers/cerebras.js +26 -0
- package/dist/{src → commonjs}/providers/cohere.d.ts +1 -1
- package/dist/{src → commonjs}/providers/cohere.d.ts.map +1 -1
- package/dist/commonjs/providers/cohere.js +29 -0
- package/dist/{src → commonjs}/providers/consts.d.ts +3 -3
- package/dist/commonjs/providers/consts.d.ts.map +1 -0
- package/dist/commonjs/providers/consts.js +35 -0
- package/dist/{src → commonjs}/providers/fal-ai.d.ts +3 -3
- package/dist/{src → commonjs}/providers/fal-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/fal-ai.js +216 -0
- package/dist/{src → commonjs}/providers/featherless-ai.d.ts +2 -2
- package/dist/{src → commonjs}/providers/featherless-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/featherless-ai.js +38 -0
- package/dist/{src → commonjs}/providers/fireworks-ai.d.ts +1 -1
- package/dist/commonjs/providers/fireworks-ai.d.ts.map +1 -0
- package/dist/commonjs/providers/fireworks-ai.js +29 -0
- package/dist/{src → commonjs}/providers/groq.d.ts +1 -1
- package/dist/{src → commonjs}/providers/groq.d.ts.map +1 -1
- package/dist/commonjs/providers/groq.js +39 -0
- package/dist/{src → commonjs}/providers/hf-inference.d.ts +6 -6
- package/dist/{src → commonjs}/providers/hf-inference.d.ts.map +1 -1
- package/dist/commonjs/providers/hf-inference.js +432 -0
- package/dist/{src → commonjs}/providers/hyperbolic.d.ts +2 -2
- package/dist/{src → commonjs}/providers/hyperbolic.d.ts.map +1 -1
- package/dist/commonjs/providers/hyperbolic.js +78 -0
- package/dist/{src → commonjs}/providers/nebius.d.ts +2 -2
- package/dist/{src → commonjs}/providers/nebius.d.ts.map +1 -1
- package/dist/commonjs/providers/nebius.js +70 -0
- package/dist/{src → commonjs}/providers/novita.d.ts +2 -2
- package/dist/{src → commonjs}/providers/novita.d.ts.map +1 -1
- package/dist/commonjs/providers/novita.js +73 -0
- package/dist/{src → commonjs}/providers/nscale.d.ts +2 -2
- package/dist/{src → commonjs}/providers/nscale.d.ts.map +1 -1
- package/dist/commonjs/providers/nscale.js +46 -0
- package/dist/{src → commonjs}/providers/openai.d.ts +1 -1
- package/dist/{src → commonjs}/providers/openai.d.ts.map +1 -1
- package/dist/commonjs/providers/openai.js +15 -0
- package/dist/{src → commonjs}/providers/ovhcloud.d.ts +2 -2
- package/dist/{src → commonjs}/providers/ovhcloud.d.ts.map +1 -1
- package/dist/commonjs/providers/ovhcloud.js +60 -0
- package/dist/{src → commonjs}/providers/providerHelper.d.ts +4 -4
- package/dist/{src → commonjs}/providers/providerHelper.d.ts.map +1 -1
- package/dist/commonjs/providers/providerHelper.js +108 -0
- package/dist/{src → commonjs}/providers/replicate.d.ts +2 -2
- package/dist/{src → commonjs}/providers/replicate.d.ts.map +1 -1
- package/dist/commonjs/providers/replicate.js +135 -0
- package/dist/{src → commonjs}/providers/sambanova.d.ts +3 -3
- package/dist/{src → commonjs}/providers/sambanova.d.ts.map +1 -1
- package/dist/commonjs/providers/sambanova.js +49 -0
- package/dist/{src → commonjs}/providers/together.d.ts +2 -2
- package/dist/{src → commonjs}/providers/together.d.ts.map +1 -1
- package/dist/commonjs/providers/together.js +71 -0
- package/dist/{src → commonjs}/snippets/getInferenceSnippets.d.ts +2 -2
- package/dist/{src → commonjs}/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +312 -0
- package/dist/commonjs/snippets/index.js +5 -0
- package/dist/commonjs/snippets/templates.exported.js +81 -0
- package/dist/{src → commonjs}/tasks/audio/audioClassification.d.ts +2 -2
- package/dist/{src → commonjs}/tasks/audio/audioClassification.d.ts.map +1 -1
- package/dist/commonjs/tasks/audio/audioClassification.js +21 -0
- package/dist/{src → commonjs}/tasks/audio/audioToAudio.d.ts +2 -2
- package/dist/commonjs/tasks/audio/audioToAudio.d.ts.map +1 -0
- package/dist/commonjs/tasks/audio/audioToAudio.js +22 -0
- package/dist/{src → commonjs}/tasks/audio/automaticSpeechRecognition.d.ts +2 -2
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -0
- package/dist/commonjs/tasks/audio/automaticSpeechRecognition.js +25 -0
- package/dist/{src → commonjs}/tasks/audio/textToSpeech.d.ts +1 -1
- package/dist/commonjs/tasks/audio/textToSpeech.d.ts.map +1 -0
- package/dist/commonjs/tasks/audio/textToSpeech.js +19 -0
- package/dist/{src → commonjs}/tasks/audio/utils.d.ts +1 -1
- package/dist/commonjs/tasks/audio/utils.d.ts.map +1 -0
- package/dist/commonjs/tasks/audio/utils.js +12 -0
- package/dist/{src → commonjs}/tasks/custom/request.d.ts +1 -1
- package/dist/commonjs/tasks/custom/request.d.ts.map +1 -0
- package/dist/commonjs/tasks/custom/request.js +17 -0
- package/dist/{src → commonjs}/tasks/custom/streamingRequest.d.ts +1 -1
- package/dist/commonjs/tasks/custom/streamingRequest.d.ts.map +1 -0
- package/dist/commonjs/tasks/custom/streamingRequest.js +16 -0
- package/dist/{src → commonjs}/tasks/cv/imageClassification.d.ts +2 -2
- package/dist/commonjs/tasks/cv/imageClassification.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/imageClassification.js +21 -0
- package/dist/{src → commonjs}/tasks/cv/imageSegmentation.d.ts +2 -2
- package/dist/commonjs/tasks/cv/imageSegmentation.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/imageSegmentation.js +21 -0
- package/dist/{src → commonjs}/tasks/cv/imageToImage.d.ts +1 -1
- package/dist/commonjs/tasks/cv/imageToImage.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/imageToImage.js +20 -0
- package/dist/{src → commonjs}/tasks/cv/imageToText.d.ts +2 -2
- package/dist/commonjs/tasks/cv/imageToText.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/imageToText.js +20 -0
- package/dist/{src → commonjs}/tasks/cv/objectDetection.d.ts +2 -2
- package/dist/commonjs/tasks/cv/objectDetection.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/objectDetection.js +21 -0
- package/dist/{src → commonjs}/tasks/cv/textToImage.d.ts +1 -1
- package/dist/commonjs/tasks/cv/textToImage.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/textToImage.js +17 -0
- package/dist/{src → commonjs}/tasks/cv/textToVideo.d.ts +1 -1
- package/dist/commonjs/tasks/cv/textToVideo.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/textToVideo.js +17 -0
- package/dist/{src → commonjs}/tasks/cv/utils.d.ts +1 -1
- package/dist/commonjs/tasks/cv/utils.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/utils.js +7 -0
- package/dist/{src → commonjs}/tasks/cv/zeroShotImageClassification.d.ts +1 -1
- package/dist/commonjs/tasks/cv/zeroShotImageClassification.d.ts.map +1 -0
- package/dist/commonjs/tasks/cv/zeroShotImageClassification.js +39 -0
- package/dist/commonjs/tasks/index.d.ts +33 -0
- package/dist/commonjs/tasks/index.d.ts.map +1 -0
- package/dist/commonjs/tasks/index.js +54 -0
- package/dist/{src → commonjs}/tasks/multimodal/documentQuestionAnswering.d.ts +1 -1
- package/dist/commonjs/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -0
- package/dist/commonjs/tasks/multimodal/documentQuestionAnswering.js +27 -0
- package/dist/{src → commonjs}/tasks/multimodal/visualQuestionAnswering.d.ts +1 -1
- package/dist/commonjs/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -0
- package/dist/commonjs/tasks/multimodal/visualQuestionAnswering.js +27 -0
- package/dist/{src → commonjs}/tasks/nlp/chatCompletion.d.ts +1 -1
- package/dist/{src → commonjs}/tasks/nlp/chatCompletion.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/chatCompletion.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/chatCompletionStream.d.ts +1 -1
- package/dist/{src → commonjs}/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/chatCompletionStream.js +17 -0
- package/dist/{src → commonjs}/tasks/nlp/featureExtraction.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/featureExtraction.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/featureExtraction.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/fillMask.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/fillMask.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/fillMask.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/questionAnswering.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/questionAnswering.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/questionAnswering.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/sentenceSimilarity.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/sentenceSimilarity.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/sentenceSimilarity.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/summarization.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/summarization.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/summarization.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/tableQuestionAnswering.d.ts +1 -1
- package/dist/{src → commonjs}/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/tableQuestionAnswering.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/textClassification.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/textClassification.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/textClassification.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/textGeneration.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/textGeneration.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/textGeneration.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/textGenerationStream.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/textGenerationStream.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/textGenerationStream.js +17 -0
- package/dist/{src → commonjs}/tasks/nlp/tokenClassification.d.ts +1 -1
- package/dist/{src → commonjs}/tasks/nlp/tokenClassification.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/tokenClassification.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/translation.d.ts +1 -1
- package/dist/commonjs/tasks/nlp/translation.d.ts.map +1 -0
- package/dist/commonjs/tasks/nlp/translation.js +18 -0
- package/dist/{src → commonjs}/tasks/nlp/zeroShotClassification.d.ts +1 -1
- package/dist/{src → commonjs}/tasks/nlp/zeroShotClassification.d.ts.map +1 -1
- package/dist/commonjs/tasks/nlp/zeroShotClassification.js +18 -0
- package/dist/{src → commonjs}/tasks/tabular/tabularClassification.d.ts +1 -1
- package/dist/commonjs/tasks/tabular/tabularClassification.d.ts.map +1 -0
- package/dist/commonjs/tasks/tabular/tabularClassification.js +20 -0
- package/dist/{src → commonjs}/tasks/tabular/tabularRegression.d.ts +1 -1
- package/dist/commonjs/tasks/tabular/tabularRegression.d.ts.map +1 -0
- package/dist/commonjs/tasks/tabular/tabularRegression.js +20 -0
- package/dist/{src → commonjs}/types.d.ts +1 -1
- package/dist/{src → commonjs}/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +23 -0
- package/dist/commonjs/utils/base64FromBytes.js +15 -0
- package/dist/commonjs/utils/delay.js +8 -0
- package/dist/commonjs/utils/distributive-omit.js +7 -0
- package/dist/commonjs/utils/isBackend.js +6 -0
- package/dist/commonjs/utils/isFrontend.js +5 -0
- package/dist/commonjs/utils/omit.js +13 -0
- package/dist/commonjs/utils/pick.js +13 -0
- package/dist/{src → commonjs}/utils/request.d.ts +2 -2
- package/dist/{src → commonjs}/utils/request.d.ts.map +1 -1
- package/dist/commonjs/utils/request.js +116 -0
- package/dist/commonjs/utils/toArray.js +9 -0
- package/dist/commonjs/utils/typedEntries.js +6 -0
- package/dist/commonjs/utils/typedInclude.js +6 -0
- package/dist/commonjs/vendor/fetch-event-source/parse.d.ts.map +1 -0
- package/dist/commonjs/vendor/fetch-event-source/parse.js +185 -0
- package/dist/commonjs/vendor/fetch-event-source/parse.spec.js +370 -0
- package/dist/esm/InferenceClient.d.ts +32 -0
- package/dist/esm/InferenceClient.d.ts.map +1 -0
- package/dist/esm/InferenceClient.js +44 -0
- package/dist/esm/config.d.ts +4 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +3 -0
- package/dist/esm/index.d.ts +7 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/{src/index.d.ts → esm/index.js} +4 -5
- package/dist/esm/lib/InferenceOutputError.d.ts +4 -0
- package/dist/esm/lib/InferenceOutputError.d.ts.map +1 -0
- package/dist/esm/lib/InferenceOutputError.js +6 -0
- package/dist/esm/lib/getDefaultTask.d.ts +11 -0
- package/dist/esm/lib/getDefaultTask.d.ts.map +1 -0
- package/dist/esm/lib/getDefaultTask.js +45 -0
- package/dist/esm/lib/getInferenceProviderMapping.d.ts +25 -0
- package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -0
- package/dist/esm/lib/getInferenceProviderMapping.js +75 -0
- package/dist/esm/lib/getProviderHelper.d.ts +37 -0
- package/dist/esm/lib/getProviderHelper.d.ts.map +1 -0
- package/dist/esm/lib/getProviderHelper.js +131 -0
- package/dist/esm/lib/isUrl.d.ts +2 -0
- package/dist/esm/lib/isUrl.d.ts.map +1 -0
- package/dist/esm/lib/isUrl.js +3 -0
- package/dist/esm/lib/makeRequestOptions.d.ts +31 -0
- package/dist/esm/lib/makeRequestOptions.d.ts.map +1 -0
- package/dist/esm/lib/makeRequestOptions.js +157 -0
- package/dist/esm/package.d.ts +3 -0
- package/dist/esm/package.d.ts.map +1 -0
- package/dist/esm/package.js +3 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/providers/black-forest-labs.d.ts +15 -0
- package/dist/esm/providers/black-forest-labs.d.ts.map +1 -0
- package/dist/esm/providers/black-forest-labs.js +78 -0
- package/dist/esm/providers/cerebras.d.ts +21 -0
- package/dist/esm/providers/cerebras.d.ts.map +1 -0
- package/dist/esm/providers/cerebras.js +22 -0
- package/dist/esm/providers/cohere.d.ts +22 -0
- package/dist/esm/providers/cohere.d.ts.map +1 -0
- package/dist/esm/providers/cohere.js +25 -0
- package/dist/esm/providers/consts.d.ts +12 -0
- package/dist/esm/providers/consts.d.ts.map +1 -0
- package/dist/esm/providers/consts.js +32 -0
- package/dist/esm/providers/fal-ai.d.ts +42 -0
- package/dist/esm/providers/fal-ai.d.ts.map +1 -0
- package/dist/esm/providers/fal-ai.js +209 -0
- package/dist/esm/providers/featherless-ai.d.ts +22 -0
- package/dist/esm/providers/featherless-ai.d.ts.map +1 -0
- package/dist/esm/providers/featherless-ai.js +33 -0
- package/dist/esm/providers/fireworks-ai.d.ts +22 -0
- package/dist/esm/providers/fireworks-ai.d.ts.map +1 -0
- package/dist/esm/providers/fireworks-ai.js +25 -0
- package/dist/esm/providers/groq.d.ts +10 -0
- package/dist/esm/providers/groq.d.ts.map +1 -0
- package/dist/esm/providers/groq.js +34 -0
- package/dist/esm/providers/hf-inference.d.ts +131 -0
- package/dist/esm/providers/hf-inference.d.ts.map +1 -0
- package/dist/esm/providers/hf-inference.js +400 -0
- package/dist/esm/providers/hyperbolic.d.ts +48 -0
- package/dist/esm/providers/hyperbolic.d.ts.map +1 -0
- package/dist/esm/providers/hyperbolic.js +72 -0
- package/dist/esm/providers/nebius.d.ts +49 -0
- package/dist/esm/providers/nebius.d.ts.map +1 -0
- package/dist/esm/providers/nebius.js +63 -0
- package/dist/esm/providers/novita.d.ts +22 -0
- package/dist/esm/providers/novita.d.ts.map +1 -0
- package/dist/esm/providers/novita.js +67 -0
- package/dist/esm/providers/nscale.d.ts +35 -0
- package/dist/esm/providers/nscale.d.ts.map +1 -0
- package/dist/esm/providers/nscale.js +41 -0
- package/dist/esm/providers/openai.d.ts +8 -0
- package/dist/esm/providers/openai.d.ts.map +1 -0
- package/dist/esm/providers/openai.js +11 -0
- package/dist/esm/providers/ovhcloud.d.ts +38 -0
- package/dist/esm/providers/ovhcloud.d.ts.map +1 -0
- package/dist/esm/providers/ovhcloud.js +55 -0
- package/dist/esm/providers/providerHelper.d.ts +186 -0
- package/dist/esm/providers/providerHelper.d.ts.map +1 -0
- package/dist/esm/providers/providerHelper.js +102 -0
- package/dist/esm/providers/replicate.d.ts +25 -0
- package/dist/esm/providers/replicate.d.ts.map +1 -0
- package/dist/esm/providers/replicate.js +129 -0
- package/dist/esm/providers/sambanova.d.ts +14 -0
- package/dist/esm/providers/sambanova.d.ts.map +1 -0
- package/dist/esm/providers/sambanova.js +44 -0
- package/dist/esm/providers/together.d.ts +49 -0
- package/dist/esm/providers/together.d.ts.map +1 -0
- package/dist/esm/providers/together.js +65 -0
- package/dist/esm/snippets/getInferenceSnippets.d.ts +9 -0
- package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -0
- package/dist/esm/snippets/getInferenceSnippets.js +309 -0
- package/dist/esm/snippets/index.d.ts +2 -0
- package/dist/esm/snippets/index.d.ts.map +1 -0
- package/dist/esm/snippets/index.js +1 -0
- package/dist/esm/snippets/templates.exported.d.ts +2 -0
- package/dist/esm/snippets/templates.exported.d.ts.map +1 -0
- package/dist/esm/snippets/templates.exported.js +78 -0
- package/dist/esm/tasks/audio/audioClassification.d.ts +10 -0
- package/dist/esm/tasks/audio/audioClassification.d.ts.map +1 -0
- package/dist/esm/tasks/audio/audioClassification.js +18 -0
- package/dist/esm/tasks/audio/audioToAudio.d.ts +29 -0
- package/dist/esm/tasks/audio/audioToAudio.d.ts.map +1 -0
- package/dist/esm/tasks/audio/audioToAudio.js +19 -0
- package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts +10 -0
- package/dist/esm/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -0
- package/dist/esm/tasks/audio/automaticSpeechRecognition.js +22 -0
- package/dist/esm/tasks/audio/textToSpeech.d.ts +10 -0
- package/dist/esm/tasks/audio/textToSpeech.d.ts.map +1 -0
- package/dist/esm/tasks/audio/textToSpeech.js +16 -0
- package/dist/esm/tasks/audio/utils.d.ts +12 -0
- package/dist/esm/tasks/audio/utils.d.ts.map +1 -0
- package/dist/esm/tasks/audio/utils.js +9 -0
- package/dist/esm/tasks/custom/request.d.ts +10 -0
- package/dist/esm/tasks/custom/request.d.ts.map +1 -0
- package/dist/esm/tasks/custom/request.js +14 -0
- package/dist/esm/tasks/custom/streamingRequest.d.ts +10 -0
- package/dist/esm/tasks/custom/streamingRequest.d.ts.map +1 -0
- package/dist/esm/tasks/custom/streamingRequest.js +13 -0
- package/dist/esm/tasks/cv/imageClassification.d.ts +10 -0
- package/dist/esm/tasks/cv/imageClassification.d.ts.map +1 -0
- package/dist/esm/tasks/cv/imageClassification.js +18 -0
- package/dist/esm/tasks/cv/imageSegmentation.d.ts +10 -0
- package/dist/esm/tasks/cv/imageSegmentation.d.ts.map +1 -0
- package/dist/esm/tasks/cv/imageSegmentation.js +18 -0
- package/dist/esm/tasks/cv/imageToImage.d.ts +9 -0
- package/dist/esm/tasks/cv/imageToImage.d.ts.map +1 -0
- package/dist/esm/tasks/cv/imageToImage.js +17 -0
- package/dist/esm/tasks/cv/imageToText.d.ts +9 -0
- package/dist/esm/tasks/cv/imageToText.d.ts.map +1 -0
- package/dist/esm/tasks/cv/imageToText.js +17 -0
- package/dist/esm/tasks/cv/objectDetection.d.ts +10 -0
- package/dist/esm/tasks/cv/objectDetection.d.ts.map +1 -0
- package/dist/esm/tasks/cv/objectDetection.js +18 -0
- package/dist/esm/tasks/cv/textToImage.d.ts +18 -0
- package/dist/esm/tasks/cv/textToImage.d.ts.map +1 -0
- package/dist/esm/tasks/cv/textToImage.js +14 -0
- package/dist/esm/tasks/cv/textToVideo.d.ts +6 -0
- package/dist/esm/tasks/cv/textToVideo.d.ts.map +1 -0
- package/dist/esm/tasks/cv/textToVideo.js +14 -0
- package/dist/esm/tasks/cv/utils.d.ts +11 -0
- package/dist/esm/tasks/cv/utils.d.ts.map +1 -0
- package/dist/esm/tasks/cv/utils.js +4 -0
- package/dist/esm/tasks/cv/zeroShotImageClassification.d.ts +18 -0
- package/dist/esm/tasks/cv/zeroShotImageClassification.d.ts.map +1 -0
- package/dist/esm/tasks/cv/zeroShotImageClassification.js +36 -0
- package/dist/esm/tasks/index.d.ts +33 -0
- package/dist/esm/tasks/index.d.ts.map +1 -0
- package/dist/esm/tasks/index.js +38 -0
- package/dist/esm/tasks/multimodal/documentQuestionAnswering.d.ts +12 -0
- package/dist/esm/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -0
- package/dist/esm/tasks/multimodal/documentQuestionAnswering.js +24 -0
- package/dist/esm/tasks/multimodal/visualQuestionAnswering.d.ts +12 -0
- package/dist/esm/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -0
- package/dist/esm/tasks/multimodal/visualQuestionAnswering.js +24 -0
- package/dist/esm/tasks/nlp/chatCompletion.d.ts +7 -0
- package/dist/esm/tasks/nlp/chatCompletion.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/chatCompletion.js +15 -0
- package/dist/esm/tasks/nlp/chatCompletionStream.d.ts +7 -0
- package/dist/esm/tasks/nlp/chatCompletionStream.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/chatCompletionStream.js +14 -0
- package/dist/esm/tasks/nlp/featureExtraction.d.ts +17 -0
- package/dist/esm/tasks/nlp/featureExtraction.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/featureExtraction.js +15 -0
- package/dist/esm/tasks/nlp/fillMask.d.ts +8 -0
- package/dist/esm/tasks/nlp/fillMask.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/fillMask.js +15 -0
- package/dist/esm/tasks/nlp/questionAnswering.d.ts +8 -0
- package/dist/esm/tasks/nlp/questionAnswering.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/questionAnswering.js +15 -0
- package/dist/esm/tasks/nlp/sentenceSimilarity.d.ts +8 -0
- package/dist/esm/tasks/nlp/sentenceSimilarity.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/sentenceSimilarity.js +15 -0
- package/dist/esm/tasks/nlp/summarization.d.ts +8 -0
- package/dist/esm/tasks/nlp/summarization.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/summarization.js +15 -0
- package/dist/esm/tasks/nlp/tableQuestionAnswering.d.ts +8 -0
- package/dist/esm/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/tableQuestionAnswering.js +15 -0
- package/dist/esm/tasks/nlp/textClassification.d.ts +8 -0
- package/dist/esm/tasks/nlp/textClassification.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/textClassification.js +15 -0
- package/dist/esm/tasks/nlp/textGeneration.d.ts +8 -0
- package/dist/esm/tasks/nlp/textGeneration.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/textGeneration.js +15 -0
- package/dist/esm/tasks/nlp/textGenerationStream.d.ts +81 -0
- package/dist/esm/tasks/nlp/textGenerationStream.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/textGenerationStream.js +14 -0
- package/dist/esm/tasks/nlp/tokenClassification.d.ts +8 -0
- package/dist/esm/tasks/nlp/tokenClassification.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/tokenClassification.js +15 -0
- package/dist/esm/tasks/nlp/translation.d.ts +8 -0
- package/dist/esm/tasks/nlp/translation.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/translation.js +15 -0
- package/dist/esm/tasks/nlp/zeroShotClassification.d.ts +8 -0
- package/dist/esm/tasks/nlp/zeroShotClassification.d.ts.map +1 -0
- package/dist/esm/tasks/nlp/zeroShotClassification.js +15 -0
- package/dist/esm/tasks/tabular/tabularClassification.d.ts +20 -0
- package/dist/esm/tasks/tabular/tabularClassification.d.ts.map +1 -0
- package/dist/esm/tasks/tabular/tabularClassification.js +17 -0
- package/dist/esm/tasks/tabular/tabularRegression.d.ts +20 -0
- package/dist/esm/tasks/tabular/tabularRegression.d.ts.map +1 -0
- package/dist/esm/tasks/tabular/tabularRegression.js +17 -0
- package/dist/esm/types.d.ts +97 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +20 -0
- package/dist/esm/utils/base64FromBytes.d.ts +2 -0
- package/dist/esm/utils/base64FromBytes.d.ts.map +1 -0
- package/dist/esm/utils/base64FromBytes.js +12 -0
- package/dist/esm/utils/delay.d.ts +2 -0
- package/dist/esm/utils/delay.d.ts.map +1 -0
- package/dist/esm/utils/delay.js +5 -0
- package/dist/esm/utils/distributive-omit.d.ts +9 -0
- package/dist/esm/utils/distributive-omit.d.ts.map +1 -0
- package/dist/esm/utils/distributive-omit.js +6 -0
- package/dist/esm/utils/isBackend.d.ts +2 -0
- package/dist/esm/utils/isBackend.d.ts.map +1 -0
- package/dist/esm/utils/isBackend.js +3 -0
- package/dist/esm/utils/isFrontend.d.ts +2 -0
- package/dist/esm/utils/isFrontend.d.ts.map +1 -0
- package/dist/esm/utils/isFrontend.js +2 -0
- package/dist/esm/utils/omit.d.ts +5 -0
- package/dist/esm/utils/omit.d.ts.map +1 -0
- package/dist/esm/utils/omit.js +10 -0
- package/dist/esm/utils/pick.d.ts +5 -0
- package/dist/esm/utils/pick.d.ts.map +1 -0
- package/dist/esm/utils/pick.js +10 -0
- package/dist/esm/utils/request.d.ts +28 -0
- package/dist/esm/utils/request.d.ts.map +1 -0
- package/dist/esm/utils/request.js +112 -0
- package/dist/esm/utils/toArray.d.ts +2 -0
- package/dist/esm/utils/toArray.d.ts.map +1 -0
- package/dist/esm/utils/toArray.js +6 -0
- package/dist/esm/utils/typedEntries.d.ts +4 -0
- package/dist/esm/utils/typedEntries.d.ts.map +1 -0
- package/dist/esm/utils/typedEntries.js +3 -0
- package/dist/esm/utils/typedInclude.d.ts +2 -0
- package/dist/esm/utils/typedInclude.d.ts.map +1 -0
- package/dist/esm/utils/typedInclude.js +3 -0
- package/dist/esm/vendor/fetch-event-source/parse.d.ts +69 -0
- package/dist/esm/vendor/fetch-event-source/parse.d.ts.map +1 -0
- package/dist/esm/vendor/fetch-event-source/parse.js +180 -0
- package/dist/esm/vendor/fetch-event-source/parse.spec.d.ts +2 -0
- package/dist/esm/vendor/fetch-event-source/parse.spec.d.ts.map +1 -0
- package/dist/esm/vendor/fetch-event-source/parse.spec.js +335 -0
- package/package.json +26 -12
- package/src/InferenceClient.ts +4 -4
- package/src/index.ts +4 -4
- package/src/lib/getDefaultTask.ts +2 -2
- package/src/lib/getInferenceProviderMapping.ts +5 -5
- package/src/lib/getProviderHelper.ts +19 -19
- package/src/lib/makeRequestOptions.ts +8 -8
- package/src/package.ts +3 -0
- package/src/providers/black-forest-labs.ts +5 -5
- package/src/providers/cerebras.ts +1 -1
- package/src/providers/cohere.ts +1 -1
- package/src/providers/consts.ts +3 -3
- package/src/providers/fal-ai.ts +9 -9
- package/src/providers/featherless-ai.ts +3 -3
- package/src/providers/fireworks-ai.ts +1 -1
- package/src/providers/groq.ts +1 -1
- package/src/providers/hf-inference.ts +11 -11
- package/src/providers/hyperbolic.ts +4 -4
- package/src/providers/nebius.ts +4 -4
- package/src/providers/novita.ts +5 -5
- package/src/providers/nscale.ts +4 -4
- package/src/providers/openai.ts +1 -1
- package/src/providers/ovhcloud.ts +4 -4
- package/src/providers/providerHelper.ts +7 -7
- package/src/providers/replicate.ts +5 -5
- package/src/providers/sambanova.ts +4 -4
- package/src/providers/together.ts +4 -4
- package/src/snippets/getInferenceSnippets.ts +7 -7
- package/src/tasks/audio/audioClassification.ts +6 -6
- package/src/tasks/audio/audioToAudio.ts +6 -6
- package/src/tasks/audio/automaticSpeechRecognition.ts +6 -6
- package/src/tasks/audio/textToSpeech.ts +4 -4
- package/src/tasks/audio/utils.ts +2 -2
- package/src/tasks/custom/request.ts +4 -4
- package/src/tasks/custom/streamingRequest.ts +4 -4
- package/src/tasks/cv/imageClassification.ts +5 -5
- package/src/tasks/cv/imageSegmentation.ts +5 -5
- package/src/tasks/cv/imageToImage.ts +4 -4
- package/src/tasks/cv/imageToText.ts +6 -6
- package/src/tasks/cv/objectDetection.ts +5 -5
- package/src/tasks/cv/textToImage.ts +5 -5
- package/src/tasks/cv/textToVideo.ts +8 -8
- package/src/tasks/cv/utils.ts +2 -2
- package/src/tasks/cv/zeroShotImageClassification.ts +5 -5
- package/src/tasks/index.ts +32 -32
- package/src/tasks/multimodal/documentQuestionAnswering.ts +5 -5
- package/src/tasks/multimodal/visualQuestionAnswering.ts +5 -5
- package/src/tasks/nlp/chatCompletion.ts +4 -4
- package/src/tasks/nlp/chatCompletionStream.ts +4 -4
- package/src/tasks/nlp/featureExtraction.ts +4 -4
- package/src/tasks/nlp/fillMask.ts +4 -4
- package/src/tasks/nlp/questionAnswering.ts +4 -4
- package/src/tasks/nlp/sentenceSimilarity.ts +4 -4
- package/src/tasks/nlp/summarization.ts +4 -4
- package/src/tasks/nlp/tableQuestionAnswering.ts +4 -4
- package/src/tasks/nlp/textClassification.ts +4 -4
- package/src/tasks/nlp/textGeneration.ts +5 -5
- package/src/tasks/nlp/textGenerationStream.ts +4 -4
- package/src/tasks/nlp/tokenClassification.ts +4 -4
- package/src/tasks/nlp/translation.ts +4 -4
- package/src/tasks/nlp/zeroShotClassification.ts +4 -4
- package/src/tasks/tabular/tabularClassification.ts +4 -4
- package/src/tasks/tabular/tabularRegression.ts +4 -4
- package/src/types.ts +1 -1
- package/src/utils/isFrontend.ts +1 -1
- package/src/utils/omit.ts +2 -2
- package/src/utils/request.ts +5 -5
- package/src/vendor/fetch-event-source/parse.spec.ts +1 -1
- package/src/vendor/fetch-event-source/parse.ts +6 -5
- package/dist/index.cjs +0 -2868
- package/dist/index.js +0 -2812
- package/dist/src/InferenceClient.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/providers/consts.d.ts.map +0 -1
- package/dist/src/providers/fireworks-ai.d.ts.map +0 -1
- package/dist/src/tasks/audio/audioToAudio.d.ts.map +0 -1
- package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +0 -1
- package/dist/src/tasks/audio/textToSpeech.d.ts.map +0 -1
- package/dist/src/tasks/audio/utils.d.ts.map +0 -1
- package/dist/src/tasks/custom/request.d.ts.map +0 -1
- package/dist/src/tasks/custom/streamingRequest.d.ts.map +0 -1
- package/dist/src/tasks/cv/imageClassification.d.ts.map +0 -1
- package/dist/src/tasks/cv/imageSegmentation.d.ts.map +0 -1
- package/dist/src/tasks/cv/imageToImage.d.ts.map +0 -1
- package/dist/src/tasks/cv/imageToText.d.ts.map +0 -1
- package/dist/src/tasks/cv/objectDetection.d.ts.map +0 -1
- package/dist/src/tasks/cv/textToImage.d.ts.map +0 -1
- package/dist/src/tasks/cv/textToVideo.d.ts.map +0 -1
- package/dist/src/tasks/cv/utils.d.ts.map +0 -1
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts.map +0 -1
- package/dist/src/tasks/index.d.ts +0 -33
- package/dist/src/tasks/index.d.ts.map +0 -1
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts.map +0 -1
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +0 -1
- package/dist/src/tasks/nlp/featureExtraction.d.ts.map +0 -1
- package/dist/src/tasks/nlp/fillMask.d.ts.map +0 -1
- package/dist/src/tasks/nlp/questionAnswering.d.ts.map +0 -1
- package/dist/src/tasks/nlp/sentenceSimilarity.d.ts.map +0 -1
- package/dist/src/tasks/nlp/summarization.d.ts.map +0 -1
- package/dist/src/tasks/nlp/textClassification.d.ts.map +0 -1
- package/dist/src/tasks/nlp/textGeneration.d.ts.map +0 -1
- package/dist/src/tasks/nlp/textGenerationStream.d.ts.map +0 -1
- package/dist/src/tasks/nlp/translation.d.ts.map +0 -1
- package/dist/src/tasks/tabular/tabularClassification.d.ts.map +0 -1
- package/dist/src/tasks/tabular/tabularRegression.d.ts.map +0 -1
- package/dist/src/vendor/fetch-event-source/parse.d.ts.map +0 -1
- package/dist/test/InferenceClient.spec.d.ts +0 -2
- package/dist/test/InferenceClient.spec.d.ts.map +0 -1
- package/dist/test/expect-closeto.d.ts +0 -2
- package/dist/test/expect-closeto.d.ts.map +0 -1
- package/dist/test/test-files.d.ts +0 -2
- package/dist/test/test-files.d.ts.map +0 -1
- /package/dist/{src → commonjs}/config.d.ts +0 -0
- /package/dist/{src → commonjs}/config.d.ts.map +0 -0
- /package/dist/{src → commonjs}/lib/InferenceOutputError.d.ts +0 -0
- /package/dist/{src → commonjs}/lib/InferenceOutputError.d.ts.map +0 -0
- /package/dist/{src → commonjs}/lib/getDefaultTask.d.ts +0 -0
- /package/dist/{src → commonjs}/lib/getDefaultTask.d.ts.map +0 -0
- /package/dist/{src → commonjs}/lib/isUrl.d.ts +0 -0
- /package/dist/{src → commonjs}/lib/isUrl.d.ts.map +0 -0
- /package/dist/{src → commonjs}/snippets/index.d.ts +0 -0
- /package/dist/{src → commonjs}/snippets/index.d.ts.map +0 -0
- /package/dist/{src → commonjs}/snippets/templates.exported.d.ts +0 -0
- /package/dist/{src → commonjs}/snippets/templates.exported.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/base64FromBytes.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/base64FromBytes.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/delay.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/delay.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/distributive-omit.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/distributive-omit.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/isBackend.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/isBackend.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/isFrontend.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/isFrontend.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/omit.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/omit.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/pick.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/pick.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/toArray.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/toArray.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/typedEntries.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/typedEntries.d.ts.map +0 -0
- /package/dist/{src → commonjs}/utils/typedInclude.d.ts +0 -0
- /package/dist/{src → commonjs}/utils/typedInclude.d.ts.map +0 -0
- /package/dist/{src → commonjs}/vendor/fetch-event-source/parse.d.ts +0 -0
- /package/dist/{src → commonjs}/vendor/fetch-event-source/parse.spec.d.ts +0 -0
- /package/dist/{src → commonjs}/vendor/fetch-event-source/parse.spec.d.ts.map +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeRequestOptions = makeRequestOptions;
|
|
4
|
+
exports.makeRequestOptionsFromResolvedModel = makeRequestOptionsFromResolvedModel;
|
|
5
|
+
const config_js_1 = require("../config.js");
|
|
6
|
+
const package_js_1 = require("../package.js");
|
|
7
|
+
const getInferenceProviderMapping_js_1 = require("./getInferenceProviderMapping.js");
|
|
8
|
+
const isUrl_js_1 = require("./isUrl.js");
|
|
9
|
+
/**
|
|
10
|
+
* Lazy-loaded from huggingface.co/api/tasks when needed
|
|
11
|
+
* Used to determine the default model to use when it's not user defined
|
|
12
|
+
*/
|
|
13
|
+
let tasks = null;
|
|
14
|
+
/**
|
|
15
|
+
* Helper that prepares request arguments.
|
|
16
|
+
* This async version handle the model ID resolution step.
|
|
17
|
+
*/
|
|
18
|
+
async function makeRequestOptions(args, providerHelper, options) {
|
|
19
|
+
const { model: maybeModel } = args;
|
|
20
|
+
const provider = providerHelper.provider;
|
|
21
|
+
const { task } = options ?? {};
|
|
22
|
+
// Validate inputs
|
|
23
|
+
if (args.endpointUrl && provider !== "hf-inference") {
|
|
24
|
+
throw new Error(`Cannot use endpointUrl with a third-party provider.`);
|
|
25
|
+
}
|
|
26
|
+
if (maybeModel && (0, isUrl_js_1.isUrl)(maybeModel)) {
|
|
27
|
+
throw new Error(`Model URLs are no longer supported. Use endpointUrl instead.`);
|
|
28
|
+
}
|
|
29
|
+
if (args.endpointUrl) {
|
|
30
|
+
// No need to have maybeModel, or to load default model for a task
|
|
31
|
+
return makeRequestOptionsFromResolvedModel(maybeModel ?? args.endpointUrl, providerHelper, args, undefined, options);
|
|
32
|
+
}
|
|
33
|
+
if (!maybeModel && !task) {
|
|
34
|
+
throw new Error("No model provided, and no task has been specified.");
|
|
35
|
+
}
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
37
|
+
const hfModel = maybeModel ?? (await loadDefaultModel(task));
|
|
38
|
+
if (providerHelper.clientSideRoutingOnly && !maybeModel) {
|
|
39
|
+
throw new Error(`Provider ${provider} requires a model ID to be passed directly.`);
|
|
40
|
+
}
|
|
41
|
+
const inferenceProviderMapping = providerHelper.clientSideRoutingOnly
|
|
42
|
+
? {
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
+
providerId: removeProviderPrefix(maybeModel, provider),
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
46
|
+
hfModelId: maybeModel,
|
|
47
|
+
status: "live",
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
+
task: task,
|
|
50
|
+
}
|
|
51
|
+
: await (0, getInferenceProviderMapping_js_1.getInferenceProviderMapping)({
|
|
52
|
+
modelId: hfModel,
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
|
+
task: task,
|
|
55
|
+
provider,
|
|
56
|
+
accessToken: args.accessToken,
|
|
57
|
+
}, { fetch: options?.fetch });
|
|
58
|
+
if (!inferenceProviderMapping) {
|
|
59
|
+
throw new Error(`We have not been able to find inference provider information for model ${hfModel}.`);
|
|
60
|
+
}
|
|
61
|
+
// Use the sync version with the resolved model
|
|
62
|
+
return makeRequestOptionsFromResolvedModel(inferenceProviderMapping.providerId, providerHelper, args, inferenceProviderMapping, options);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Helper that prepares request arguments. - for internal use only
|
|
66
|
+
* This sync version skips the model ID resolution step
|
|
67
|
+
*/
|
|
68
|
+
function makeRequestOptionsFromResolvedModel(resolvedModel, providerHelper, args, mapping, options) {
|
|
69
|
+
const { accessToken, endpointUrl, provider: maybeProvider, model, ...remainingArgs } = args;
|
|
70
|
+
void model;
|
|
71
|
+
void maybeProvider;
|
|
72
|
+
const provider = providerHelper.provider;
|
|
73
|
+
const { includeCredentials, task, signal, billTo } = options ?? {};
|
|
74
|
+
const authMethod = (() => {
|
|
75
|
+
if (providerHelper.clientSideRoutingOnly) {
|
|
76
|
+
// Closed-source providers require an accessToken (cannot be routed).
|
|
77
|
+
if (accessToken && accessToken.startsWith("hf_")) {
|
|
78
|
+
throw new Error(`Provider ${provider} is closed-source and does not support HF tokens.`);
|
|
79
|
+
}
|
|
80
|
+
return "provider-key";
|
|
81
|
+
}
|
|
82
|
+
if (accessToken) {
|
|
83
|
+
return accessToken.startsWith("hf_") ? "hf-token" : "provider-key";
|
|
84
|
+
}
|
|
85
|
+
if (includeCredentials === "include") {
|
|
86
|
+
// If accessToken is passed, it should take precedence over includeCredentials
|
|
87
|
+
return "credentials-include";
|
|
88
|
+
}
|
|
89
|
+
return "none";
|
|
90
|
+
})();
|
|
91
|
+
// Make URL
|
|
92
|
+
const modelId = endpointUrl ?? resolvedModel;
|
|
93
|
+
const url = providerHelper.makeUrl({
|
|
94
|
+
authMethod,
|
|
95
|
+
model: modelId,
|
|
96
|
+
task,
|
|
97
|
+
});
|
|
98
|
+
// Make headers
|
|
99
|
+
const headers = providerHelper.prepareHeaders({
|
|
100
|
+
accessToken,
|
|
101
|
+
authMethod,
|
|
102
|
+
}, "data" in args && !!args.data);
|
|
103
|
+
if (billTo) {
|
|
104
|
+
headers[config_js_1.HF_HEADER_X_BILL_TO] = billTo;
|
|
105
|
+
}
|
|
106
|
+
// Add user-agent to headers
|
|
107
|
+
// e.g. @huggingface/inference/3.1.3
|
|
108
|
+
const ownUserAgent = `${package_js_1.PACKAGE_NAME}/${package_js_1.PACKAGE_VERSION}`;
|
|
109
|
+
const userAgent = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : undefined]
|
|
110
|
+
.filter((x) => x !== undefined)
|
|
111
|
+
.join(" ");
|
|
112
|
+
headers["User-Agent"] = userAgent;
|
|
113
|
+
// Make body
|
|
114
|
+
const body = providerHelper.makeBody({
|
|
115
|
+
args: remainingArgs,
|
|
116
|
+
model: resolvedModel,
|
|
117
|
+
task,
|
|
118
|
+
mapping,
|
|
119
|
+
});
|
|
120
|
+
/**
|
|
121
|
+
* For edge runtimes, leave 'credentials' undefined, otherwise cloudflare workers will error
|
|
122
|
+
*/
|
|
123
|
+
let credentials;
|
|
124
|
+
if (typeof includeCredentials === "string") {
|
|
125
|
+
credentials = includeCredentials;
|
|
126
|
+
}
|
|
127
|
+
else if (includeCredentials === true) {
|
|
128
|
+
credentials = "include";
|
|
129
|
+
}
|
|
130
|
+
const info = {
|
|
131
|
+
headers,
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: body,
|
|
134
|
+
...(credentials ? { credentials } : undefined),
|
|
135
|
+
signal,
|
|
136
|
+
};
|
|
137
|
+
return { url, info };
|
|
138
|
+
}
|
|
139
|
+
async function loadDefaultModel(task) {
|
|
140
|
+
if (!tasks) {
|
|
141
|
+
tasks = await loadTaskInfo();
|
|
142
|
+
}
|
|
143
|
+
const taskInfo = tasks[task];
|
|
144
|
+
if ((taskInfo?.models.length ?? 0) <= 0) {
|
|
145
|
+
throw new Error(`No default model defined for task ${task}, please define the model explicitly.`);
|
|
146
|
+
}
|
|
147
|
+
return taskInfo.models[0].id;
|
|
148
|
+
}
|
|
149
|
+
async function loadTaskInfo() {
|
|
150
|
+
const res = await fetch(`${config_js_1.HF_HUB_URL}/api/tasks`);
|
|
151
|
+
if (!res.ok) {
|
|
152
|
+
throw new Error("Failed to load tasks definitions from Hugging Face Hub.");
|
|
153
|
+
}
|
|
154
|
+
return await res.json();
|
|
155
|
+
}
|
|
156
|
+
function removeProviderPrefix(model, provider) {
|
|
157
|
+
if (!model.startsWith(`${provider}/`)) {
|
|
158
|
+
throw new Error(`Models from ${provider} must be prefixed by "${provider}/". Got "${model}".`);
|
|
159
|
+
}
|
|
160
|
+
return model.slice(provider.length + 1);
|
|
161
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../src/package.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,YAAY,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
|
|
4
|
+
// Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
|
|
5
|
+
exports.PACKAGE_VERSION = "3.14.0";
|
|
6
|
+
exports.PACKAGE_NAME = "@huggingface/inference";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BodyParams, HeaderParams, UrlParams } from "../types";
|
|
2
|
-
import { TaskProviderHelper, type TextToImageTaskHelper } from "./providerHelper";
|
|
1
|
+
import type { BodyParams, HeaderParams, UrlParams } from "../types.js";
|
|
2
|
+
import { TaskProviderHelper, type TextToImageTaskHelper } from "./providerHelper.js";
|
|
3
3
|
interface BlackForestLabsResponse {
|
|
4
4
|
id: string;
|
|
5
5
|
polling_url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGrF,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,qBAAqB;;IAKtG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQlD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWtF,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAO9B,WAAW,CAChB,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAgCzB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlackForestLabsTextToImageTask = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* See the registered mapping of HF model ID => Black Forest Labs model ID here:
|
|
6
|
+
*
|
|
7
|
+
* https://huggingface.co/api/partners/blackforestlabs/models
|
|
8
|
+
*
|
|
9
|
+
* This is a publicly available mapping.
|
|
10
|
+
*
|
|
11
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
12
|
+
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
13
|
+
*
|
|
14
|
+
* - If you work at Black Forest Labs and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
15
|
+
* - If you're a community member and want to add a new supported HF model to Black Forest Labs, please open an issue on the present repo
|
|
16
|
+
* and we will tag Black Forest Labs team members.
|
|
17
|
+
*
|
|
18
|
+
* Thanks!
|
|
19
|
+
*/
|
|
20
|
+
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
21
|
+
const delay_js_1 = require("../utils/delay.js");
|
|
22
|
+
const omit_js_1 = require("../utils/omit.js");
|
|
23
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
24
|
+
const BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai";
|
|
25
|
+
class BlackForestLabsTextToImageTask extends providerHelper_js_1.TaskProviderHelper {
|
|
26
|
+
constructor() {
|
|
27
|
+
super("black-forest-labs", BLACK_FOREST_LABS_AI_API_BASE_URL);
|
|
28
|
+
}
|
|
29
|
+
preparePayload(params) {
|
|
30
|
+
return {
|
|
31
|
+
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
32
|
+
...params.args.parameters,
|
|
33
|
+
prompt: params.args.inputs,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
prepareHeaders(params, binary) {
|
|
37
|
+
const headers = {
|
|
38
|
+
Authorization: params.authMethod !== "provider-key" ? `Bearer ${params.accessToken}` : `X-Key ${params.accessToken}`,
|
|
39
|
+
};
|
|
40
|
+
if (!binary) {
|
|
41
|
+
headers["Content-Type"] = "application/json";
|
|
42
|
+
}
|
|
43
|
+
return headers;
|
|
44
|
+
}
|
|
45
|
+
makeRoute(params) {
|
|
46
|
+
if (!params) {
|
|
47
|
+
throw new Error("Params are required");
|
|
48
|
+
}
|
|
49
|
+
return `/v1/${params.model}`;
|
|
50
|
+
}
|
|
51
|
+
async getResponse(response, url, headers, outputType) {
|
|
52
|
+
const urlObj = new URL(response.polling_url);
|
|
53
|
+
for (let step = 0; step < 5; step++) {
|
|
54
|
+
await (0, delay_js_1.delay)(1000);
|
|
55
|
+
console.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
|
|
56
|
+
urlObj.searchParams.set("attempt", step.toString(10));
|
|
57
|
+
const resp = await fetch(urlObj, { headers: { "Content-Type": "application/json" } });
|
|
58
|
+
if (!resp.ok) {
|
|
59
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Failed to fetch result from black forest labs API");
|
|
60
|
+
}
|
|
61
|
+
const payload = await resp.json();
|
|
62
|
+
if (typeof payload === "object" &&
|
|
63
|
+
payload &&
|
|
64
|
+
"status" in payload &&
|
|
65
|
+
typeof payload.status === "string" &&
|
|
66
|
+
payload.status === "Ready" &&
|
|
67
|
+
"result" in payload &&
|
|
68
|
+
typeof payload.result === "object" &&
|
|
69
|
+
payload.result &&
|
|
70
|
+
"sample" in payload.result &&
|
|
71
|
+
typeof payload.result.sample === "string") {
|
|
72
|
+
if (outputType === "url") {
|
|
73
|
+
return payload.result.sample;
|
|
74
|
+
}
|
|
75
|
+
const image = await fetch(payload.result.sample);
|
|
76
|
+
return await image.blob();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Failed to fetch result from black forest labs API");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.BlackForestLabsTextToImageTask = BlackForestLabsTextToImageTask;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cerebras.d.ts","sourceRoot":"","sources":["../../../src/providers/cerebras.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cerebras.d.ts","sourceRoot":"","sources":["../../../src/providers/cerebras.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,qBAAa,0BAA2B,SAAQ,sBAAsB;;CAIrE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* See the registered mapping of HF model ID => Cerebras model ID here:
|
|
4
|
+
*
|
|
5
|
+
* https://huggingface.co/api/partners/cerebras/models
|
|
6
|
+
*
|
|
7
|
+
* This is a publicly available mapping.
|
|
8
|
+
*
|
|
9
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
10
|
+
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
11
|
+
*
|
|
12
|
+
* - If you work at Cerebras and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
13
|
+
* - If you're a community member and want to add a new supported HF model to Cerebras, please open an issue on the present repo
|
|
14
|
+
* and we will tag Cerebras team members.
|
|
15
|
+
*
|
|
16
|
+
* Thanks!
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.CerebrasConversationalTask = void 0;
|
|
20
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
21
|
+
class CerebrasConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("cerebras", "https://api.cerebras.ai");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.CerebrasConversationalTask = CerebrasConversationalTask;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
-
import { BaseConversationalTask } from "./providerHelper";
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper.js";
|
|
18
18
|
export declare class CohereConversationalTask extends BaseConversationalTask {
|
|
19
19
|
constructor();
|
|
20
20
|
makeRoute(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cohere.d.ts","sourceRoot":"","sources":["../../../src/providers/cohere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cohere.d.ts","sourceRoot":"","sources":["../../../src/providers/cohere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,qBAAa,wBAAyB,SAAQ,sBAAsB;;IAI1D,SAAS,IAAI,MAAM;CAG5B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CohereConversationalTask = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* See the registered mapping of HF model ID => Cohere model ID here:
|
|
6
|
+
*
|
|
7
|
+
* https://huggingface.co/api/partners/cohere/models
|
|
8
|
+
*
|
|
9
|
+
* This is a publicly available mapping.
|
|
10
|
+
*
|
|
11
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
12
|
+
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
13
|
+
*
|
|
14
|
+
* - If you work at Cohere and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
15
|
+
* - If you're a community member and want to add a new supported HF model to Cohere, please open an issue on the present repo
|
|
16
|
+
* and we will tag Cohere team members.
|
|
17
|
+
*
|
|
18
|
+
* Thanks!
|
|
19
|
+
*/
|
|
20
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
21
|
+
class CohereConversationalTask extends providerHelper_js_1.BaseConversationalTask {
|
|
22
|
+
constructor() {
|
|
23
|
+
super("cohere", "https://api.cohere.com");
|
|
24
|
+
}
|
|
25
|
+
makeRoute() {
|
|
26
|
+
return "/compatibility/v1/chat/completions";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CohereConversationalTask = CohereConversationalTask;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { InferenceProviderModelMapping } from "../lib/getInferenceProviderMapping";
|
|
2
|
-
import type { InferenceProvider } from "../types";
|
|
3
|
-
import { type ModelId } from "../types";
|
|
1
|
+
import type { InferenceProviderModelMapping } from "../lib/getInferenceProviderMapping.js";
|
|
2
|
+
import type { InferenceProvider } from "../types.js";
|
|
3
|
+
import { type ModelId } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* If you want to try to run inference for a new model locally before it's registered on huggingface.co
|
|
6
6
|
* for a given Inference Provider,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CACrD,iBAAiB,EACjB,MAAM,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAyB9C,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HARDCODED_MODEL_INFERENCE_MAPPING = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co
|
|
6
|
+
* for a given Inference Provider,
|
|
7
|
+
* you can add it to the following dictionary, for dev purposes.
|
|
8
|
+
*
|
|
9
|
+
* We also inject into this dictionary from tests.
|
|
10
|
+
*/
|
|
11
|
+
exports.HARDCODED_MODEL_INFERENCE_MAPPING = {
|
|
12
|
+
/**
|
|
13
|
+
* "HF model ID" => "Model ID on Inference Provider's side"
|
|
14
|
+
*
|
|
15
|
+
* Example:
|
|
16
|
+
* "Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
|
|
17
|
+
*/
|
|
18
|
+
"black-forest-labs": {},
|
|
19
|
+
cerebras: {},
|
|
20
|
+
cohere: {},
|
|
21
|
+
"fal-ai": {},
|
|
22
|
+
"featherless-ai": {},
|
|
23
|
+
"fireworks-ai": {},
|
|
24
|
+
groq: {},
|
|
25
|
+
"hf-inference": {},
|
|
26
|
+
hyperbolic: {},
|
|
27
|
+
nebius: {},
|
|
28
|
+
novita: {},
|
|
29
|
+
nscale: {},
|
|
30
|
+
openai: {},
|
|
31
|
+
ovhcloud: {},
|
|
32
|
+
replicate: {},
|
|
33
|
+
sambanova: {},
|
|
34
|
+
together: {},
|
|
35
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
2
|
-
import type { BodyParams, HeaderParams, RequestArgs, UrlParams } from "../types";
|
|
3
|
-
import { type AutomaticSpeechRecognitionTaskHelper, TaskProviderHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper";
|
|
4
|
-
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition";
|
|
2
|
+
import type { BodyParams, HeaderParams, RequestArgs, UrlParams } from "../types.js";
|
|
3
|
+
import { type AutomaticSpeechRecognitionTaskHelper, TaskProviderHelper, type TextToImageTaskHelper, type TextToVideoTaskHelper } from "./providerHelper.js";
|
|
4
|
+
import type { AutomaticSpeechRecognitionArgs } from "../tasks/audio/automaticSpeechRecognition.js";
|
|
5
5
|
export interface FalAiQueueOutput {
|
|
6
6
|
request_id: string;
|
|
7
7
|
status: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fal-ai.d.ts","sourceRoot":"","sources":["../../../src/providers/fal-ai.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAG3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAW,WAAW,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"fal-ai.d.ts","sourceRoot":"","sources":["../../../src/providers/fal-ai.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AAG3E,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAW,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG7F,OAAO,EACN,KAAK,oCAAoC,EACzC,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,8CAA8C,CAAC;AAEnG,MAAM,WAAW,gBAAgB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,sBAAsB;IAC/B,MAAM,EAAE,KAAK,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC,CAAC;CACH;AAYD,eAAO,MAAM,2BAA2B,UAA0D,CAAC;AAEnG,uBAAe,SAAU,SAAQ,kBAAkB;gBACtC,GAAG,CAAC,EAAE,MAAM;IAIxB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAG3D,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAG3B,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAUtF;AAMD,qBAAa,oBAAqB,SAAQ,SAAU,YAAW,qBAAqB;IAC1E,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAuBrD,WAAW,CAAC,QAAQ,EAAE,sBAAsB,EAAE,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkBjH;AAED,qBAAa,oBAAqB,SAAQ,SAAU,YAAW,qBAAqB;;IAI1E,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAMpC,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQrD,WAAW,CACzB,QAAQ,EAAE,gBAAgB,EAC1B,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,IAAI,CAAC;CA8DhB;AAED,qBAAa,mCAAoC,SAAQ,SAAU,YAAW,oCAAoC;IACxG,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAKvE,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,gCAAgC,CAAC;IAUlF,mBAAmB,CAAC,IAAI,EAAE,8BAA8B,GAAG,OAAO,CAAC,WAAW,CAAC;CAqBrF;AAED,qBAAa,qBAAsB,SAAQ,SAAS;IAC1C,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQrD,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAqB5D"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FalAITextToSpeechTask = exports.FalAIAutomaticSpeechRecognitionTask = exports.FalAITextToVideoTask = exports.FalAITextToImageTask = exports.FAL_AI_SUPPORTED_BLOB_TYPES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* See the registered mapping of HF model ID => Fal model ID here:
|
|
6
|
+
*
|
|
7
|
+
* https://huggingface.co/api/partners/fal-ai/models
|
|
8
|
+
*
|
|
9
|
+
* This is a publicly available mapping.
|
|
10
|
+
*
|
|
11
|
+
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
|
|
12
|
+
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
|
|
13
|
+
*
|
|
14
|
+
* - If you work at Fal and want to update this mapping, please use the model mapping API we provide on huggingface.co
|
|
15
|
+
* - If you're a community member and want to add a new supported HF model to Fal, please open an issue on the present repo
|
|
16
|
+
* and we will tag Fal team members.
|
|
17
|
+
*
|
|
18
|
+
* Thanks!
|
|
19
|
+
*/
|
|
20
|
+
const base64FromBytes_js_1 = require("../utils/base64FromBytes.js");
|
|
21
|
+
const InferenceOutputError_js_1 = require("../lib/InferenceOutputError.js");
|
|
22
|
+
const isUrl_js_1 = require("../lib/isUrl.js");
|
|
23
|
+
const delay_js_1 = require("../utils/delay.js");
|
|
24
|
+
const omit_js_1 = require("../utils/omit.js");
|
|
25
|
+
const providerHelper_js_1 = require("./providerHelper.js");
|
|
26
|
+
const config_js_1 = require("../config.js");
|
|
27
|
+
exports.FAL_AI_SUPPORTED_BLOB_TYPES = ["audio/mpeg", "audio/mp4", "audio/wav", "audio/x-wav"];
|
|
28
|
+
class FalAITask extends providerHelper_js_1.TaskProviderHelper {
|
|
29
|
+
constructor(url) {
|
|
30
|
+
super("fal-ai", url || "https://fal.run");
|
|
31
|
+
}
|
|
32
|
+
preparePayload(params) {
|
|
33
|
+
return params.args;
|
|
34
|
+
}
|
|
35
|
+
makeRoute(params) {
|
|
36
|
+
return `/${params.model}`;
|
|
37
|
+
}
|
|
38
|
+
prepareHeaders(params, binary) {
|
|
39
|
+
const headers = {
|
|
40
|
+
Authorization: params.authMethod !== "provider-key" ? `Bearer ${params.accessToken}` : `Key ${params.accessToken}`,
|
|
41
|
+
};
|
|
42
|
+
if (!binary) {
|
|
43
|
+
headers["Content-Type"] = "application/json";
|
|
44
|
+
}
|
|
45
|
+
return headers;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function buildLoraPath(modelId, adapterWeightsPath) {
|
|
49
|
+
return `${config_js_1.HF_HUB_URL}/${modelId}/resolve/main/${adapterWeightsPath}`;
|
|
50
|
+
}
|
|
51
|
+
class FalAITextToImageTask extends FalAITask {
|
|
52
|
+
preparePayload(params) {
|
|
53
|
+
const payload = {
|
|
54
|
+
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
55
|
+
...params.args.parameters,
|
|
56
|
+
sync_mode: true,
|
|
57
|
+
prompt: params.args.inputs,
|
|
58
|
+
};
|
|
59
|
+
if (params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath) {
|
|
60
|
+
payload.loras = [
|
|
61
|
+
{
|
|
62
|
+
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
|
|
63
|
+
scale: 1,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
if (params.mapping.providerId === "fal-ai/lora") {
|
|
67
|
+
payload.model_name = "stabilityai/stable-diffusion-xl-base-1.0";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return payload;
|
|
71
|
+
}
|
|
72
|
+
async getResponse(response, outputType) {
|
|
73
|
+
if (typeof response === "object" &&
|
|
74
|
+
"images" in response &&
|
|
75
|
+
Array.isArray(response.images) &&
|
|
76
|
+
response.images.length > 0 &&
|
|
77
|
+
"url" in response.images[0] &&
|
|
78
|
+
typeof response.images[0].url === "string") {
|
|
79
|
+
if (outputType === "url") {
|
|
80
|
+
return response.images[0].url;
|
|
81
|
+
}
|
|
82
|
+
const urlResponse = await fetch(response.images[0].url);
|
|
83
|
+
return await urlResponse.blob();
|
|
84
|
+
}
|
|
85
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Expected Fal.ai text-to-image response format");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.FalAITextToImageTask = FalAITextToImageTask;
|
|
89
|
+
class FalAITextToVideoTask extends FalAITask {
|
|
90
|
+
constructor() {
|
|
91
|
+
super("https://queue.fal.run");
|
|
92
|
+
}
|
|
93
|
+
makeRoute(params) {
|
|
94
|
+
if (params.authMethod !== "provider-key") {
|
|
95
|
+
return `/${params.model}?_subdomain=queue`;
|
|
96
|
+
}
|
|
97
|
+
return `/${params.model}`;
|
|
98
|
+
}
|
|
99
|
+
preparePayload(params) {
|
|
100
|
+
return {
|
|
101
|
+
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
102
|
+
...params.args.parameters,
|
|
103
|
+
prompt: params.args.inputs,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async getResponse(response, url, headers) {
|
|
107
|
+
if (!url || !headers) {
|
|
108
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("URL and headers are required for text-to-video task");
|
|
109
|
+
}
|
|
110
|
+
const requestId = response.request_id;
|
|
111
|
+
if (!requestId) {
|
|
112
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("No request ID found in the response");
|
|
113
|
+
}
|
|
114
|
+
let status = response.status;
|
|
115
|
+
const parsedUrl = new URL(url);
|
|
116
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""}`;
|
|
117
|
+
// extracting the provider model id for status and result urls
|
|
118
|
+
// from the response as it might be different from the mapped model in `url`
|
|
119
|
+
const modelId = new URL(response.response_url).pathname;
|
|
120
|
+
const queryParams = parsedUrl.search;
|
|
121
|
+
const statusUrl = `${baseUrl}${modelId}/status${queryParams}`;
|
|
122
|
+
const resultUrl = `${baseUrl}${modelId}${queryParams}`;
|
|
123
|
+
while (status !== "COMPLETED") {
|
|
124
|
+
await (0, delay_js_1.delay)(500);
|
|
125
|
+
const statusResponse = await fetch(statusUrl, { headers });
|
|
126
|
+
if (!statusResponse.ok) {
|
|
127
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Failed to fetch response status from fal-ai API");
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
status = (await statusResponse.json()).status;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Failed to parse status response from fal-ai API");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const resultResponse = await fetch(resultUrl, { headers });
|
|
137
|
+
let result;
|
|
138
|
+
try {
|
|
139
|
+
result = await resultResponse.json();
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Failed to parse result response from fal-ai API");
|
|
143
|
+
}
|
|
144
|
+
if (typeof result === "object" &&
|
|
145
|
+
!!result &&
|
|
146
|
+
"video" in result &&
|
|
147
|
+
typeof result.video === "object" &&
|
|
148
|
+
!!result.video &&
|
|
149
|
+
"url" in result.video &&
|
|
150
|
+
typeof result.video.url === "string" &&
|
|
151
|
+
(0, isUrl_js_1.isUrl)(result.video.url)) {
|
|
152
|
+
const urlResponse = await fetch(result.video.url);
|
|
153
|
+
return await urlResponse.blob();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
throw new InferenceOutputError_js_1.InferenceOutputError("Expected { video: { url: string } } result format, got instead: " + JSON.stringify(result));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
exports.FalAITextToVideoTask = FalAITextToVideoTask;
|
|
161
|
+
class FalAIAutomaticSpeechRecognitionTask extends FalAITask {
|
|
162
|
+
prepareHeaders(params, binary) {
|
|
163
|
+
const headers = super.prepareHeaders(params, binary);
|
|
164
|
+
headers["Content-Type"] = "application/json";
|
|
165
|
+
return headers;
|
|
166
|
+
}
|
|
167
|
+
async getResponse(response) {
|
|
168
|
+
const res = response;
|
|
169
|
+
if (typeof res?.text !== "string") {
|
|
170
|
+
throw new InferenceOutputError_js_1.InferenceOutputError(`Expected { text: string } format from Fal.ai Automatic Speech Recognition, got: ${JSON.stringify(response)}`);
|
|
171
|
+
}
|
|
172
|
+
return { text: res.text };
|
|
173
|
+
}
|
|
174
|
+
async preparePayloadAsync(args) {
|
|
175
|
+
const blob = "data" in args && args.data instanceof Blob ? args.data : "inputs" in args ? args.inputs : undefined;
|
|
176
|
+
const contentType = blob?.type;
|
|
177
|
+
if (!contentType) {
|
|
178
|
+
throw new Error(`Unable to determine the input's content-type. Make sure your are passing a Blob when using provider fal-ai.`);
|
|
179
|
+
}
|
|
180
|
+
if (!exports.FAL_AI_SUPPORTED_BLOB_TYPES.includes(contentType)) {
|
|
181
|
+
throw new Error(`Provider fal-ai does not support blob type ${contentType} - supported content types are: ${exports.FAL_AI_SUPPORTED_BLOB_TYPES.join(", ")}`);
|
|
182
|
+
}
|
|
183
|
+
const base64audio = (0, base64FromBytes_js_1.base64FromBytes)(new Uint8Array(await blob.arrayBuffer()));
|
|
184
|
+
return {
|
|
185
|
+
...("data" in args ? (0, omit_js_1.omit)(args, "data") : (0, omit_js_1.omit)(args, "inputs")),
|
|
186
|
+
audio_url: `data:${contentType};base64,${base64audio}`,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.FalAIAutomaticSpeechRecognitionTask = FalAIAutomaticSpeechRecognitionTask;
|
|
191
|
+
class FalAITextToSpeechTask extends FalAITask {
|
|
192
|
+
preparePayload(params) {
|
|
193
|
+
return {
|
|
194
|
+
...(0, omit_js_1.omit)(params.args, ["inputs", "parameters"]),
|
|
195
|
+
...params.args.parameters,
|
|
196
|
+
text: params.args.inputs,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
async getResponse(response) {
|
|
200
|
+
const res = response;
|
|
201
|
+
if (typeof res?.audio?.url !== "string") {
|
|
202
|
+
throw new InferenceOutputError_js_1.InferenceOutputError(`Expected { audio: { url: string } } format from Fal.ai Text-to-Speech, got: ${JSON.stringify(response)}`);
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const urlResponse = await fetch(res.audio.url);
|
|
206
|
+
if (!urlResponse.ok) {
|
|
207
|
+
throw new Error(`Failed to fetch audio from ${res.audio.url}: ${urlResponse.statusText}`);
|
|
208
|
+
}
|
|
209
|
+
return await urlResponse.blob();
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
throw new InferenceOutputError_js_1.InferenceOutputError(`Error fetching or processing audio from Fal.ai Text-to-Speech URL: ${res.audio.url}. ${error instanceof Error ? error.message : String(error)}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.FalAITextToSpeechTask = FalAITextToSpeechTask;
|