@huggingface/inference 4.5.1 → 4.5.2
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/commonjs/config.d.ts +1 -0
- package/dist/commonjs/config.d.ts.map +1 -1
- package/dist/commonjs/config.js +2 -1
- package/dist/commonjs/package.d.ts +1 -1
- package/dist/commonjs/package.js +1 -1
- package/dist/commonjs/providers/black-forest-labs.d.ts +1 -1
- package/dist/commonjs/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/commonjs/providers/black-forest-labs.js +3 -0
- package/dist/commonjs/providers/fal-ai.d.ts +1 -1
- package/dist/commonjs/providers/fal-ai.d.ts.map +1 -1
- package/dist/commonjs/providers/fal-ai.js +4 -1
- package/dist/commonjs/providers/hf-inference.d.ts +1 -1
- package/dist/commonjs/providers/hf-inference.d.ts.map +1 -1
- package/dist/commonjs/providers/hf-inference.js +5 -2
- package/dist/commonjs/providers/hyperbolic.d.ts +1 -1
- package/dist/commonjs/providers/hyperbolic.d.ts.map +1 -1
- package/dist/commonjs/providers/hyperbolic.js +3 -0
- package/dist/commonjs/providers/nebius.d.ts +1 -1
- package/dist/commonjs/providers/nebius.d.ts.map +1 -1
- package/dist/commonjs/providers/nebius.js +3 -0
- package/dist/commonjs/providers/nscale.d.ts +1 -1
- package/dist/commonjs/providers/nscale.d.ts.map +1 -1
- package/dist/commonjs/providers/nscale.js +3 -0
- package/dist/commonjs/providers/providerHelper.d.ts +1 -1
- package/dist/commonjs/providers/providerHelper.d.ts.map +1 -1
- package/dist/commonjs/providers/replicate.d.ts +1 -1
- package/dist/commonjs/providers/replicate.d.ts.map +1 -1
- package/dist/commonjs/providers/replicate.js +3 -0
- package/dist/commonjs/providers/together.d.ts +1 -1
- package/dist/commonjs/providers/together.d.ts.map +1 -1
- package/dist/commonjs/providers/together.js +4 -1
- package/dist/commonjs/snippets/getInferenceSnippets.d.ts +1 -0
- package/dist/commonjs/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/commonjs/snippets/getInferenceSnippets.js +8 -3
- package/dist/commonjs/tasks/cv/textToImage.d.ts +4 -1
- package/dist/commonjs/tasks/cv/textToImage.d.ts.map +1 -1
- package/dist/esm/config.d.ts +1 -0
- package/dist/esm/config.d.ts.map +1 -1
- package/dist/esm/config.js +1 -0
- package/dist/esm/package.d.ts +1 -1
- package/dist/esm/package.js +1 -1
- package/dist/esm/providers/black-forest-labs.d.ts +1 -1
- package/dist/esm/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/esm/providers/black-forest-labs.js +3 -0
- package/dist/esm/providers/fal-ai.d.ts +1 -1
- package/dist/esm/providers/fal-ai.d.ts.map +1 -1
- package/dist/esm/providers/fal-ai.js +4 -1
- package/dist/esm/providers/hf-inference.d.ts +1 -1
- package/dist/esm/providers/hf-inference.d.ts.map +1 -1
- package/dist/esm/providers/hf-inference.js +5 -2
- package/dist/esm/providers/hyperbolic.d.ts +1 -1
- package/dist/esm/providers/hyperbolic.d.ts.map +1 -1
- package/dist/esm/providers/hyperbolic.js +3 -0
- package/dist/esm/providers/nebius.d.ts +1 -1
- package/dist/esm/providers/nebius.d.ts.map +1 -1
- package/dist/esm/providers/nebius.js +3 -0
- package/dist/esm/providers/nscale.d.ts +1 -1
- package/dist/esm/providers/nscale.d.ts.map +1 -1
- package/dist/esm/providers/nscale.js +3 -0
- package/dist/esm/providers/providerHelper.d.ts +1 -1
- package/dist/esm/providers/providerHelper.d.ts.map +1 -1
- package/dist/esm/providers/replicate.d.ts +1 -1
- package/dist/esm/providers/replicate.d.ts.map +1 -1
- package/dist/esm/providers/replicate.js +3 -0
- package/dist/esm/providers/together.d.ts +1 -1
- package/dist/esm/providers/together.d.ts.map +1 -1
- package/dist/esm/providers/together.js +4 -1
- package/dist/esm/snippets/getInferenceSnippets.d.ts +1 -0
- package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/esm/snippets/getInferenceSnippets.js +8 -3
- package/dist/esm/tasks/cv/textToImage.d.ts +4 -1
- package/dist/esm/tasks/cv/textToImage.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/config.ts +1 -0
- package/src/package.ts +1 -1
- package/src/providers/black-forest-labs.ts +5 -2
- package/src/providers/fal-ai.ts +9 -1
- package/src/providers/hf-inference.ts +7 -4
- package/src/providers/hyperbolic.ts +5 -2
- package/src/providers/nebius.ts +5 -2
- package/src/providers/nscale.ts +5 -2
- package/src/providers/providerHelper.ts +2 -2
- package/src/providers/replicate.ts +5 -2
- package/src/providers/together.ts +9 -1
- package/src/snippets/getInferenceSnippets.ts +9 -3
- package/src/tasks/cv/textToImage.ts +9 -2
|
@@ -13,6 +13,7 @@ import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions.j
|
|
|
13
13
|
import type { InferenceProviderMappingEntry, InferenceProviderOrPolicy, InferenceTask, RequestArgs } from "../types.js";
|
|
14
14
|
import { templates } from "./templates.exported.js";
|
|
15
15
|
import { getLogger } from "../lib/logger.js";
|
|
16
|
+
import { HF_ROUTER_AUTO_ENDPOINT } from "../config.js";
|
|
16
17
|
|
|
17
18
|
export type InferenceSnippetOptions = {
|
|
18
19
|
streaming?: boolean;
|
|
@@ -20,6 +21,7 @@ export type InferenceSnippetOptions = {
|
|
|
20
21
|
accessToken?: string;
|
|
21
22
|
directRequest?: boolean; // to bypass HF routing and call the provider directly
|
|
22
23
|
endpointUrl?: string; // to call a local endpoint directly
|
|
24
|
+
inputs?: Record<string, unknown>; // overrides the default snippet's inputs
|
|
23
25
|
} & Record<string, unknown>;
|
|
24
26
|
|
|
25
27
|
const PYTHON_CLIENTS = ["huggingface_hub", "fal_client", "requests", "openai"] as const;
|
|
@@ -36,7 +38,7 @@ const CLIENTS: Record<InferenceSnippetLanguage, Client[]> = {
|
|
|
36
38
|
|
|
37
39
|
const CLIENTS_AUTO_POLICY: Partial<Record<InferenceSnippetLanguage, Client[]>> = {
|
|
38
40
|
js: ["huggingface.js"],
|
|
39
|
-
python: ["huggingface_hub"],
|
|
41
|
+
python: ["huggingface_hub", "openai"],
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
type InputPreparationFn = (model: ModelDataMinimal, opts?: Record<string, unknown>) => object;
|
|
@@ -167,14 +169,18 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
|
|
|
167
169
|
const accessTokenOrPlaceholder = opts?.accessToken ?? placeholder;
|
|
168
170
|
|
|
169
171
|
/// Prepare inputs + make request
|
|
170
|
-
const inputs =
|
|
172
|
+
const inputs = opts?.inputs
|
|
173
|
+
? { inputs: opts.inputs }
|
|
174
|
+
: inputPreparationFn
|
|
175
|
+
? inputPreparationFn(model, opts)
|
|
176
|
+
: { inputs: getModelInputSnippet(model) };
|
|
171
177
|
const request = makeRequestOptionsFromResolvedModel(
|
|
172
178
|
providerModelId,
|
|
173
179
|
providerHelper,
|
|
174
180
|
{
|
|
175
181
|
accessToken: accessTokenOrPlaceholder,
|
|
176
182
|
provider,
|
|
177
|
-
endpointUrl: opts?.endpointUrl,
|
|
183
|
+
endpointUrl: opts?.endpointUrl ?? (provider === "auto" ? HF_ROUTER_AUTO_ENDPOINT : undefined),
|
|
178
184
|
...inputs,
|
|
179
185
|
} as RequestArgs,
|
|
180
186
|
inferenceProviderMapping,
|
|
@@ -8,7 +8,7 @@ import { innerRequest } from "../../utils/request.js";
|
|
|
8
8
|
export type TextToImageArgs = BaseArgs & TextToImageInput;
|
|
9
9
|
|
|
10
10
|
interface TextToImageOptions extends Options {
|
|
11
|
-
outputType?: "url" | "blob";
|
|
11
|
+
outputType?: "url" | "blob" | "json";
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -23,7 +23,14 @@ export async function textToImage(
|
|
|
23
23
|
args: TextToImageArgs,
|
|
24
24
|
options?: TextToImageOptions & { outputType?: undefined | "blob" }
|
|
25
25
|
): Promise<Blob>;
|
|
26
|
-
export async function textToImage(
|
|
26
|
+
export async function textToImage(
|
|
27
|
+
args: TextToImageArgs,
|
|
28
|
+
options?: TextToImageOptions & { outputType?: undefined | "json" }
|
|
29
|
+
): Promise<Record<string, unknown>>;
|
|
30
|
+
export async function textToImage(
|
|
31
|
+
args: TextToImageArgs,
|
|
32
|
+
options?: TextToImageOptions
|
|
33
|
+
): Promise<Blob | string | Record<string, unknown>> {
|
|
27
34
|
const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
|
|
28
35
|
const providerHelper = getProviderHelper(provider, "text-to-image");
|
|
29
36
|
const { data: res } = await innerRequest<Record<string, unknown>>(args, providerHelper, {
|