New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@huggingface/inference

Package Overview
Dependencies
Maintainers
4
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@huggingface/inference - npm Package Compare versions

Comparing version 3.1.6 to 3.2.0

dist/src/lib/getProviderModelId.d.ts

213

dist/index.js

@@ -46,124 +46,15 @@ var __defProp = Object.defineProperty;

var HF_HUB_URL = "https://huggingface.co";
var HF_ROUTER_URL = "https://router.huggingface.co";
// src/providers/fal-ai.ts
var FAL_AI_API_BASE_URL = "https://fal.run";
var FAL_AI_SUPPORTED_MODEL_IDS = {
"text-to-image": {
"black-forest-labs/FLUX.1-schnell": "fal-ai/flux/schnell",
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev",
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25",
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models",
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma",
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium",
"Warlord-K/Sana-1024": "fal-ai/sana",
"fal/AuraFlow-v0.2": "fal-ai/aura-flow",
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large",
"stabilityai/stable-diffusion-3.5-large-turbo": "fal-ai/stable-diffusion-v35-large/turbo",
"stabilityai/stable-diffusion-3.5-medium": "fal-ai/stable-diffusion-v35-medium",
"Kwai-Kolors/Kolors": "fal-ai/kolors"
},
"automatic-speech-recognition": {
"openai/whisper-large-v3": "fal-ai/whisper"
},
"text-to-video": {
"genmo/mochi-1-preview": "fal-ai/mochi-v1",
"tencent/HunyuanVideo": "fal-ai/hunyuan-video",
"THUDM/CogVideoX-5b": "fal-ai/cogvideox-5b",
"Lightricks/LTX-Video": "fal-ai/ltx-video"
}
};
// src/providers/replicate.ts
var REPLICATE_API_BASE_URL = "https://api.replicate.com";
var REPLICATE_SUPPORTED_MODEL_IDS = {
"text-to-image": {
"black-forest-labs/FLUX.1-dev": "black-forest-labs/flux-dev",
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/flux-schnell",
"ByteDance/Hyper-SD": "bytedance/hyper-flux-16step:382cf8959fb0f0d665b26e7e80b8d6dc3faaef1510f14ce017e8c732bb3d1eb7",
"ByteDance/SDXL-Lightning": "bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637",
"playgroundai/playground-v2.5-1024px-aesthetic": "playgroundai/playground-v2.5-1024px-aesthetic:a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24",
"stabilityai/stable-diffusion-3.5-large-turbo": "stability-ai/stable-diffusion-3.5-large-turbo",
"stabilityai/stable-diffusion-3.5-large": "stability-ai/stable-diffusion-3.5-large",
"stabilityai/stable-diffusion-3.5-medium": "stability-ai/stable-diffusion-3.5-medium",
"stabilityai/stable-diffusion-xl-base-1.0": "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc"
},
"text-to-speech": {
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:3c645149db020c85d080e2f8cfe482a0e68189a922cde964fa9e80fb179191f3",
"hexgrad/Kokoro-82M": "jaaari/kokoro-82m:dfdf537ba482b029e0a761699e6f55e9162cfd159270bfe0e44857caa5f275a6"
},
"text-to-video": {
"genmo/mochi-1-preview": "genmoai/mochi-1:1944af04d098ef69bed7f9d335d102e652203f268ec4aaa2d836f6217217e460"
}
};
// src/providers/sambanova.ts
var SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
var SAMBANOVA_SUPPORTED_MODEL_IDS = {
/** Chat completion / conversational */
conversational: {
"deepseek-ai/DeepSeek-Distill-R1-Llama-70B": "DeepSeek-Distill-R1-Llama-70B",
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
"Qwen/Qwen2.5-72B-Instruct": "Qwen2.5-72B-Instruct",
"Qwen/QwQ-32B-Preview": "QwQ-32B-Preview",
"meta-llama/Llama-3.3-70B-Instruct": "Meta-Llama-3.3-70B-Instruct",
"meta-llama/Llama-3.2-1B-Instruct": "Meta-Llama-3.2-1B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct": "Meta-Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.2-11B-Vision-Instruct": "Llama-3.2-11B-Vision-Instruct",
"meta-llama/Llama-3.2-90B-Vision-Instruct": "Llama-3.2-90B-Vision-Instruct",
"meta-llama/Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
"meta-llama/Llama-3.1-70B-Instruct": "Meta-Llama-3.1-70B-Instruct",
"meta-llama/Llama-3.1-405B-Instruct": "Meta-Llama-3.1-405B-Instruct",
"meta-llama/Llama-Guard-3-8B": "Meta-Llama-Guard-3-8B"
}
};
// src/providers/together.ts
var TOGETHER_API_BASE_URL = "https://api.together.xyz";
var TOGETHER_SUPPORTED_MODEL_IDS = {
"text-to-image": {
"black-forest-labs/FLUX.1-Canny-dev": "black-forest-labs/FLUX.1-canny",
"black-forest-labs/FLUX.1-Depth-dev": "black-forest-labs/FLUX.1-depth",
"black-forest-labs/FLUX.1-dev": "black-forest-labs/FLUX.1-dev",
"black-forest-labs/FLUX.1-Redux-dev": "black-forest-labs/FLUX.1-redux",
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/FLUX.1-pro",
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0"
},
conversational: {
"databricks/dbrx-instruct": "databricks/dbrx-instruct",
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1",
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3",
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat",
"google/gemma-2-9b-it": "google/gemma-2-9b-it",
"google/gemma-2b-it": "google/gemma-2-27b-it",
"meta-llama/Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
"meta-llama/Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
"meta-llama/Llama-3.2-11B-Vision-Instruct": "meta-llama/Llama-Vision-Free",
"meta-llama/Llama-3.2-3B-Instruct": "meta-llama/Llama-3.2-3B-Instruct-Turbo",
"meta-llama/Llama-3.2-90B-Vision-Instruct": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
"meta-llama/Llama-3.3-70B-Instruct": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
"meta-llama/Meta-Llama-3-70B-Instruct": "meta-llama/Llama-3-70b-chat-hf",
"meta-llama/Meta-Llama-3-8B-Instruct": "meta-llama/Meta-Llama-3-8B-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-405B-Instruct": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-8B-Instruct": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo-128K",
"microsoft/WizardLM-2-8x22B": "microsoft/WizardLM-2-8x22B",
"mistralai/Mistral-7B-Instruct-v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
"mistralai/Mistral-Small-24B-Instruct-2501": "mistralai/Mistral-Small-24B-Instruct-2501",
"mistralai/Mixtral-8x22B-Instruct-v0.1": "mistralai/Mixtral-8x22B-Instruct-v0.1",
"mistralai/Mixtral-8x7B-Instruct-v0.1": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
"Qwen/Qwen2-72B-Instruct": "Qwen/Qwen2-72B-Instruct",
"Qwen/Qwen2.5-72B-Instruct": "Qwen/Qwen2.5-72B-Instruct-Turbo",
"Qwen/Qwen2.5-7B-Instruct": "Qwen/Qwen2.5-7B-Instruct-Turbo",
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen/Qwen2.5-Coder-32B-Instruct",
"Qwen/QwQ-32B-Preview": "Qwen/QwQ-32B-Preview",
"scb10x/llama-3-typhoon-v1.5-8b-instruct": "scb10x/scb10x-llama3-typhoon-v1-5-8b-instruct",
"scb10x/llama-3-typhoon-v1.5x-70b-instruct-awq": "scb10x/scb10x-llama3-typhoon-v1-5x-4f316"
},
"text-generation": {
"meta-llama/Llama-2-70b-hf": "meta-llama/Llama-2-70b-hf",
"mistralai/Mixtral-8x7B-v0.1": "mistralai/Mixtral-8x7B-v0.1"
}
};

@@ -177,6 +68,58 @@ // src/lib/isUrl.ts

var name = "@huggingface/inference";
var version = "3.1.6";
var version = "3.2.0";
// src/providers/consts.ts
var HARDCODED_MODEL_ID_MAPPING = {
/**
* "HF model ID" => "Model ID on Inference Provider's side"
*/
// "Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
};
// src/lib/getProviderModelId.ts
var inferenceProviderMappingCache = /* @__PURE__ */ new Map();
async function getProviderModelId(params, args, options = {}) {
if (params.provider === "hf-inference") {
return params.model;
}
if (!options.taskHint) {
throw new Error("taskHint must be specified when using a third-party provider");
}
const task = options.taskHint === "text-generation" && options.chatCompletion ? "conversational" : options.taskHint;
if (HARDCODED_MODEL_ID_MAPPING[params.model]) {
return HARDCODED_MODEL_ID_MAPPING[params.model];
}
let inferenceProviderMapping;
if (inferenceProviderMappingCache.has(params.model)) {
inferenceProviderMapping = inferenceProviderMappingCache.get(params.model);
} else {
inferenceProviderMapping = await (options?.fetch ?? fetch)(
`${HF_HUB_URL}/api/models/${params.model}?expand[]=inferenceProviderMapping`,
{
headers: args.accessToken?.startsWith("hf_") ? { Authorization: `Bearer ${args.accessToken}` } : {}
}
).then((resp) => resp.json()).then((json) => json.inferenceProviderMapping).catch(() => null);
}
if (!inferenceProviderMapping) {
throw new Error(`We have not been able to find inference provider information for model ${params.model}.`);
}
const providerMapping = inferenceProviderMapping[params.provider];
if (providerMapping) {
if (providerMapping.task !== task) {
throw new Error(
`Model ${params.model} is not supported for task ${task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`
);
}
if (providerMapping.status === "staging") {
console.warn(
`Model ${params.model} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
);
}
return providerMapping.providerId;
}
throw new Error(`Model ${params.model} is not supported provider ${params.provider}.`);
}
// src/lib/makeRequestOptions.ts
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_HUB_URL}/api/inference-proxy/{{PROVIDER}}`;
var HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;
var tasks = null;

@@ -197,12 +140,11 @@ async function makeRequestOptions(args, options) {

}
let model;
if (!maybeModel) {
if (taskHint) {
model = mapModel({ model: await loadDefaultModel(taskHint), provider, taskHint, chatCompletion: chatCompletion2 });
} else {
throw new Error("No model provided, and no default model found for this task");
}
} else {
model = mapModel({ model: maybeModel, provider, taskHint, chatCompletion: chatCompletion2 });
if (!maybeModel && !taskHint) {
throw new Error("No model provided, and no task has been specified.");
}
const hfModel = maybeModel ?? await loadDefaultModel(taskHint);
const model = await getProviderModelId({ model: hfModel, provider }, args, {
taskHint,
chatCompletion: chatCompletion2,
fetch: options?.fetch
});
const authMethod = accessToken ? accessToken.startsWith("hf_") ? "hf-token" : "provider-key" : includeCredentials === "include" ? "credentials-include" : "none";

@@ -263,27 +205,2 @@ const url = endpointUrl ? chatCompletion2 ? endpointUrl + `/v1/chat/completions` : endpointUrl : makeUrl({

}
function mapModel(params) {
if (params.provider === "hf-inference") {
return params.model;
}
if (!params.taskHint) {
throw new Error("taskHint must be specified when using a third-party provider");
}
const task = params.taskHint === "text-generation" && params.chatCompletion ? "conversational" : params.taskHint;
const model = (() => {
switch (params.provider) {
case "fal-ai":
return FAL_AI_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "replicate":
return REPLICATE_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "sambanova":
return SAMBANOVA_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "together":
return TOGETHER_SUPPORTED_MODEL_IDS[task]?.[params.model];
}
})();
if (!model) {
throw new Error(`Model ${params.model} is not supported for task ${task} and provider ${params.provider}`);
}
return model;
}
function makeUrl(params) {

@@ -1306,3 +1223,2 @@ if (params.authMethod === "none" && params.provider !== "hf-inference") {

export {
FAL_AI_SUPPORTED_MODEL_IDS,
HfInference,

@@ -1312,5 +1228,2 @@ HfInferenceEndpoint,

InferenceOutputError,
REPLICATE_SUPPORTED_MODEL_IDS,
SAMBANOVA_SUPPORTED_MODEL_IDS,
TOGETHER_SUPPORTED_MODEL_IDS,
audioClassification,

@@ -1317,0 +1230,0 @@ audioToAudio,

export declare const HF_HUB_URL = "https://huggingface.co";
export declare const HF_ROUTER_URL = "https://router.huggingface.co";
//# sourceMappingURL=config.d.ts.map

@@ -1,10 +0,5 @@

export type { ProviderMapping } from "./providers/types";
export { HfInference, HfInferenceEndpoint } from "./HfInference";
export { InferenceOutputError } from "./lib/InferenceOutputError";
export { FAL_AI_SUPPORTED_MODEL_IDS } from "./providers/fal-ai";
export { REPLICATE_SUPPORTED_MODEL_IDS } from "./providers/replicate";
export { SAMBANOVA_SUPPORTED_MODEL_IDS } from "./providers/sambanova";
export { TOGETHER_SUPPORTED_MODEL_IDS } from "./providers/together";
export * from "./types";
export * from "./tasks";
//# sourceMappingURL=index.d.ts.map

@@ -1,6 +0,18 @@

import type { ProviderMapping } from "./types";
export declare const FAL_AI_API_BASE_URL = "https://fal.run";
type FalAiId = string;
export declare const FAL_AI_SUPPORTED_MODEL_IDS: ProviderMapping<FalAiId>;
export {};
/**
* See the registered mapping of HF model ID => Fal model ID here:
*
* https://huggingface.co/api/partners/fal-ai/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Fal and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - 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
* and we will tag Fal team members.
*
* Thanks!
*/
//# sourceMappingURL=fal-ai.d.ts.map

@@ -1,6 +0,18 @@

import type { ProviderMapping } from "./types";
export declare const REPLICATE_API_BASE_URL = "https://api.replicate.com";
type ReplicateId = string;
export declare const REPLICATE_SUPPORTED_MODEL_IDS: ProviderMapping<ReplicateId>;
export {};
/**
* See the registered mapping of HF model ID => Replicate model ID here:
*
* https://huggingface.co/api/partners/replicate/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Replicate and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Replicate, please open an issue on the present repo
* and we will tag Replicate team members.
*
* Thanks!
*/
//# sourceMappingURL=replicate.d.ts.map

@@ -1,6 +0,18 @@

import type { ProviderMapping } from "./types";
export declare const SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
type SambanovaId = string;
export declare const SAMBANOVA_SUPPORTED_MODEL_IDS: ProviderMapping<SambanovaId>;
export {};
/**
* See the registered mapping of HF model ID => Sambanova model ID here:
*
* https://huggingface.co/api/partners/sambanova/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Sambanova and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Sambanova, please open an issue on the present repo
* and we will tag Sambanova team members.
*
* Thanks!
*/
//# sourceMappingURL=sambanova.d.ts.map

@@ -1,12 +0,18 @@

import type { ProviderMapping } from "./types";
export declare const TOGETHER_API_BASE_URL = "https://api.together.xyz";
/**
* Same comment as in sambanova.ts
* See the registered mapping of HF model ID => Together model ID here:
*
* https://huggingface.co/api/partners/together/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Together and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Together, please open an issue on the present repo
* and we will tag Together team members.
*
* Thanks!
*/
type TogetherId = string;
/**
* https://docs.together.ai/reference/models-1
*/
export declare const TOGETHER_SUPPORTED_MODEL_IDS: ProviderMapping<TogetherId>;
export {};
//# sourceMappingURL=together.d.ts.map
{
"name": "@huggingface/inference",
"version": "3.1.6",
"version": "3.2.0",
"packageManager": "pnpm@8.10.5",

@@ -42,3 +42,3 @@ "license": "MIT",

"dependencies": {
"@huggingface/tasks": "^0.15.7"
"@huggingface/tasks": "^0.15.9"
},

@@ -45,0 +45,0 @@ "devDependencies": {

@@ -120,3 +120,3 @@ # 🤗 Hugging Face Inference

Using the `chatCompletion` method, you can generate text with models compatible with the OpenAI Chat Completion API. All models served by [TGI](https://api-inference.huggingface.co/framework/text-generation-inference) on Hugging Face support Messages API.
Using the `chatCompletion` method, you can generate text with models compatible with the OpenAI Chat Completion API. All models served by [TGI](https://huggingface.co/docs/text-generation-inference/) on Hugging Face support Messages API.

@@ -615,3 +615,3 @@ [Demo](https://huggingface.co/spaces/huggingfacejs/streaming-chat-completion)

const ep = hf.endpoint(
"https://api-inference.huggingface.co/models/meta-llama/Llama-3.1-8B-Instruct"
"https://router.huggingface.co/hf-inference/models/meta-llama/Llama-3.1-8B-Instruct"
);

@@ -618,0 +618,0 @@ const stream = ep.chatCompletionStream({

export const HF_HUB_URL = "https://huggingface.co";
export const HF_ROUTER_URL = "https://router.huggingface.co";

@@ -1,9 +0,4 @@

export type { ProviderMapping } from "./providers/types";
export { HfInference, HfInferenceEndpoint } from "./HfInference";
export { InferenceOutputError } from "./lib/InferenceOutputError";
export { FAL_AI_SUPPORTED_MODEL_IDS } from "./providers/fal-ai";
export { REPLICATE_SUPPORTED_MODEL_IDS } from "./providers/replicate";
export { SAMBANOVA_SUPPORTED_MODEL_IDS } from "./providers/sambanova";
export { TOGETHER_SUPPORTED_MODEL_IDS } from "./providers/together";
export * from "./types";
export * from "./tasks";

@@ -1,7 +0,6 @@

import type { WidgetType } from "@huggingface/tasks";
import { HF_HUB_URL } from "../config";
import { FAL_AI_API_BASE_URL, FAL_AI_SUPPORTED_MODEL_IDS } from "../providers/fal-ai";
import { REPLICATE_API_BASE_URL, REPLICATE_SUPPORTED_MODEL_IDS } from "../providers/replicate";
import { SAMBANOVA_API_BASE_URL, SAMBANOVA_SUPPORTED_MODEL_IDS } from "../providers/sambanova";
import { TOGETHER_API_BASE_URL, TOGETHER_SUPPORTED_MODEL_IDS } from "../providers/together";
import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
import { FAL_AI_API_BASE_URL } from "../providers/fal-ai";
import { REPLICATE_API_BASE_URL } from "../providers/replicate";
import { SAMBANOVA_API_BASE_URL } from "../providers/sambanova";
import { TOGETHER_API_BASE_URL } from "../providers/together";
import type { InferenceProvider } from "../types";

@@ -11,4 +10,5 @@ import type { InferenceTask, Options, RequestArgs } from "../types";

import { version as packageVersion, name as packageName } from "../../package.json";
import { getProviderModelId } from "./getProviderModelId";
const HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_HUB_URL}/api/inference-proxy/{{PROVIDER}}`;
const HF_HUB_INFERENCE_PROXY_TEMPLATE = `${HF_ROUTER_URL}/{{PROVIDER}}`;

@@ -53,14 +53,12 @@ /**

}
let model: string;
if (!maybeModel) {
if (taskHint) {
model = mapModel({ model: await loadDefaultModel(taskHint), provider, taskHint, chatCompletion });
} else {
throw new Error("No model provided, and no default model found for this task");
/// TODO : change error message ^
}
} else {
model = mapModel({ model: maybeModel, provider, taskHint, chatCompletion });
if (!maybeModel && !taskHint) {
throw new Error("No model provided, and no task has been specified.");
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const hfModel = maybeModel ?? (await loadDefaultModel(taskHint!));
const model = await getProviderModelId({ model: hfModel, provider }, args, {
taskHint,
chatCompletion,
fetch: options?.fetch,
});

@@ -158,35 +156,2 @@ /// If accessToken is passed, it should take precedence over includeCredentials

function mapModel(params: {
model: string;
provider: InferenceProvider;
taskHint: InferenceTask | undefined;
chatCompletion: boolean | undefined;
}): string {
if (params.provider === "hf-inference") {
return params.model;
}
if (!params.taskHint) {
throw new Error("taskHint must be specified when using a third-party provider");
}
const task: WidgetType =
params.taskHint === "text-generation" && params.chatCompletion ? "conversational" : params.taskHint;
const model = (() => {
switch (params.provider) {
case "fal-ai":
return FAL_AI_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "replicate":
return REPLICATE_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "sambanova":
return SAMBANOVA_SUPPORTED_MODEL_IDS[task]?.[params.model];
case "together":
return TOGETHER_SUPPORTED_MODEL_IDS[task]?.[params.model];
}
})();
if (!model) {
throw new Error(`Model ${params.model} is not supported for task ${task} and provider ${params.provider}`);
}
return model;
}
function makeUrl(params: {

@@ -193,0 +158,0 @@ authMethod: "none" | "hf-token" | "credentials-include" | "provider-key";

@@ -1,31 +0,18 @@

import type { ProviderMapping } from "./types";
export const FAL_AI_API_BASE_URL = "https://fal.run";
type FalAiId = string;
export const FAL_AI_SUPPORTED_MODEL_IDS: ProviderMapping<FalAiId> = {
"text-to-image": {
"black-forest-labs/FLUX.1-schnell": "fal-ai/flux/schnell",
"black-forest-labs/FLUX.1-dev": "fal-ai/flux/dev",
"playgroundai/playground-v2.5-1024px-aesthetic": "fal-ai/playground-v25",
"ByteDance/SDXL-Lightning": "fal-ai/lightning-models",
"PixArt-alpha/PixArt-Sigma-XL-2-1024-MS": "fal-ai/pixart-sigma",
"stabilityai/stable-diffusion-3-medium": "fal-ai/stable-diffusion-v3-medium",
"Warlord-K/Sana-1024": "fal-ai/sana",
"fal/AuraFlow-v0.2": "fal-ai/aura-flow",
"stabilityai/stable-diffusion-3.5-large": "fal-ai/stable-diffusion-v35-large",
"stabilityai/stable-diffusion-3.5-large-turbo": "fal-ai/stable-diffusion-v35-large/turbo",
"stabilityai/stable-diffusion-3.5-medium": "fal-ai/stable-diffusion-v35-medium",
"Kwai-Kolors/Kolors": "fal-ai/kolors",
},
"automatic-speech-recognition": {
"openai/whisper-large-v3": "fal-ai/whisper",
},
"text-to-video": {
"genmo/mochi-1-preview": "fal-ai/mochi-v1",
"tencent/HunyuanVideo": "fal-ai/hunyuan-video",
"THUDM/CogVideoX-5b": "fal-ai/cogvideox-5b",
"Lightricks/LTX-Video": "fal-ai/ltx-video",
},
};
/**
* See the registered mapping of HF model ID => Fal model ID here:
*
* https://huggingface.co/api/partners/fal-ai/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Fal and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - 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
* and we will tag Fal team members.
*
* Thanks!
*/

@@ -1,30 +0,18 @@

import type { ProviderMapping } from "./types";
export const REPLICATE_API_BASE_URL = "https://api.replicate.com";
type ReplicateId = string;
export const REPLICATE_SUPPORTED_MODEL_IDS: ProviderMapping<ReplicateId> = {
"text-to-image": {
"black-forest-labs/FLUX.1-dev": "black-forest-labs/flux-dev",
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/flux-schnell",
"ByteDance/Hyper-SD":
"bytedance/hyper-flux-16step:382cf8959fb0f0d665b26e7e80b8d6dc3faaef1510f14ce017e8c732bb3d1eb7",
"ByteDance/SDXL-Lightning":
"bytedance/sdxl-lightning-4step:5599ed30703defd1d160a25a63321b4dec97101d98b4674bcc56e41f62f35637",
"playgroundai/playground-v2.5-1024px-aesthetic":
"playgroundai/playground-v2.5-1024px-aesthetic:a45f82a1382bed5c7aeb861dac7c7d191b0fdf74d8d57c4a0e6ed7d4d0bf7d24",
"stabilityai/stable-diffusion-3.5-large-turbo": "stability-ai/stable-diffusion-3.5-large-turbo",
"stabilityai/stable-diffusion-3.5-large": "stability-ai/stable-diffusion-3.5-large",
"stabilityai/stable-diffusion-3.5-medium": "stability-ai/stable-diffusion-3.5-medium",
"stabilityai/stable-diffusion-xl-base-1.0":
"stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
},
"text-to-speech": {
"OuteAI/OuteTTS-0.3-500M": "jbilcke/oute-tts:3c645149db020c85d080e2f8cfe482a0e68189a922cde964fa9e80fb179191f3",
"hexgrad/Kokoro-82M": "jaaari/kokoro-82m:dfdf537ba482b029e0a761699e6f55e9162cfd159270bfe0e44857caa5f275a6",
},
"text-to-video": {
"genmo/mochi-1-preview": "genmoai/mochi-1:1944af04d098ef69bed7f9d335d102e652203f268ec4aaa2d836f6217217e460",
},
};
/**
* See the registered mapping of HF model ID => Replicate model ID here:
*
* https://huggingface.co/api/partners/replicate/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Replicate and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Replicate, please open an issue on the present repo
* and we will tag Replicate team members.
*
* Thanks!
*/

@@ -1,24 +0,18 @@

import type { ProviderMapping } from "./types";
export const SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
type SambanovaId = string;
export const SAMBANOVA_SUPPORTED_MODEL_IDS: ProviderMapping<SambanovaId> = {
/** Chat completion / conversational */
conversational: {
"deepseek-ai/DeepSeek-Distill-R1-Llama-70B": "DeepSeek-Distill-R1-Llama-70B",
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
"Qwen/Qwen2.5-72B-Instruct": "Qwen2.5-72B-Instruct",
"Qwen/QwQ-32B-Preview": "QwQ-32B-Preview",
"meta-llama/Llama-3.3-70B-Instruct": "Meta-Llama-3.3-70B-Instruct",
"meta-llama/Llama-3.2-1B-Instruct": "Meta-Llama-3.2-1B-Instruct",
"meta-llama/Llama-3.2-3B-Instruct": "Meta-Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.2-11B-Vision-Instruct": "Llama-3.2-11B-Vision-Instruct",
"meta-llama/Llama-3.2-90B-Vision-Instruct": "Llama-3.2-90B-Vision-Instruct",
"meta-llama/Llama-3.1-8B-Instruct": "Meta-Llama-3.1-8B-Instruct",
"meta-llama/Llama-3.1-70B-Instruct": "Meta-Llama-3.1-70B-Instruct",
"meta-llama/Llama-3.1-405B-Instruct": "Meta-Llama-3.1-405B-Instruct",
"meta-llama/Llama-Guard-3-8B": "Meta-Llama-Guard-3-8B",
},
};
/**
* See the registered mapping of HF model ID => Sambanova model ID here:
*
* https://huggingface.co/api/partners/sambanova/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Sambanova and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Sambanova, please open an issue on the present repo
* and we will tag Sambanova team members.
*
* Thanks!
*/

@@ -1,59 +0,18 @@

import type { ProviderMapping } from "./types";
export const TOGETHER_API_BASE_URL = "https://api.together.xyz";
/**
* Same comment as in sambanova.ts
* See the registered mapping of HF model ID => Together model ID here:
*
* https://huggingface.co/api/partners/together/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Together and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Together, please open an issue on the present repo
* and we will tag Together team members.
*
* Thanks!
*/
type TogetherId = string;
/**
* https://docs.together.ai/reference/models-1
*/
export const TOGETHER_SUPPORTED_MODEL_IDS: ProviderMapping<TogetherId> = {
"text-to-image": {
"black-forest-labs/FLUX.1-Canny-dev": "black-forest-labs/FLUX.1-canny",
"black-forest-labs/FLUX.1-Depth-dev": "black-forest-labs/FLUX.1-depth",
"black-forest-labs/FLUX.1-dev": "black-forest-labs/FLUX.1-dev",
"black-forest-labs/FLUX.1-Redux-dev": "black-forest-labs/FLUX.1-redux",
"black-forest-labs/FLUX.1-schnell": "black-forest-labs/FLUX.1-pro",
"stabilityai/stable-diffusion-xl-base-1.0": "stabilityai/stable-diffusion-xl-base-1.0",
},
conversational: {
"databricks/dbrx-instruct": "databricks/dbrx-instruct",
"deepseek-ai/DeepSeek-R1": "deepseek-ai/DeepSeek-R1",
"deepseek-ai/DeepSeek-V3": "deepseek-ai/DeepSeek-V3",
"deepseek-ai/deepseek-llm-67b-chat": "deepseek-ai/deepseek-llm-67b-chat",
"google/gemma-2-9b-it": "google/gemma-2-9b-it",
"google/gemma-2b-it": "google/gemma-2-27b-it",
"meta-llama/Llama-2-13b-chat-hf": "meta-llama/Llama-2-13b-chat-hf",
"meta-llama/Llama-2-7b-chat-hf": "meta-llama/Llama-2-7b-chat-hf",
"meta-llama/Llama-3.2-11B-Vision-Instruct": "meta-llama/Llama-Vision-Free",
"meta-llama/Llama-3.2-3B-Instruct": "meta-llama/Llama-3.2-3B-Instruct-Turbo",
"meta-llama/Llama-3.2-90B-Vision-Instruct": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
"meta-llama/Llama-3.3-70B-Instruct": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
"meta-llama/Meta-Llama-3-70B-Instruct": "meta-llama/Llama-3-70b-chat-hf",
"meta-llama/Meta-Llama-3-8B-Instruct": "meta-llama/Meta-Llama-3-8B-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-405B-Instruct": "meta-llama/Llama-3.2-11B-Vision-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-70B-Instruct": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
"meta-llama/Meta-Llama-3.1-8B-Instruct": "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo-128K",
"microsoft/WizardLM-2-8x22B": "microsoft/WizardLM-2-8x22B",
"mistralai/Mistral-7B-Instruct-v0.3": "mistralai/Mistral-7B-Instruct-v0.3",
"mistralai/Mistral-Small-24B-Instruct-2501": "mistralai/Mistral-Small-24B-Instruct-2501",
"mistralai/Mixtral-8x22B-Instruct-v0.1": "mistralai/Mixtral-8x22B-Instruct-v0.1",
"mistralai/Mixtral-8x7B-Instruct-v0.1": "mistralai/Mixtral-8x7B-Instruct-v0.1",
"NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
"nvidia/Llama-3.1-Nemotron-70B-Instruct-HF": "nvidia/Llama-3.1-Nemotron-70B-Instruct-HF",
"Qwen/Qwen2-72B-Instruct": "Qwen/Qwen2-72B-Instruct",
"Qwen/Qwen2.5-72B-Instruct": "Qwen/Qwen2.5-72B-Instruct-Turbo",
"Qwen/Qwen2.5-7B-Instruct": "Qwen/Qwen2.5-7B-Instruct-Turbo",
"Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen/Qwen2.5-Coder-32B-Instruct",
"Qwen/QwQ-32B-Preview": "Qwen/QwQ-32B-Preview",
"scb10x/llama-3-typhoon-v1.5-8b-instruct": "scb10x/scb10x-llama3-typhoon-v1-5-8b-instruct",
"scb10x/llama-3-typhoon-v1.5x-70b-instruct-awq": "scb10x/scb10x-llama3-typhoon-v1-5x-4f316",
},
"text-generation": {
"meta-llama/Llama-2-70b-hf": "meta-llama/Llama-2-70b-hf",
"mistralai/Mixtral-8x7B-v0.1": "mistralai/Mixtral-8x7B-v0.1",
},
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc