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
0
Versions
68
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.3.6 to 3.3.7

dist/src/providers/hf-inference.d.ts

489

dist/index.js

@@ -48,29 +48,253 @@ var __defProp = Object.defineProperty;

// src/providers/black-forest-labs.ts
var BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
var makeBody = (params) => {
return params.args;
};
var makeHeaders = (params) => {
if (params.authMethod === "provider-key") {
return { "X-Key": `${params.accessToken}` };
} else {
return { Authorization: `Bearer ${params.accessToken}` };
}
};
var makeUrl = (params) => {
return `${params.baseUrl}/${params.model}`;
};
var BLACK_FOREST_LABS_CONFIG = {
baseUrl: BLACK_FOREST_LABS_AI_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl
};
// src/providers/fal-ai.ts
var FAL_AI_API_BASE_URL = "https://fal.run";
var makeBody2 = (params) => {
return params.args;
};
var makeHeaders2 = (params) => {
return {
Authorization: params.authMethod === "provider-key" ? `Key ${params.accessToken}` : `Bearer ${params.accessToken}`
};
};
var makeUrl2 = (params) => {
return `${params.baseUrl}/${params.model}`;
};
var FAL_AI_CONFIG = {
baseUrl: FAL_AI_API_BASE_URL,
makeBody: makeBody2,
makeHeaders: makeHeaders2,
makeUrl: makeUrl2
};
// src/providers/fireworks-ai.ts
var FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
var makeBody3 = (params) => {
return {
...params.args,
...params.chatCompletion ? { model: params.model } : void 0
};
};
var makeHeaders3 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl3 = (params) => {
if (params.task === "text-generation" && params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return params.baseUrl;
};
var FIREWORKS_AI_CONFIG = {
baseUrl: FIREWORKS_AI_API_BASE_URL,
makeBody: makeBody3,
makeHeaders: makeHeaders3,
makeUrl: makeUrl3
};
// src/providers/hf-inference.ts
var makeBody4 = (params) => {
return {
...params.args,
...params.chatCompletion ? { model: params.model } : void 0
};
};
var makeHeaders4 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl4 = (params) => {
if (params.task && ["feature-extraction", "sentence-similarity"].includes(params.task)) {
return `${params.baseUrl}/pipeline/${params.task}/${params.model}`;
}
if (params.task === "text-generation" && params.chatCompletion) {
return `${params.baseUrl}/models/${params.model}/v1/chat/completions`;
}
return `${params.baseUrl}/models/${params.model}`;
};
var HF_INFERENCE_CONFIG = {
baseUrl: `${HF_ROUTER_URL}/hf-inference`,
makeBody: makeBody4,
makeHeaders: makeHeaders4,
makeUrl: makeUrl4
};
// src/providers/hyperbolic.ts
var HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
var makeBody5 = (params) => {
return {
...params.args,
...params.task === "text-to-image" ? { model_name: params.model } : { model: params.model }
};
};
var makeHeaders5 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl5 = (params) => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
return `${params.baseUrl}/v1/chat/completions`;
};
var HYPERBOLIC_CONFIG = {
baseUrl: HYPERBOLIC_API_BASE_URL,
makeBody: makeBody5,
makeHeaders: makeHeaders5,
makeUrl: makeUrl5
};
// src/providers/nebius.ts
var NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
var makeBody6 = (params) => {
return {
...params.args,
model: params.model
};
};
var makeHeaders6 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl6 = (params) => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return `${params.baseUrl}/v1/completions`;
}
return params.baseUrl;
};
var NEBIUS_CONFIG = {
baseUrl: NEBIUS_API_BASE_URL,
makeBody: makeBody6,
makeHeaders: makeHeaders6,
makeUrl: makeUrl6
};
// src/providers/novita.ts
var NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
var makeBody7 = (params) => {
return {
...params.args,
...params.chatCompletion ? { model: params.model } : void 0
};
};
var makeHeaders7 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl7 = (params) => {
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/chat/completions`;
}
return `${params.baseUrl}/completions`;
}
return params.baseUrl;
};
var NOVITA_CONFIG = {
baseUrl: NOVITA_API_BASE_URL,
makeBody: makeBody7,
makeHeaders: makeHeaders7,
makeUrl: makeUrl7
};
// src/providers/replicate.ts
var REPLICATE_API_BASE_URL = "https://api.replicate.com";
var makeBody8 = (params) => {
return {
input: params.args,
version: params.model.includes(":") ? params.model.split(":")[1] : void 0
};
};
var makeHeaders8 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl8 = (params) => {
if (params.model.includes(":")) {
return `${params.baseUrl}/v1/predictions`;
}
return `${params.baseUrl}/v1/models/${params.model}/predictions`;
};
var REPLICATE_CONFIG = {
baseUrl: REPLICATE_API_BASE_URL,
makeBody: makeBody8,
makeHeaders: makeHeaders8,
makeUrl: makeUrl8
};
// src/providers/sambanova.ts
var SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
var makeBody9 = (params) => {
return {
...params.args,
...params.chatCompletion ? { model: params.model } : void 0
};
};
var makeHeaders9 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl9 = (params) => {
if (params.task === "text-generation" && params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return params.baseUrl;
};
var SAMBANOVA_CONFIG = {
baseUrl: SAMBANOVA_API_BASE_URL,
makeBody: makeBody9,
makeHeaders: makeHeaders9,
makeUrl: makeUrl9
};
// src/providers/together.ts
var TOGETHER_API_BASE_URL = "https://api.together.xyz";
var makeBody10 = (params) => {
return {
...params.args,
model: params.model
};
};
var makeHeaders10 = (params) => {
return { Authorization: `Bearer ${params.accessToken}` };
};
var makeUrl10 = (params) => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return `${params.baseUrl}/v1/completions`;
}
return params.baseUrl;
};
var TOGETHER_CONFIG = {
baseUrl: TOGETHER_API_BASE_URL,
makeBody: makeBody10,
makeHeaders: makeHeaders10,
makeUrl: makeUrl10
};
// src/providers/novita.ts
var NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
// src/providers/fireworks-ai.ts
var FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
// src/providers/hyperbolic.ts
var HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
// src/providers/black-forest-labs.ts
var BLACKFORESTLABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
// src/lib/isUrl.ts

@@ -83,3 +307,3 @@ function isUrl(modelOrUrl) {

var name = "@huggingface/inference";
var version = "3.3.6";
var version = "3.3.7";

@@ -100,6 +324,6 @@ // src/providers/consts.ts

nebius: {},
novita: {},
replicate: {},
sambanova: {},
together: {},
novita: {}
together: {}
};

@@ -113,6 +337,6 @@

}
if (!options.taskHint) {
throw new Error("taskHint must be specified when using a third-party provider");
if (!options.task) {
throw new Error("task must be specified when using a third-party provider");
}
const task = options.taskHint === "text-generation" && options.chatCompletion ? "conversational" : options.taskHint;
const task = options.task === "text-generation" && options.chatCompletion ? "conversational" : options.task;
if (HARDCODED_MODEL_ID_MAPPING[params.provider]?.[params.model]) {

@@ -155,7 +379,19 @@ return HARDCODED_MODEL_ID_MAPPING[params.provider][params.model];

var tasks = null;
var providerConfigs = {
"black-forest-labs": BLACK_FOREST_LABS_CONFIG,
"fal-ai": FAL_AI_CONFIG,
"fireworks-ai": FIREWORKS_AI_CONFIG,
"hf-inference": HF_INFERENCE_CONFIG,
hyperbolic: HYPERBOLIC_CONFIG,
nebius: NEBIUS_CONFIG,
novita: NOVITA_CONFIG,
replicate: REPLICATE_CONFIG,
sambanova: SAMBANOVA_CONFIG,
together: TOGETHER_CONFIG
};
async function makeRequestOptions(args, options) {
const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args;
let otherArgs = remainingArgs;
const provider = maybeProvider ?? "hf-inference";
const { includeCredentials, taskHint, chatCompletion: chatCompletion2 } = options ?? {};
const providerConfig = providerConfigs[provider];
const { includeCredentials, task, chatCompletion: chatCompletion2, signal } = options ?? {};
if (endpointUrl && provider !== "hf-inference") {

@@ -167,8 +403,11 @@ throw new Error(`Cannot use endpointUrl with a third-party provider.`);

}
if (!maybeModel && !taskHint) {
if (!maybeModel && !task) {
throw new Error("No model provided, and no task has been specified.");
}
const hfModel = maybeModel ?? await loadDefaultModel(taskHint);
if (!providerConfig) {
throw new Error(`No provider config found for provider ${provider}`);
}
const hfModel = maybeModel ?? await loadDefaultModel(task);
const model = await getProviderModelId({ model: hfModel, provider }, args, {
taskHint,
task,
chatCompletion: chatCompletion2,

@@ -178,28 +417,27 @@ fetch: options?.fetch

const authMethod = accessToken ? accessToken.startsWith("hf_") ? "hf-token" : "provider-key" : includeCredentials === "include" ? "credentials-include" : "none";
const url = endpointUrl ? chatCompletion2 ? endpointUrl + `/v1/chat/completions` : endpointUrl : makeUrl({
authMethod,
chatCompletion: chatCompletion2 ?? false,
const url = endpointUrl ? chatCompletion2 ? endpointUrl + `/v1/chat/completions` : endpointUrl : providerConfig.makeUrl({
baseUrl: authMethod !== "provider-key" ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider) : providerConfig.baseUrl,
model,
provider: provider ?? "hf-inference",
taskHint
chatCompletion: chatCompletion2,
task
});
const headers = {};
if (accessToken) {
if (provider === "fal-ai" && authMethod === "provider-key") {
headers["Authorization"] = `Key ${accessToken}`;
} else if (provider === "black-forest-labs" && authMethod === "provider-key") {
headers["X-Key"] = accessToken;
} else {
headers["Authorization"] = `Bearer ${accessToken}`;
}
}
const ownUserAgent = `${name}/${version}`;
headers["User-Agent"] = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : void 0].filter((x) => x !== void 0).join(" ");
const binary = "data" in args && !!args.data;
const headers = providerConfig.makeHeaders({
accessToken,
authMethod
});
if (!binary) {
headers["Content-Type"] = "application/json";
}
if (provider === "replicate") {
headers["Prefer"] = "wait";
}
const ownUserAgent = `${name}/${version}`;
const userAgent = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : void 0].filter((x) => x !== void 0).join(" ");
headers["User-Agent"] = userAgent;
const body = binary ? args.data : JSON.stringify(
providerConfig.makeBody({
args: remainingArgs,
model,
task,
chatCompletion: chatCompletion2
})
);
let credentials;

@@ -211,108 +449,11 @@ if (typeof includeCredentials === "string") {

}
if (provider === "replicate") {
const version2 = model.includes(":") ? model.split(":")[1] : void 0;
otherArgs = { input: otherArgs, version: version2 };
}
const info = {
headers,
method: "POST",
body: binary ? args.data : JSON.stringify({
...otherArgs,
...taskHint === "text-to-image" && provider === "hyperbolic" ? { model_name: model } : chatCompletion2 || provider === "together" || provider === "nebius" || provider === "hyperbolic" ? { model } : void 0
}),
body,
...credentials ? { credentials } : void 0,
signal: options?.signal
signal
};
return { url, info };
}
function makeUrl(params) {
if (params.authMethod === "none" && params.provider !== "hf-inference") {
throw new Error("Authentication is required when requesting a third-party provider. Please provide accessToken");
}
const shouldProxy = params.provider !== "hf-inference" && params.authMethod !== "provider-key";
switch (params.provider) {
case "black-forest-labs": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : BLACKFORESTLABS_AI_API_BASE_URL;
return `${baseUrl}/${params.model}`;
}
case "fal-ai": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : FAL_AI_API_BASE_URL;
return `${baseUrl}/${params.model}`;
}
case "nebius": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : NEBIUS_API_BASE_URL;
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return `${baseUrl}/v1/completions`;
}
return baseUrl;
}
case "replicate": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : REPLICATE_API_BASE_URL;
if (params.model.includes(":")) {
return `${baseUrl}/v1/predictions`;
}
return `${baseUrl}/v1/models/${params.model}/predictions`;
}
case "sambanova": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : SAMBANOVA_API_BASE_URL;
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return baseUrl;
}
case "together": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : TOGETHER_API_BASE_URL;
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return `${baseUrl}/v1/completions`;
}
return baseUrl;
}
case "fireworks-ai": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : FIREWORKS_AI_API_BASE_URL;
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return baseUrl;
}
case "hyperbolic": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : HYPERBOLIC_API_BASE_URL;
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
return `${baseUrl}/v1/chat/completions`;
}
case "novita": {
const baseUrl = shouldProxy ? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider) : NOVITA_API_BASE_URL;
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/chat/completions`;
}
return `${baseUrl}/completions`;
}
return baseUrl;
}
default: {
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
if (params.taskHint && ["feature-extraction", "sentence-similarity"].includes(params.taskHint)) {
return `${baseUrl}/pipeline/${params.taskHint}/${params.model}`;
}
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/models/${params.model}/v1/chat/completions`;
}
return `${baseUrl}/models/${params.model}`;
}
}
}
async function loadDefaultModel(task) {

@@ -584,3 +725,3 @@ if (!tasks) {

...options,
taskHint: "audio-classification"
task: "audio-classification"
});

@@ -612,3 +753,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");

...options,
taskHint: "automatic-speech-recognition"
task: "automatic-speech-recognition"
});

@@ -657,3 +798,3 @@ const isValidOutput = typeof res?.text === "string";

...options,
taskHint: "text-to-speech"
task: "text-to-speech"
});

@@ -684,3 +825,3 @@ if (res instanceof Blob) {

...options,
taskHint: "audio-to-audio"
task: "audio-to-audio"
});

@@ -711,3 +852,3 @@ return validateOutput(res);

...options,
taskHint: "image-classification"
task: "image-classification"
});

@@ -726,3 +867,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");

...options,
taskHint: "image-segmentation"
task: "image-segmentation"
});

@@ -741,3 +882,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.mask === "string" && typeof x.score === "number");

...options,
taskHint: "image-to-text"
task: "image-to-text"
}))?.[0];

@@ -755,3 +896,3 @@ if (typeof res?.generated_text !== "string") {

...options,
taskHint: "object-detection"
task: "object-detection"
});

@@ -800,3 +941,3 @@ const isValidOutput = Array.isArray(res) && res.every(

...options,
taskHint: "text-to-image"
task: "text-to-image"
});

@@ -890,3 +1031,3 @@ if (res && typeof res === "object") {

...options,
taskHint: "image-to-image"
task: "image-to-image"
});

@@ -926,3 +1067,3 @@ const isValidOutput = res && res instanceof Blob;

...options,
taskHint: "zero-shot-image-classification"
task: "zero-shot-image-classification"
});

@@ -947,3 +1088,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x.label === "string" && typeof x.score === "number");

...options,
taskHint: "text-to-video"
task: "text-to-video"
});

@@ -971,3 +1112,3 @@ if (args.provider === "fal-ai") {

...options,
taskHint: "feature-extraction"
task: "feature-extraction"
});

@@ -995,3 +1136,3 @@ let isValidOutput = true;

...options,
taskHint: "fill-mask"
task: "fill-mask"
});

@@ -1013,3 +1154,3 @@ const isValidOutput = Array.isArray(res) && res.every(

...options,
taskHint: "question-answering"
task: "question-answering"
});

@@ -1029,3 +1170,3 @@ const isValidOutput = Array.isArray(res) ? res.every(

...options,
taskHint: "sentence-similarity"
task: "sentence-similarity"
});

@@ -1050,3 +1191,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

...options,
taskHint: "summarization"
task: "summarization"
});

@@ -1064,3 +1205,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.summary_text === "string");

...options,
taskHint: "table-question-answering"
task: "table-question-answering"
});

@@ -1085,3 +1226,3 @@ const isValidOutput = Array.isArray(res) ? res.every((elem) => validate(elem)) : validate(res);

...options,
taskHint: "text-classification"
task: "text-classification"
}))?.[0];

@@ -1109,3 +1250,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.label === "string" && typeof x.score === "number");

...options,
taskHint: "text-generation"
task: "text-generation"
});

@@ -1131,3 +1272,3 @@ const isValidOutput = typeof raw === "object" && "choices" in raw && Array.isArray(raw?.choices) && typeof raw?.model === "string";

...options,
taskHint: "text-generation"
task: "text-generation"
});

@@ -1146,3 +1287,3 @@ const isValidOutput = typeof raw === "object" && "choices" in raw && Array.isArray(raw?.choices) && typeof raw?.model === "string";

...options,
taskHint: "text-generation"
task: "text-generation"
})

@@ -1162,3 +1303,3 @@ );

...options,
taskHint: "text-generation"
task: "text-generation"
});

@@ -1172,3 +1313,3 @@ }

...options,
taskHint: "token-classification"
task: "token-classification"
})

@@ -1191,3 +1332,3 @@ );

...options,
taskHint: "translation"
task: "translation"
});

@@ -1206,3 +1347,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.translation_text === "string");

...options,
taskHint: "zero-shot-classification"
task: "zero-shot-classification"
})

@@ -1223,3 +1364,3 @@ );

...options,
taskHint: "text-generation",
task: "text-generation",
chatCompletion: true

@@ -1239,3 +1380,3 @@ });

...options,
taskHint: "text-generation",
task: "text-generation",
chatCompletion: true

@@ -1258,3 +1399,3 @@ });

...options,
taskHint: "document-question-answering"
task: "document-question-answering"
})

@@ -1283,3 +1424,3 @@ );

...options,
taskHint: "visual-question-answering"
task: "visual-question-answering"
});

@@ -1299,3 +1440,3 @@ const isValidOutput = Array.isArray(res) && res.every(

...options,
taskHint: "tabular-regression"
task: "tabular-regression"
});

@@ -1313,3 +1454,3 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

...options,
taskHint: "tabular-classification"
task: "tabular-classification"
});

@@ -1316,0 +1457,0 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

@@ -6,3 +6,3 @@ import type { InferenceProvider, InferenceTask, Options, RequestArgs } from "../types";

}, args: RequestArgs, options?: {
taskHint?: InferenceTask;
task?: InferenceTask;
chatCompletion?: boolean;

@@ -9,0 +9,0 @@ fetch?: Options["fetch"];

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

}, options?: Options & {
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
chatCompletion?: boolean;

@@ -13,0 +13,0 @@ }): Promise<{

@@ -1,2 +0,1 @@

export declare const BLACKFORESTLABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Black Forest Labs model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const BLACK_FOREST_LABS_CONFIG: ProviderConfig;
//# sourceMappingURL=black-forest-labs.d.ts.map

@@ -1,2 +0,1 @@

export declare const FAL_AI_API_BASE_URL = "https://fal.run";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Fal model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const FAL_AI_CONFIG: ProviderConfig;
//# sourceMappingURL=fal-ai.d.ts.map

@@ -1,2 +0,1 @@

export declare const FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Fireworks model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const FIREWORKS_AI_CONFIG: ProviderConfig;
//# sourceMappingURL=fireworks-ai.d.ts.map

@@ -1,2 +0,1 @@

export declare const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Hyperbolic model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const HYPERBOLIC_CONFIG: ProviderConfig;
//# sourceMappingURL=hyperbolic.d.ts.map

@@ -1,2 +0,1 @@

export declare const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Nebius model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const NEBIUS_CONFIG: ProviderConfig;
//# sourceMappingURL=nebius.d.ts.map

@@ -1,2 +0,1 @@

export declare const NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Novita model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const NOVITA_CONFIG: ProviderConfig;
//# sourceMappingURL=novita.d.ts.map

@@ -1,2 +0,1 @@

export declare const REPLICATE_API_BASE_URL = "https://api.replicate.com";
/**

@@ -18,2 +17,5 @@ * See the registered mapping of HF model ID => Replicate model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const REPLICATE_API_BASE_URL = "https://api.replicate.com";
export declare const REPLICATE_CONFIG: ProviderConfig;
//# sourceMappingURL=replicate.d.ts.map

@@ -1,2 +0,1 @@

export declare const SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Sambanova model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const SAMBANOVA_CONFIG: ProviderConfig;
//# sourceMappingURL=sambanova.d.ts.map

@@ -1,2 +0,1 @@

export declare const TOGETHER_API_BASE_URL = "https://api.together.xyz";
/**

@@ -18,2 +17,4 @@ * See the registered mapping of HF model ID => Together model ID here:

*/
import type { ProviderConfig } from "../types";
export declare const TOGETHER_CONFIG: ProviderConfig;
//# sourceMappingURL=together.d.ts.map

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

export declare function request<T>(args: RequestArgs, options?: Options & {
/** When a model can be used for multiple tasks, and we want to run a non-default task */
task?: string | InferenceTask;
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
/** Is chat completion compatible */

@@ -12,0 +10,0 @@ chatCompletion?: boolean;

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

export declare function streamingRequest<T>(args: RequestArgs, options?: Options & {
/** When a model can be used for multiple tasks, and we want to run a non-default task */
task?: string | InferenceTask;
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
/** Is chat completion compatible */

@@ -12,0 +10,0 @@ chatCompletion?: boolean;

@@ -0,11 +1,4 @@

import type { FeatureExtractionInput } from "@huggingface/tasks";
import type { BaseArgs, Options } from "../../types";
export type FeatureExtractionArgs = BaseArgs & {
/**
* The inputs is a string or a list of strings to get the features from.
*
* inputs: "That is a happy person",
*
*/
inputs: string | string[];
};
export type FeatureExtractionArgs = BaseArgs & FeatureExtractionInput;
/**

@@ -12,0 +5,0 @@ * Returned values are a multidimensional array of floats (dimension depending on if you sent a string or a list of string, and if the automatic reduction, usually mean_pooling for instance was applied for you or not. This should be explained on the model's README).

@@ -1,2 +0,2 @@

import type { ChatCompletionInput, PipelineType } from "@huggingface/tasks";
import type { ChatCompletionInput, FeatureExtractionInput, PipelineType } from "@huggingface/tasks";
/**

@@ -68,6 +68,27 @@ * HF model id, like "meta-llama/Llama-3.3-70B-Instruct"

audio_url: string;
} | ChatCompletionInput) & {
} | ChatCompletionInput | FeatureExtractionInput) & {
parameters?: Record<string, unknown>;
};
export interface ProviderConfig {
baseUrl: string;
makeBody: (params: BodyParams) => Record<string, unknown>;
makeHeaders: (params: HeaderParams) => Record<string, string>;
makeUrl: (params: UrlParams) => string;
}
export interface HeaderParams {
accessToken?: string;
};
authMethod: "none" | "hf-token" | "credentials-include" | "provider-key";
}
export interface UrlParams {
baseUrl: string;
model: string;
task?: InferenceTask;
chatCompletion?: boolean;
}
export interface BodyParams {
args: Record<string, unknown>;
chatCompletion?: boolean;
model: string;
task?: InferenceTask;
}
//# sourceMappingURL=types.d.ts.map
{
"name": "@huggingface/inference",
"version": "3.3.6",
"version": "3.3.7",
"packageManager": "pnpm@8.10.5",

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

"dependencies": {
"@huggingface/tasks": "^0.16.0"
"@huggingface/tasks": "^0.16.3"
},

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

@@ -18,3 +18,3 @@ import type { WidgetType } from "@huggingface/tasks";

options: {
taskHint?: InferenceTask;
task?: InferenceTask;
chatCompletion?: boolean;

@@ -27,7 +27,7 @@ fetch?: Options["fetch"];

}
if (!options.taskHint) {
throw new Error("taskHint must be specified when using a third-party provider");
if (!options.task) {
throw new Error("task must be specified when using a third-party provider");
}
const task: WidgetType =
options.taskHint === "text-generation" && options.chatCompletion ? "conversational" : options.taskHint;
options.task === "text-generation" && options.chatCompletion ? "conversational" : options.task;

@@ -34,0 +34,0 @@ // A dict called HARDCODED_MODEL_ID_MAPPING takes precedence in all cases (useful for dev purposes)

import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
import { FAL_AI_API_BASE_URL } from "../providers/fal-ai";
import { NEBIUS_API_BASE_URL } from "../providers/nebius";
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 { NOVITA_API_BASE_URL } from "../providers/novita";
import { FIREWORKS_AI_API_BASE_URL } from "../providers/fireworks-ai";
import { HYPERBOLIC_API_BASE_URL } from "../providers/hyperbolic";
import { BLACKFORESTLABS_AI_API_BASE_URL } from "../providers/black-forest-labs";
import type { InferenceProvider } from "../types";
import type { InferenceTask, Options, RequestArgs } from "../types";
import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
import { FAL_AI_CONFIG } from "../providers/fal-ai";
import { FIREWORKS_AI_CONFIG } from "../providers/fireworks-ai";
import { HF_INFERENCE_CONFIG } from "../providers/hf-inference";
import { HYPERBOLIC_CONFIG } from "../providers/hyperbolic";
import { NEBIUS_CONFIG } from "../providers/nebius";
import { NOVITA_CONFIG } from "../providers/novita";
import { REPLICATE_CONFIG } from "../providers/replicate";
import { SAMBANOVA_CONFIG } from "../providers/sambanova";
import { TOGETHER_CONFIG } from "../providers/together";
import type { InferenceProvider, InferenceTask, Options, ProviderConfig, RequestArgs } from "../types";
import { isUrl } from "./isUrl";

@@ -26,2 +26,18 @@ import { version as packageVersion, name as packageName } from "../../package.json";

/**
* Config to define how to serialize requests for each provider
*/
const providerConfigs: Record<InferenceProvider, ProviderConfig> = {
"black-forest-labs": BLACK_FOREST_LABS_CONFIG,
"fal-ai": FAL_AI_CONFIG,
"fireworks-ai": FIREWORKS_AI_CONFIG,
"hf-inference": HF_INFERENCE_CONFIG,
hyperbolic: HYPERBOLIC_CONFIG,
nebius: NEBIUS_CONFIG,
novita: NOVITA_CONFIG,
replicate: REPLICATE_CONFIG,
sambanova: SAMBANOVA_CONFIG,
together: TOGETHER_CONFIG,
};
/**
* Helper that prepares request arguments

@@ -35,4 +51,4 @@ */

options?: Options & {
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
chatCompletion?: boolean;

@@ -42,6 +58,6 @@ }

const { accessToken, endpointUrl, provider: maybeProvider, model: maybeModel, ...remainingArgs } = args;
let otherArgs = remainingArgs;
const provider = maybeProvider ?? "hf-inference";
const providerConfig = providerConfigs[provider];
const { includeCredentials, taskHint, chatCompletion } = options ?? {};
const { includeCredentials, task, chatCompletion, signal } = options ?? {};

@@ -54,9 +70,12 @@ if (endpointUrl && provider !== "hf-inference") {

}
if (!maybeModel && !taskHint) {
if (!maybeModel && !task) {
throw new Error("No model provided, and no task has been specified.");
}
if (!providerConfig) {
throw new Error(`No provider config found for provider ${provider}`);
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const hfModel = maybeModel ?? (await loadDefaultModel(taskHint!));
const hfModel = maybeModel ?? (await loadDefaultModel(task!));
const model = await getProviderModelId({ model: hfModel, provider }, args, {
taskHint,
task,
chatCompletion,

@@ -75,2 +94,3 @@ fetch: options?.fetch,

// Make URL
const url = endpointUrl

@@ -80,37 +100,44 @@ ? chatCompletion

: endpointUrl
: makeUrl({
authMethod,
chatCompletion: chatCompletion ?? false,
: providerConfig.makeUrl({
baseUrl:
authMethod !== "provider-key"
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider)
: providerConfig.baseUrl,
model,
provider: provider ?? "hf-inference",
taskHint,
chatCompletion,
task,
});
const headers: Record<string, string> = {};
if (accessToken) {
if (provider === "fal-ai" && authMethod === "provider-key") {
headers["Authorization"] = `Key ${accessToken}`;
} else if (provider === "black-forest-labs" && authMethod === "provider-key") {
headers["X-Key"] = accessToken;
} else {
headers["Authorization"] = `Bearer ${accessToken}`;
}
// Make headers
const binary = "data" in args && !!args.data;
const headers = providerConfig.makeHeaders({
accessToken,
authMethod,
});
// Add content-type to headers
if (!binary) {
headers["Content-Type"] = "application/json";
}
// Add user-agent to headers
// e.g. @huggingface/inference/3.1.3
const ownUserAgent = `${packageName}/${packageVersion}`;
headers["User-Agent"] = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : undefined]
const userAgent = [ownUserAgent, typeof navigator !== "undefined" ? navigator.userAgent : undefined]
.filter((x) => x !== undefined)
.join(" ");
headers["User-Agent"] = userAgent;
const binary = "data" in args && !!args.data;
// Make body
const body = binary
? args.data
: JSON.stringify(
providerConfig.makeBody({
args: remainingArgs as Record<string, unknown>,
model,
task,
chatCompletion,
})
);
if (!binary) {
headers["Content-Type"] = "application/json";
}
if (provider === "replicate") {
headers["Prefer"] = "wait";
}
/**

@@ -126,26 +153,8 @@ * For edge runtimes, leave 'credentials' undefined, otherwise cloudflare workers will error

/**
* Replicate models wrap all inputs inside { input: ... }
* Versioned Replicate models in the format `owner/model:version` expect the version in the body
*/
if (provider === "replicate") {
const version = model.includes(":") ? model.split(":")[1] : undefined;
(otherArgs as unknown) = { input: otherArgs, version };
}
const info: RequestInit = {
headers,
method: "POST",
body: binary
? args.data
: JSON.stringify({
...otherArgs,
...(taskHint === "text-to-image" && provider === "hyperbolic"
? { model_name: model }
: chatCompletion || provider === "together" || provider === "nebius" || provider === "hyperbolic"
? { model }
: undefined),
}),
body,
...(credentials ? { credentials } : undefined),
signal: options?.signal,
signal,
};

@@ -156,125 +165,2 @@

function makeUrl(params: {
authMethod: "none" | "hf-token" | "credentials-include" | "provider-key";
chatCompletion: boolean;
model: string;
provider: InferenceProvider;
taskHint: InferenceTask | undefined;
}): string {
if (params.authMethod === "none" && params.provider !== "hf-inference") {
throw new Error("Authentication is required when requesting a third-party provider. Please provide accessToken");
}
const shouldProxy = params.provider !== "hf-inference" && params.authMethod !== "provider-key";
switch (params.provider) {
case "black-forest-labs": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: BLACKFORESTLABS_AI_API_BASE_URL;
return `${baseUrl}/${params.model}`;
}
case "fal-ai": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: FAL_AI_API_BASE_URL;
return `${baseUrl}/${params.model}`;
}
case "nebius": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: NEBIUS_API_BASE_URL;
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return `${baseUrl}/v1/completions`;
}
return baseUrl;
}
case "replicate": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: REPLICATE_API_BASE_URL;
if (params.model.includes(":")) {
/// Versioned model
return `${baseUrl}/v1/predictions`;
}
/// Evergreen / Canonical model
return `${baseUrl}/v1/models/${params.model}/predictions`;
}
case "sambanova": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: SAMBANOVA_API_BASE_URL;
/// Sambanova API matches OpenAI-like APIs: model is defined in the request body
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return baseUrl;
}
case "together": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: TOGETHER_API_BASE_URL;
/// Together API matches OpenAI-like APIs: model is defined in the request body
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return `${baseUrl}/v1/completions`;
}
return baseUrl;
}
case "fireworks-ai": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: FIREWORKS_AI_API_BASE_URL;
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/v1/chat/completions`;
}
return baseUrl;
}
case "hyperbolic": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: HYPERBOLIC_API_BASE_URL;
if (params.taskHint === "text-to-image") {
return `${baseUrl}/v1/images/generations`;
}
return `${baseUrl}/v1/chat/completions`;
}
case "novita": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: NOVITA_API_BASE_URL;
if (params.taskHint === "text-generation") {
if (params.chatCompletion) {
return `${baseUrl}/chat/completions`;
}
return `${baseUrl}/completions`;
}
return baseUrl;
}
default: {
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
if (params.taskHint && ["feature-extraction", "sentence-similarity"].includes(params.taskHint)) {
/// when deployed on hf-inference, those two tasks are automatically compatible with one another.
return `${baseUrl}/pipeline/${params.taskHint}/${params.model}`;
}
if (params.taskHint === "text-generation" && params.chatCompletion) {
return `${baseUrl}/models/${params.model}/v1/chat/completions`;
}
return `${baseUrl}/models/${params.model}`;
}
}
}
async function loadDefaultModel(task: InferenceTask): Promise<string> {

@@ -281,0 +167,0 @@ if (!tasks) {

@@ -1,3 +0,1 @@

export const BLACKFORESTLABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
/**

@@ -19,1 +17,27 @@ * See the registered mapping of HF model ID => Black Forest Labs model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return params.args;
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
if (params.authMethod === "provider-key") {
return { "X-Key": `${params.accessToken}` };
} else {
return { Authorization: `Bearer ${params.accessToken}` };
}
};
const makeUrl = (params: UrlParams): string => {
return `${params.baseUrl}/${params.model}`;
};
export const BLACK_FOREST_LABS_CONFIG: ProviderConfig = {
baseUrl: BLACK_FOREST_LABS_AI_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -25,6 +25,6 @@ import type { InferenceProvider } from "../types";

nebius: {},
novita: {},
replicate: {},
sambanova: {},
together: {},
novita: {},
};

@@ -1,3 +0,1 @@

export const FAL_AI_API_BASE_URL = "https://fal.run";
/**

@@ -19,1 +17,25 @@ * See the registered mapping of HF model ID => Fal model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const FAL_AI_API_BASE_URL = "https://fal.run";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return params.args;
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return {
Authorization: params.authMethod === "provider-key" ? `Key ${params.accessToken}` : `Bearer ${params.accessToken}`,
};
};
const makeUrl = (params: UrlParams): string => {
return `${params.baseUrl}/${params.model}`;
};
export const FAL_AI_CONFIG: ProviderConfig = {
baseUrl: FAL_AI_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
/**

@@ -19,1 +17,29 @@ * See the registered mapping of HF model ID => Fireworks model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
...(params.chatCompletion ? { model: params.model } : undefined),
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-generation" && params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return params.baseUrl;
};
export const FIREWORKS_AI_CONFIG: ProviderConfig = {
baseUrl: FIREWORKS_AI_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
/**

@@ -19,1 +17,29 @@ * See the registered mapping of HF model ID => Hyperbolic model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
...(params.task === "text-to-image" ? { model_name: params.model } : { model: params.model }),
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
return `${params.baseUrl}/v1/chat/completions`;
};
export const HYPERBOLIC_CONFIG: ProviderConfig = {
baseUrl: HYPERBOLIC_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
/**

@@ -19,1 +17,35 @@ * See the registered mapping of HF model ID => Nebius model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
model: params.model,
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return `${params.baseUrl}/v1/completions`;
}
return params.baseUrl;
};
export const NEBIUS_CONFIG: ProviderConfig = {
baseUrl: NEBIUS_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
/**

@@ -19,1 +17,32 @@ * See the registered mapping of HF model ID => Novita model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const NOVITA_API_BASE_URL = "https://api.novita.ai/v3/openai";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
...(params.chatCompletion ? { model: params.model } : undefined),
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/chat/completions`;
}
return `${params.baseUrl}/completions`;
}
return params.baseUrl;
};
export const NOVITA_CONFIG: ProviderConfig = {
baseUrl: NOVITA_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const REPLICATE_API_BASE_URL = "https://api.replicate.com";
/**

@@ -19,1 +17,31 @@ * See the registered mapping of HF model ID => Replicate model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
export const REPLICATE_API_BASE_URL = "https://api.replicate.com";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
input: params.args,
version: params.model.includes(":") ? params.model.split(":")[1] : undefined,
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.model.includes(":")) {
/// Versioned model
return `${params.baseUrl}/v1/predictions`;
}
/// Evergreen / Canonical model
return `${params.baseUrl}/v1/models/${params.model}/predictions`;
};
export const REPLICATE_CONFIG: ProviderConfig = {
baseUrl: REPLICATE_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
/**

@@ -19,1 +17,29 @@ * See the registered mapping of HF model ID => Sambanova model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const SAMBANOVA_API_BASE_URL = "https://api.sambanova.ai";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
...(params.chatCompletion ? { model: params.model } : undefined),
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-generation" && params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return params.baseUrl;
};
export const SAMBANOVA_CONFIG: ProviderConfig = {
baseUrl: SAMBANOVA_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -1,3 +0,1 @@

export const TOGETHER_API_BASE_URL = "https://api.together.xyz";
/**

@@ -19,1 +17,35 @@ * See the registered mapping of HF model ID => Together model ID here:

*/
import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
const TOGETHER_API_BASE_URL = "https://api.together.xyz";
const makeBody = (params: BodyParams): Record<string, unknown> => {
return {
...params.args,
model: params.model,
};
};
const makeHeaders = (params: HeaderParams): Record<string, string> => {
return { Authorization: `Bearer ${params.accessToken}` };
};
const makeUrl = (params: UrlParams): string => {
if (params.task === "text-to-image") {
return `${params.baseUrl}/v1/images/generations`;
}
if (params.task === "text-generation") {
if (params.chatCompletion) {
return `${params.baseUrl}/v1/chat/completions`;
}
return `${params.baseUrl}/v1/completions`;
}
return params.baseUrl;
};
export const TOGETHER_CONFIG: ProviderConfig = {
baseUrl: TOGETHER_API_BASE_URL,
makeBody,
makeHeaders,
makeUrl,
};

@@ -21,3 +21,3 @@ import type { AudioClassificationInput, AudioClassificationOutput } from "@huggingface/tasks";

...options,
taskHint: "audio-classification",
task: "audio-classification",
});

@@ -24,0 +24,0 @@ const isValidOutput =

@@ -42,3 +42,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "audio-to-audio",
task: "audio-to-audio",
});

@@ -45,0 +45,0 @@

@@ -22,3 +22,3 @@ import type { AutomaticSpeechRecognitionInput, AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";

...options,
taskHint: "automatic-speech-recognition",
task: "automatic-speech-recognition",
});

@@ -25,0 +25,0 @@ const isValidOutput = typeof res?.text === "string";

@@ -27,3 +27,3 @@ import type { TextToSpeechInput } from "@huggingface/tasks";

...options,
taskHint: "text-to-speech",
task: "text-to-speech",
});

@@ -30,0 +30,0 @@ if (res instanceof Blob) {

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

options?: Options & {
/** When a model can be used for multiple tasks, and we want to run a non-default task */
task?: string | InferenceTask;
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
/** Is chat completion compatible */

@@ -16,0 +14,0 @@ chatCompletion?: boolean;

@@ -12,6 +12,4 @@ import type { InferenceTask, Options, RequestArgs } from "../../types";

options?: Options & {
/** When a model can be used for multiple tasks, and we want to run a non-default task */
task?: string | InferenceTask;
/** To load default model if needed */
taskHint?: InferenceTask;
/** In most cases (unless we pass a endpointUrl) we know the task */
task?: InferenceTask;
/** Is chat completion compatible */

@@ -18,0 +16,0 @@ chatCompletion?: boolean;

@@ -20,3 +20,3 @@ import type { ImageClassificationInput, ImageClassificationOutput } from "@huggingface/tasks";

...options,
taskHint: "image-classification",
task: "image-classification",
});

@@ -23,0 +23,0 @@ const isValidOutput =

@@ -20,3 +20,3 @@ import type { ImageSegmentationInput, ImageSegmentationOutput } from "@huggingface/tasks";

...options,
taskHint: "image-segmentation",
task: "image-segmentation",
});

@@ -23,0 +23,0 @@ const isValidOutput =

@@ -31,3 +31,3 @@ import type { ImageToImageInput } from "@huggingface/tasks";

...options,
taskHint: "image-to-image",
task: "image-to-image",
});

@@ -34,0 +34,0 @@ const isValidOutput = res && res instanceof Blob;

@@ -17,3 +17,3 @@ import type { ImageToTextInput, ImageToTextOutput } from "@huggingface/tasks";

...options,
taskHint: "image-to-text",
task: "image-to-text",
})

@@ -20,0 +20,0 @@ )?.[0];

@@ -17,3 +17,3 @@ import { request } from "../custom/request";

...options,
taskHint: "object-detection",
task: "object-detection",
});

@@ -20,0 +20,0 @@ const isValidOutput =

@@ -76,3 +76,3 @@ import type { TextToImageInput, TextToImageOutput } from "@huggingface/tasks";

...options,
taskHint: "text-to-image",
task: "text-to-image",
});

@@ -79,0 +79,0 @@

@@ -38,3 +38,3 @@ import type { BaseArgs, InferenceProvider, Options } from "../../types";

...options,
taskHint: "text-to-video",
task: "text-to-video",
});

@@ -41,0 +41,0 @@

@@ -51,3 +51,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "zero-shot-image-classification",
task: "zero-shot-image-classification",
});

@@ -54,0 +54,0 @@ const isValidOutput =

@@ -35,3 +35,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "document-question-answering",
task: "document-question-answering",
})

@@ -38,0 +38,0 @@ );

@@ -32,3 +32,3 @@ import type {

...options,
taskHint: "visual-question-answering",
task: "visual-question-answering",
});

@@ -35,0 +35,0 @@ const isValidOutput =

@@ -15,3 +15,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "text-generation",
task: "text-generation",
chatCompletion: true,

@@ -18,0 +18,0 @@ });

@@ -14,5 +14,5 @@ import type { BaseArgs, Options } from "../../types";

...options,
taskHint: "text-generation",
task: "text-generation",
chatCompletion: true,
});
}

@@ -0,1 +1,2 @@

import type { FeatureExtractionInput } from "@huggingface/tasks";
import { InferenceOutputError } from "../../lib/InferenceOutputError";

@@ -5,11 +6,3 @@ import type { BaseArgs, Options } from "../../types";

export type FeatureExtractionArgs = BaseArgs & {
/**
* The inputs is a string or a list of strings to get the features from.
*
* inputs: "That is a happy person",
*
*/
inputs: string | string[];
};
export type FeatureExtractionArgs = BaseArgs & FeatureExtractionInput;

@@ -30,3 +23,3 @@ /**

...options,
taskHint: "feature-extraction",
task: "feature-extraction",
});

@@ -33,0 +26,0 @@ let isValidOutput = true;

@@ -14,3 +14,3 @@ import type { FillMaskInput, FillMaskOutput } from "@huggingface/tasks";

...options,
taskHint: "fill-mask",
task: "fill-mask",
});

@@ -17,0 +17,0 @@ const isValidOutput =

@@ -17,3 +17,3 @@ import type { QuestionAnsweringInput, QuestionAnsweringOutput } from "@huggingface/tasks";

...options,
taskHint: "question-answering",
task: "question-answering",
});

@@ -20,0 +20,0 @@ const isValidOutput = Array.isArray(res)

@@ -18,3 +18,3 @@ import type { SentenceSimilarityInput, SentenceSimilarityOutput } from "@huggingface/tasks";

...options,
taskHint: "sentence-similarity",
task: "sentence-similarity",
});

@@ -21,0 +21,0 @@

@@ -14,3 +14,3 @@ import type { SummarizationInput, SummarizationOutput } from "@huggingface/tasks";

...options,
taskHint: "summarization",
task: "summarization",
});

@@ -17,0 +17,0 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.summary_text === "string");

@@ -17,3 +17,3 @@ import type { TableQuestionAnsweringInput, TableQuestionAnsweringOutput } from "@huggingface/tasks";

...options,
taskHint: "table-question-answering",
task: "table-question-answering",
});

@@ -20,0 +20,0 @@ const isValidOutput = Array.isArray(res) ? res.every((elem) => validate(elem)) : validate(res);

@@ -18,3 +18,3 @@ import type { TextClassificationInput, TextClassificationOutput } from "@huggingface/tasks";

...options,
taskHint: "text-classification",
task: "text-classification",
})

@@ -21,0 +21,0 @@ )?.[0];

@@ -42,3 +42,3 @@ import type {

...options,
taskHint: "text-generation",
task: "text-generation",
});

@@ -67,3 +67,3 @@ const isValidOutput =

...options,
taskHint: "text-generation",
task: "text-generation",
});

@@ -83,3 +83,3 @@ const isValidOutput =

...options,
taskHint: "text-generation",
task: "text-generation",
})

@@ -86,0 +86,0 @@ );

@@ -94,4 +94,4 @@ import type { TextGenerationInput } from "@huggingface/tasks";

...options,
taskHint: "text-generation",
task: "text-generation",
});
}

@@ -19,3 +19,3 @@ import type { TokenClassificationInput, TokenClassificationOutput } from "@huggingface/tasks";

...options,
taskHint: "token-classification",
task: "token-classification",
})

@@ -22,0 +22,0 @@ );

@@ -13,3 +13,3 @@ import type { TranslationInput, TranslationOutput } from "@huggingface/tasks";

...options,
taskHint: "translation",
task: "translation",
});

@@ -16,0 +16,0 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x?.translation_text === "string");

@@ -19,3 +19,3 @@ import type { ZeroShotClassificationInput, ZeroShotClassificationOutput } from "@huggingface/tasks";

...options,
taskHint: "zero-shot-classification",
task: "zero-shot-classification",
})

@@ -22,0 +22,0 @@ );

@@ -30,3 +30,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "tabular-classification",
task: "tabular-classification",
});

@@ -33,0 +33,0 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

@@ -30,3 +30,3 @@ import { InferenceOutputError } from "../../lib/InferenceOutputError";

...options,
taskHint: "tabular-regression",
task: "tabular-regression",
});

@@ -33,0 +33,0 @@ const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

@@ -1,2 +0,2 @@

import type { ChatCompletionInput, PipelineType } from "@huggingface/tasks";
import type { ChatCompletionInput, FeatureExtractionInput, PipelineType } from "@huggingface/tasks";

@@ -89,5 +89,31 @@ /**

| ChatCompletionInput
| FeatureExtractionInput
) & {
parameters?: Record<string, unknown>;
accessToken?: string;
};
export interface ProviderConfig {
baseUrl: string;
makeBody: (params: BodyParams) => Record<string, unknown>;
makeHeaders: (params: HeaderParams) => Record<string, string>;
makeUrl: (params: UrlParams) => string;
}
export interface HeaderParams {
accessToken?: string;
authMethod: "none" | "hf-token" | "credentials-include" | "provider-key";
}
export interface UrlParams {
baseUrl: string;
model: string;
task?: InferenceTask;
chatCompletion?: boolean;
}
export interface BodyParams {
args: Record<string, unknown>;
chatCompletion?: boolean;
model: string;
task?: InferenceTask;
}

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

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