@huggingface/inference 3.4.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,4 +2,6 @@ export { HfInference, HfInferenceEndpoint } from "./HfInference";
2
2
  export { InferenceOutputError } from "./lib/InferenceOutputError";
3
3
  export * from "./types";
4
4
  export * from "./tasks";
5
+ import * as snippets from "./snippets/index.js";
6
+ export { snippets };
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"makeRequestOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/makeRequestOptions.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAqB,aAAa,EAAE,OAAO,EAAkB,WAAW,EAAE,MAAM,UAAU,CAAC;AA8BvG;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,WAAW,GAAG;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,EACD,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAsG7C"}
1
+ {"version":3,"file":"makeRequestOptions.d.ts","sourceRoot":"","sources":["../../../src/lib/makeRequestOptions.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAqB,aAAa,EAAE,OAAO,EAAkB,WAAW,EAAE,MAAM,UAAU,CAAC;AAgCvG;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,IAAI,EAAE,WAAW,GAAG;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB,EACD,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAsH7C"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * See the registered mapping of HF model ID => Cerebras model ID here:
3
+ *
4
+ * https://huggingface.co/api/partners/cerebras/models
5
+ *
6
+ * This is a publicly available mapping.
7
+ *
8
+ * If you want to try to run inference for a new model locally before it's registered on huggingface.co,
9
+ * you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
10
+ *
11
+ * - If you work at Cerebras and want to update this mapping, please use the model mapping API we provide on huggingface.co
12
+ * - If you're a community member and want to add a new supported HF model to Cerebras, please open an issue on the present repo
13
+ * and we will tag Cerebras team members.
14
+ *
15
+ * Thanks!
16
+ */
17
+ import type { ProviderConfig } from "../types";
18
+ export declare const CEREBRAS_CONFIG: ProviderConfig;
19
+ //# sourceMappingURL=cerebras.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cerebras.d.ts","sourceRoot":"","sources":["../../../src/providers/cerebras.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,UAAU,CAAC;AAmBpF,eAAO,MAAM,eAAe,EAAE,cAK7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAkB7F,CAAC"}
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/providers/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,CAoB7F,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Special case: provider configuration for a private models provider (OpenAI in this case).
3
+ */
4
+ import type { ProviderConfig } from "../types";
5
+ export declare const OPENAI_CONFIG: ProviderConfig;
6
+ //# sourceMappingURL=openai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/providers/openai.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,UAAU,CAAC;AAyBpF,eAAO,MAAM,aAAa,EAAE,cAM3B,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { type SnippetInferenceProvider } from "@huggingface/tasks";
2
+ import type { PipelineType } from "@huggingface/tasks/src/pipelines.js";
3
+ import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
4
+ import { type InferenceSnippet, type ModelDataMinimal } from "@huggingface/tasks";
5
+ export declare const snippetBasic: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
6
+ export declare const snippetTextGeneration: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: {
7
+ streaming?: boolean;
8
+ messages?: ChatCompletionInputMessage[];
9
+ temperature?: GenerationParameters["temperature"];
10
+ max_tokens?: GenerationParameters["max_tokens"];
11
+ top_p?: GenerationParameters["top_p"];
12
+ }) => InferenceSnippet[];
13
+ export declare const snippetZeroShotClassification: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
14
+ export declare const snippetFile: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
15
+ export declare const curlSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
16
+ export declare function getCurlInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>): InferenceSnippet[];
17
+ //# sourceMappingURL=curl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../src/snippets/curl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC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AC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CAIpB"}
@@ -0,0 +1,5 @@
1
+ import * as curl from "./curl.js";
2
+ import * as python from "./python.js";
3
+ import * as js from "./js.js";
4
+ export { curl, python, js };
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/snippets/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type SnippetInferenceProvider } from "@huggingface/tasks";
2
+ import type { PipelineType } from "@huggingface/tasks/src/pipelines.js";
3
+ import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
4
+ import { type InferenceSnippet, type ModelDataMinimal } from "@huggingface/tasks";
5
+ export declare const snippetBasic: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
6
+ export declare const snippetTextGeneration: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: {
7
+ streaming?: boolean;
8
+ messages?: ChatCompletionInputMessage[];
9
+ temperature?: GenerationParameters["temperature"];
10
+ max_tokens?: GenerationParameters["max_tokens"];
11
+ top_p?: GenerationParameters["top_p"];
12
+ }) => InferenceSnippet[];
13
+ export declare const snippetZeroShotClassification: (model: ModelDataMinimal, accessToken: string) => InferenceSnippet[];
14
+ export declare const snippetTextToImage: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
15
+ export declare const snippetTextToVideo: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
16
+ export declare const snippetTextToAudio: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
17
+ export declare const snippetAutomaticSpeechRecognition: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
18
+ export declare const snippetFile: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
19
+ export declare const jsSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
20
+ export declare function getJsInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>): InferenceSnippet[];
21
+ //# sourceMappingURL=js.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js.d.ts","sourceRoot":"","sources":["../../../src/snippets/js.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,qCAAqC,CAAC;AACpF,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC9G,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAIrB,MAAM,oBAAoB,CAAC;AAgB5B,eAAO,MAAM,YAAY,UACjB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EA8ClB,CAAC;AAEF,eAAO,MAAM,qBAAqB,UAC1B,gBAAgB,eACV,MAAM,YACT,wBAAwB,oBAChB,MAAM,SACjB;IACN,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAC;IACxC,WAAW,CAAC,EAAE,oBAAoB,CAAC,aAAa,CAAC,CAAC;IAClD,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACtC,KACC,gBAAgB,EA+GlB,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAAW,gBAAgB,eAAe,MAAM,KAAG,gBAAgB,EA2B5G,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACvB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EA4ClB,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACvB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EAqBlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACvB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EAgDlB,CAAC;AAEF,eAAO,MAAM,iCAAiC,UACtC,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EAsBlB,CAAC;AAEF,eAAO,MAAM,WAAW,UAChB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EA6BlB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,OAAO,CAC/B,MAAM,CACL,YAAY,EACZ,CACC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,eAAe,CAAC,EAAE,MAAM,EACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,gBAAgB,EAAE,CACvB,CA2BD,CAAC;AAEF,wBAAgB,qBAAqB,CACpC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,eAAe,CAAC,EAAE,MAAM,EACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CAIpB"}
@@ -0,0 +1,23 @@
1
+ import { type SnippetInferenceProvider } from "@huggingface/tasks";
2
+ import type { PipelineType } from "@huggingface/tasks/src/pipelines.js";
3
+ import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
4
+ import { type InferenceSnippet, type ModelDataMinimal } from "@huggingface/tasks";
5
+ export declare const snippetConversational: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: {
6
+ streaming?: boolean;
7
+ messages?: ChatCompletionInputMessage[];
8
+ temperature?: GenerationParameters["temperature"];
9
+ max_tokens?: GenerationParameters["max_tokens"];
10
+ top_p?: GenerationParameters["top_p"];
11
+ }) => InferenceSnippet[];
12
+ export declare const snippetZeroShotClassification: (model: ModelDataMinimal) => InferenceSnippet[];
13
+ export declare const snippetZeroShotImageClassification: (model: ModelDataMinimal) => InferenceSnippet[];
14
+ export declare const snippetBasic: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
15
+ export declare const snippetFile: (model: ModelDataMinimal) => InferenceSnippet[];
16
+ export declare const snippetTextToImage: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string) => InferenceSnippet[];
17
+ export declare const snippetTextToVideo: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
18
+ export declare const snippetTabular: (model: ModelDataMinimal) => InferenceSnippet[];
19
+ export declare const snippetTextToAudio: (model: ModelDataMinimal) => InferenceSnippet[];
20
+ export declare const snippetDocumentQuestionAnswering: (model: ModelDataMinimal) => InferenceSnippet[];
21
+ export declare const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
22
+ export declare function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>): InferenceSnippet[];
23
+ //# sourceMappingURL=python.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../src/snippets/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB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AAgB,EAuC5E,CAAC;AAEF,eAAO,MAAM,gCAAgC,UAAW,gBAAgB,KAAG,gBAAgB,EAiB1F,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,OAAO,CACnC,MAAM,CACL,YAAY,EACZ,CACC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,eAAe,CAAC,EAAE,MAAM,EACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,gBAAgB,EAAE,CACvB,CA+BD,CAAC;AAEF,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,gBAAgB,EACvB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,wBAAwB,EAClC,eAAe,CAAC,EAAE,MAAM,EACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CA0BpB"}
@@ -1,4 +1,4 @@
1
- import type { ChatCompletionInput, FeatureExtractionInput, PipelineType } from "@huggingface/tasks";
1
+ import type { ChatCompletionInput, PipelineType } from "@huggingface/tasks";
2
2
  /**
3
3
  * HF model id, like "meta-llama/Llama-3.3-70B-Instruct"
4
4
  */
@@ -22,7 +22,7 @@ export interface Options {
22
22
  includeCredentials?: string | boolean;
23
23
  }
24
24
  export type InferenceTask = Exclude<PipelineType, "other">;
25
- export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cohere", "fal-ai", "fireworks-ai", "hf-inference", "hyperbolic", "nebius", "novita", "replicate", "sambanova", "together"];
25
+ export declare const INFERENCE_PROVIDERS: readonly ["black-forest-labs", "cerebras", "cohere", "fal-ai", "fireworks-ai", "hf-inference", "hyperbolic", "nebius", "novita", "openai", "replicate", "sambanova", "together"];
26
26
  export type InferenceProvider = (typeof INFERENCE_PROVIDERS)[number];
27
27
  export interface BaseArgs {
28
28
  /**
@@ -65,7 +65,7 @@ export type RequestArgs = BaseArgs & ({
65
65
  text: string;
66
66
  } | {
67
67
  audio_url: string;
68
- } | ChatCompletionInput | FeatureExtractionInput) & {
68
+ } | ChatCompletionInput) & {
69
69
  parameters?: Record<string, unknown>;
70
70
  };
71
71
  export interface ProviderConfig {
@@ -73,6 +73,7 @@ export interface ProviderConfig {
73
73
  makeBody: (params: BodyParams) => Record<string, unknown>;
74
74
  makeHeaders: (params: HeaderParams) => Record<string, string>;
75
75
  makeUrl: (params: UrlParams) => string;
76
+ clientSideRoutingOnly?: boolean;
76
77
  }
77
78
  export interface HeaderParams {
78
79
  accessToken?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEpG;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,OAAO;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtC;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAE3D,eAAO,MAAM,mBAAmB,4JAYtB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,WAAW,QAAQ;IACxB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,QAAQ,CAAC,E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AW,cAAc;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,WAAW,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9D,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,CAAC;IACvC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,YAAY;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,qBAAqB,GAAG,cAAc,CAAC;CACzE;AAED,MAAM,WAAW,SAAS;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "packageManager": "pnpm@8.10.5",
5
5
  "license": "MIT",
6
6
  "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "type": "module",
41
41
  "dependencies": {
42
- "@huggingface/tasks": "^0.16.4"
42
+ "@huggingface/tasks": "^0.17.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "18.13.0"
package/src/index.ts CHANGED
@@ -2,3 +2,6 @@ export { HfInference, HfInferenceEndpoint } from "./HfInference";
2
2
  export { InferenceOutputError } from "./lib/InferenceOutputError";
3
3
  export * from "./types";
4
4
  export * from "./tasks";
5
+
6
+ import * as snippets from "./snippets/index.js";
7
+ export { snippets };
@@ -1,5 +1,6 @@
1
1
  import { HF_HUB_URL, HF_ROUTER_URL } from "../config";
2
2
  import { BLACK_FOREST_LABS_CONFIG } from "../providers/black-forest-labs";
3
+ import { CEREBRAS_CONFIG } from "../providers/cerebras";
3
4
  import { COHERE_CONFIG } from "../providers/cohere";
4
5
  import { FAL_AI_CONFIG } from "../providers/fal-ai";
5
6
  import { FIREWORKS_AI_CONFIG } from "../providers/fireworks-ai";
@@ -10,6 +11,7 @@ import { NOVITA_CONFIG } from "../providers/novita";
10
11
  import { REPLICATE_CONFIG } from "../providers/replicate";
11
12
  import { SAMBANOVA_CONFIG } from "../providers/sambanova";
12
13
  import { TOGETHER_CONFIG } from "../providers/together";
14
+ import { OPENAI_CONFIG } from "../providers/openai";
13
15
  import type { InferenceProvider, InferenceTask, Options, ProviderConfig, RequestArgs } from "../types";
14
16
  import { isUrl } from "./isUrl";
15
17
  import { version as packageVersion, name as packageName } from "../../package.json";
@@ -28,11 +30,13 @@ let tasks: Record<string, { models: { id: string }[] }> | null = null;
28
30
  */
29
31
  const providerConfigs: Record<InferenceProvider, ProviderConfig> = {
30
32
  "black-forest-labs": BLACK_FOREST_LABS_CONFIG,
33
+ cerebras: CEREBRAS_CONFIG,
31
34
  cohere: COHERE_CONFIG,
32
35
  "fal-ai": FAL_AI_CONFIG,
33
36
  "fireworks-ai": FIREWORKS_AI_CONFIG,
34
37
  "hf-inference": HF_INFERENCE_CONFIG,
35
38
  hyperbolic: HYPERBOLIC_CONFIG,
39
+ openai: OPENAI_CONFIG,
36
40
  nebius: NEBIUS_CONFIG,
37
41
  novita: NOVITA_CONFIG,
38
42
  replicate: REPLICATE_CONFIG,
@@ -72,22 +76,38 @@ export async function makeRequestOptions(
72
76
  if (!providerConfig) {
73
77
  throw new Error(`No provider config found for provider ${provider}`);
74
78
  }
79
+ if (providerConfig.clientSideRoutingOnly && !maybeModel) {
80
+ throw new Error(`Provider ${provider} requires a model ID to be passed directly.`);
81
+ }
75
82
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76
83
  const hfModel = maybeModel ?? (await loadDefaultModel(task!));
77
- const model = await getProviderModelId({ model: hfModel, provider }, args, {
78
- task,
79
- chatCompletion,
80
- fetch: options?.fetch,
81
- });
84
+ const model = providerConfig.clientSideRoutingOnly
85
+ ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
86
+ removeProviderPrefix(maybeModel!, provider)
87
+ : // For closed-models API providers, one needs to pass the model ID directly (e.g. "gpt-3.5-turbo")
88
+ await getProviderModelId({ model: hfModel, provider }, args, {
89
+ task,
90
+ chatCompletion,
91
+ fetch: options?.fetch,
92
+ });
82
93
 
83
- /// If accessToken is passed, it should take precedence over includeCredentials
84
- const authMethod = accessToken
85
- ? accessToken.startsWith("hf_")
86
- ? "hf-token"
87
- : "provider-key"
88
- : includeCredentials === "include"
89
- ? "credentials-include"
90
- : "none";
94
+ const authMethod = (() => {
95
+ if (providerConfig.clientSideRoutingOnly) {
96
+ // Closed-source providers require an accessToken (cannot be routed).
97
+ if (accessToken && accessToken.startsWith("hf_")) {
98
+ throw new Error(`Provider ${provider} is closed-source and does not support HF tokens.`);
99
+ }
100
+ return "provider-key";
101
+ }
102
+ if (accessToken) {
103
+ return accessToken.startsWith("hf_") ? "hf-token" : "provider-key";
104
+ }
105
+ if (includeCredentials === "include") {
106
+ // If accessToken is passed, it should take precedence over includeCredentials
107
+ return "credentials-include";
108
+ }
109
+ return "none";
110
+ })();
91
111
 
92
112
  // Make URL
93
113
  const url = endpointUrl
@@ -176,3 +196,10 @@ async function loadTaskInfo(): Promise<Record<string, { models: { id: string }[]
176
196
  }
177
197
  return await res.json();
178
198
  }
199
+
200
+ function removeProviderPrefix(model: string, provider: string): string {
201
+ if (!model.startsWith(`${provider}/`)) {
202
+ throw new Error(`Models from ${provider} must be prefixed by "${provider}/". Got "${model}".`);
203
+ }
204
+ return model.slice(provider.length + 1);
205
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * See the registered mapping of HF model ID => Cerebras model ID here:
3
+ *
4
+ * https://huggingface.co/api/partners/cerebras/models
5
+ *
6
+ * This is a publicly available mapping.
7
+ *
8
+ * If you want to try to run inference for a new model locally before it's registered on huggingface.co,
9
+ * you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
10
+ *
11
+ * - If you work at Cerebras and want to update this mapping, please use the model mapping API we provide on huggingface.co
12
+ * - If you're a community member and want to add a new supported HF model to Cerebras, please open an issue on the present repo
13
+ * and we will tag Cerebras team members.
14
+ *
15
+ * Thanks!
16
+ */
17
+ import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
18
+
19
+ const CEREBRAS_API_BASE_URL = "https://api.cerebras.ai";
20
+
21
+ const makeBody = (params: BodyParams): Record<string, unknown> => {
22
+ return {
23
+ ...params.args,
24
+ model: params.model,
25
+ };
26
+ };
27
+
28
+ const makeHeaders = (params: HeaderParams): Record<string, string> => {
29
+ return { Authorization: `Bearer ${params.accessToken}` };
30
+ };
31
+
32
+ const makeUrl = (params: UrlParams): string => {
33
+ return `${params.baseUrl}/v1/chat/completions`;
34
+ };
35
+
36
+ export const CEREBRAS_CONFIG: ProviderConfig = {
37
+ baseUrl: CEREBRAS_API_BASE_URL,
38
+ makeBody,
39
+ makeHeaders,
40
+ makeUrl,
41
+ };
@@ -17,6 +17,7 @@ export const HARDCODED_MODEL_ID_MAPPING: Record<InferenceProvider, Record<ModelI
17
17
  * "Qwen/Qwen2.5-Coder-32B-Instruct": "Qwen2.5-Coder-32B-Instruct",
18
18
  */
19
19
  "black-forest-labs": {},
20
+ cerebras: {},
20
21
  cohere: {},
21
22
  "fal-ai": {},
22
23
  "fireworks-ai": {},
@@ -24,6 +25,7 @@ export const HARDCODED_MODEL_ID_MAPPING: Record<InferenceProvider, Record<ModelI
24
25
  hyperbolic: {},
25
26
  nebius: {},
26
27
  novita: {},
28
+ openai: {},
27
29
  replicate: {},
28
30
  sambanova: {},
29
31
  together: {},
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Special case: provider configuration for a private models provider (OpenAI in this case).
3
+ */
4
+ import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
5
+
6
+ const OPENAI_API_BASE_URL = "https://api.openai.com";
7
+
8
+ const makeBody = (params: BodyParams): Record<string, unknown> => {
9
+ if (!params.chatCompletion) {
10
+ throw new Error("OpenAI only supports chat completions.");
11
+ }
12
+ return {
13
+ ...params.args,
14
+ model: params.model,
15
+ };
16
+ };
17
+
18
+ const makeHeaders = (params: HeaderParams): Record<string, string> => {
19
+ return { Authorization: `Bearer ${params.accessToken}` };
20
+ };
21
+
22
+ const makeUrl = (params: UrlParams): string => {
23
+ if (!params.chatCompletion) {
24
+ throw new Error("OpenAI only supports chat completions.");
25
+ }
26
+ return `${params.baseUrl}/v1/chat/completions`;
27
+ };
28
+
29
+ export const OPENAI_CONFIG: ProviderConfig = {
30
+ baseUrl: OPENAI_API_BASE_URL,
31
+ makeBody,
32
+ makeHeaders,
33
+ makeUrl,
34
+ clientSideRoutingOnly: true,
35
+ };
@@ -0,0 +1,177 @@
1
+ import { HF_HUB_INFERENCE_PROXY_TEMPLATE, type SnippetInferenceProvider } from "@huggingface/tasks";
2
+ import type { PipelineType } from "@huggingface/tasks/src/pipelines.js";
3
+ import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
4
+ import {
5
+ type InferenceSnippet,
6
+ type ModelDataMinimal,
7
+ getModelInputSnippet,
8
+ stringifyGenerationConfig,
9
+ stringifyMessages,
10
+ } from "@huggingface/tasks";
11
+
12
+ export const snippetBasic = (
13
+ model: ModelDataMinimal,
14
+ accessToken: string,
15
+ provider: SnippetInferenceProvider
16
+ ): InferenceSnippet[] => {
17
+ if (provider !== "hf-inference") {
18
+ return [];
19
+ }
20
+ return [
21
+ {
22
+ client: "curl",
23
+ content: `\
24
+ curl https://router.huggingface.co/hf-inference/models/${model.id} \\
25
+ -X POST \\
26
+ -d '{"inputs": ${getModelInputSnippet(model, true)}}' \\
27
+ -H 'Content-Type: application/json' \\
28
+ -H 'Authorization: Bearer ${accessToken || `{API_TOKEN}`}'`,
29
+ },
30
+ ];
31
+ };
32
+
33
+ export const snippetTextGeneration = (
34
+ model: ModelDataMinimal,
35
+ accessToken: string,
36
+ provider: SnippetInferenceProvider,
37
+ providerModelId?: string,
38
+ opts?: {
39
+ streaming?: boolean;
40
+ messages?: ChatCompletionInputMessage[];
41
+ temperature?: GenerationParameters["temperature"];
42
+ max_tokens?: GenerationParameters["max_tokens"];
43
+ top_p?: GenerationParameters["top_p"];
44
+ }
45
+ ): InferenceSnippet[] => {
46
+ if (model.tags.includes("conversational")) {
47
+ const baseUrl =
48
+ provider === "hf-inference"
49
+ ? `https://router.huggingface.co/hf-inference/models/${model.id}/v1/chat/completions`
50
+ : HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", provider) + "/v1/chat/completions";
51
+ const modelId = providerModelId ?? model.id;
52
+
53
+ // Conversational model detected, so we display a code snippet that features the Messages API
54
+ const streaming = opts?.streaming ?? true;
55
+ const exampleMessages = getModelInputSnippet(model) as ChatCompletionInputMessage[];
56
+ const messages = opts?.messages ?? exampleMessages;
57
+
58
+ const config = {
59
+ ...(opts?.temperature ? { temperature: opts.temperature } : undefined),
60
+ max_tokens: opts?.max_tokens ?? 500,
61
+ ...(opts?.top_p ? { top_p: opts.top_p } : undefined),
62
+ };
63
+ return [
64
+ {
65
+ client: "curl",
66
+ content: `curl '${baseUrl}' \\
67
+ -H 'Authorization: Bearer ${accessToken || `{API_TOKEN}`}' \\
68
+ -H 'Content-Type: application/json' \\
69
+ --data '{
70
+ "model": "${modelId}",
71
+ "messages": ${stringifyMessages(messages, {
72
+ indent: "\t",
73
+ attributeKeyQuotes: true,
74
+ customContentEscaper: (str) => str.replace(/'/g, "'\\''"),
75
+ })},
76
+ ${stringifyGenerationConfig(config, {
77
+ indent: "\n ",
78
+ attributeKeyQuotes: true,
79
+ attributeValueConnector: ": ",
80
+ })}
81
+ "stream": ${!!streaming}
82
+ }'`,
83
+ },
84
+ ];
85
+ } else {
86
+ return snippetBasic(model, accessToken, provider);
87
+ }
88
+ };
89
+
90
+ export const snippetZeroShotClassification = (
91
+ model: ModelDataMinimal,
92
+ accessToken: string,
93
+ provider: SnippetInferenceProvider
94
+ ): InferenceSnippet[] => {
95
+ if (provider !== "hf-inference") {
96
+ return [];
97
+ }
98
+ return [
99
+ {
100
+ client: "curl",
101
+ content: `curl https://router.huggingface.co/hf-inference/models/${model.id} \\
102
+ -X POST \\
103
+ -d '{"inputs": ${getModelInputSnippet(model, true)}, "parameters": {"candidate_labels": ["refund", "legal", "faq"]}}' \\
104
+ -H 'Content-Type: application/json' \\
105
+ -H 'Authorization: Bearer ${accessToken || `{API_TOKEN}`}'`,
106
+ },
107
+ ];
108
+ };
109
+
110
+ export const snippetFile = (
111
+ model: ModelDataMinimal,
112
+ accessToken: string,
113
+ provider: SnippetInferenceProvider
114
+ ): InferenceSnippet[] => {
115
+ if (provider !== "hf-inference") {
116
+ return [];
117
+ }
118
+ return [
119
+ {
120
+ client: "curl",
121
+ content: `curl https://router.huggingface.co/hf-inference/models/${model.id} \\
122
+ -X POST \\
123
+ --data-binary '@${getModelInputSnippet(model, true, true)}' \\
124
+ -H 'Authorization: Bearer ${accessToken || `{API_TOKEN}`}'`,
125
+ },
126
+ ];
127
+ };
128
+
129
+ export const curlSnippets: Partial<
130
+ Record<
131
+ PipelineType,
132
+ (
133
+ model: ModelDataMinimal,
134
+ accessToken: string,
135
+ provider: SnippetInferenceProvider,
136
+ providerModelId?: string,
137
+ opts?: Record<string, unknown>
138
+ ) => InferenceSnippet[]
139
+ >
140
+ > = {
141
+ // Same order as in tasks/src/pipelines.ts
142
+ "text-classification": snippetBasic,
143
+ "token-classification": snippetBasic,
144
+ "table-question-answering": snippetBasic,
145
+ "question-answering": snippetBasic,
146
+ "zero-shot-classification": snippetZeroShotClassification,
147
+ translation: snippetBasic,
148
+ summarization: snippetBasic,
149
+ "feature-extraction": snippetBasic,
150
+ "text-generation": snippetTextGeneration,
151
+ "image-text-to-text": snippetTextGeneration,
152
+ "text2text-generation": snippetBasic,
153
+ "fill-mask": snippetBasic,
154
+ "sentence-similarity": snippetBasic,
155
+ "automatic-speech-recognition": snippetFile,
156
+ "text-to-image": snippetBasic,
157
+ "text-to-speech": snippetBasic,
158
+ "text-to-audio": snippetBasic,
159
+ "audio-to-audio": snippetFile,
160
+ "audio-classification": snippetFile,
161
+ "image-classification": snippetFile,
162
+ "image-to-text": snippetFile,
163
+ "object-detection": snippetFile,
164
+ "image-segmentation": snippetFile,
165
+ };
166
+
167
+ export function getCurlInferenceSnippet(
168
+ model: ModelDataMinimal,
169
+ accessToken: string,
170
+ provider: SnippetInferenceProvider,
171
+ providerModelId?: string,
172
+ opts?: Record<string, unknown>
173
+ ): InferenceSnippet[] {
174
+ return model.pipeline_tag && model.pipeline_tag in curlSnippets
175
+ ? curlSnippets[model.pipeline_tag]?.(model, accessToken, provider, providerModelId, opts) ?? []
176
+ : [];
177
+ }
@@ -0,0 +1,5 @@
1
+ import * as curl from "./curl.js";
2
+ import * as python from "./python.js";
3
+ import * as js from "./js.js";
4
+
5
+ export { curl, python, js };