@huggingface/inference 4.13.10 → 4.13.12

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.
Files changed (86) hide show
  1. package/README.md +2 -0
  2. package/dist/commonjs/lib/getProviderHelper.d.ts.map +1 -1
  3. package/dist/commonjs/lib/getProviderHelper.js +4 -0
  4. package/dist/commonjs/package.d.ts +1 -1
  5. package/dist/commonjs/package.js +1 -1
  6. package/dist/commonjs/providers/consts.d.ts.map +1 -1
  7. package/dist/commonjs/providers/consts.js +1 -0
  8. package/dist/commonjs/providers/nvidia.d.ts +21 -0
  9. package/dist/commonjs/providers/nvidia.d.ts.map +1 -0
  10. package/dist/commonjs/providers/nvidia.js +26 -0
  11. package/dist/commonjs/providers/replicate.d.ts.map +1 -1
  12. package/dist/commonjs/providers/replicate.js +6 -1
  13. package/dist/commonjs/snippets/getInferenceSnippets.js +11 -20
  14. package/dist/commonjs/types.d.ts +2 -2
  15. package/dist/commonjs/types.d.ts.map +1 -1
  16. package/dist/commonjs/types.js +2 -0
  17. package/dist/esm/lib/getProviderHelper.d.ts.map +1 -1
  18. package/dist/esm/lib/getProviderHelper.js +4 -0
  19. package/dist/esm/package.d.ts +1 -1
  20. package/dist/esm/package.js +1 -1
  21. package/dist/esm/providers/consts.d.ts.map +1 -1
  22. package/dist/esm/providers/consts.js +1 -0
  23. package/dist/esm/providers/nvidia.d.ts +21 -0
  24. package/dist/esm/providers/nvidia.d.ts.map +1 -0
  25. package/dist/esm/providers/nvidia.js +22 -0
  26. package/dist/esm/providers/replicate.d.ts.map +1 -1
  27. package/dist/esm/providers/replicate.js +6 -1
  28. package/dist/esm/snippets/getInferenceSnippets.js +11 -20
  29. package/dist/esm/types.d.ts +2 -2
  30. package/dist/esm/types.d.ts.map +1 -1
  31. package/dist/esm/types.js +2 -0
  32. package/package.json +34 -34
  33. package/src/InferenceClient.ts +2 -2
  34. package/src/errors.ts +1 -1
  35. package/src/lib/getDefaultTask.ts +1 -1
  36. package/src/lib/getInferenceProviderMapping.ts +11 -11
  37. package/src/lib/getProviderHelper.ts +41 -37
  38. package/src/lib/makeRequestOptions.ts +11 -11
  39. package/src/package.ts +1 -1
  40. package/src/providers/black-forest-labs.ts +3 -3
  41. package/src/providers/consts.ts +1 -0
  42. package/src/providers/fal-ai.ts +33 -33
  43. package/src/providers/featherless-ai.ts +1 -1
  44. package/src/providers/hf-inference.ts +48 -48
  45. package/src/providers/hyperbolic.ts +3 -3
  46. package/src/providers/nebius.ts +1 -1
  47. package/src/providers/novita.ts +7 -7
  48. package/src/providers/nscale.ts +2 -2
  49. package/src/providers/nvidia.ts +23 -0
  50. package/src/providers/ovhcloud.ts +1 -1
  51. package/src/providers/providerHelper.ts +7 -7
  52. package/src/providers/replicate.ts +8 -3
  53. package/src/providers/sambanova.ts +1 -1
  54. package/src/providers/together.ts +1 -1
  55. package/src/providers/wavespeed.ts +10 -10
  56. package/src/providers/zai-org.ts +7 -7
  57. package/src/snippets/getInferenceSnippets.ts +26 -26
  58. package/src/tasks/audio/audioClassification.ts +1 -1
  59. package/src/tasks/audio/automaticSpeechRecognition.ts +1 -1
  60. package/src/tasks/audio/utils.ts +1 -1
  61. package/src/tasks/custom/request.ts +2 -2
  62. package/src/tasks/custom/streamingRequest.ts +2 -2
  63. package/src/tasks/cv/imageClassification.ts +1 -1
  64. package/src/tasks/cv/imageSegmentation.ts +1 -1
  65. package/src/tasks/cv/textToImage.ts +5 -5
  66. package/src/tasks/cv/textToVideo.ts +1 -1
  67. package/src/tasks/cv/zeroShotImageClassification.ts +3 -3
  68. package/src/tasks/multimodal/documentQuestionAnswering.ts +2 -2
  69. package/src/tasks/multimodal/visualQuestionAnswering.ts +1 -1
  70. package/src/tasks/nlp/chatCompletion.ts +1 -1
  71. package/src/tasks/nlp/chatCompletionStream.ts +1 -1
  72. package/src/tasks/nlp/featureExtraction.ts +1 -1
  73. package/src/tasks/nlp/questionAnswering.ts +2 -2
  74. package/src/tasks/nlp/sentenceSimilarity.ts +1 -1
  75. package/src/tasks/nlp/tableQuestionAnswering.ts +2 -2
  76. package/src/tasks/nlp/textClassification.ts +1 -1
  77. package/src/tasks/nlp/textGeneration.ts +1 -1
  78. package/src/tasks/nlp/textGenerationStream.ts +1 -1
  79. package/src/tasks/nlp/tokenClassification.ts +2 -2
  80. package/src/tasks/nlp/zeroShotClassification.ts +2 -2
  81. package/src/tasks/tabular/tabularClassification.ts +1 -1
  82. package/src/tasks/tabular/tabularRegression.ts +1 -1
  83. package/src/types.ts +2 -0
  84. package/src/utils/pick.ts +1 -1
  85. package/src/utils/request.ts +20 -20
  86. package/src/utils/typedEntries.ts +1 -1
@@ -29,8 +29,8 @@ async function preparePayload(args: ZeroShotImageClassificationArgs): Promise<Re
29
29
  inputs: {
30
30
  image: base64FromBytes(
31
31
  new Uint8Array(
32
- args.inputs.image instanceof ArrayBuffer ? args.inputs.image : await args.inputs.image.arrayBuffer()
33
- )
32
+ args.inputs.image instanceof ArrayBuffer ? args.inputs.image : await args.inputs.image.arrayBuffer(),
33
+ ),
34
34
  ),
35
35
  },
36
36
  };
@@ -43,7 +43,7 @@ async function preparePayload(args: ZeroShotImageClassificationArgs): Promise<Re
43
43
  */
44
44
  export async function zeroShotImageClassification(
45
45
  args: ZeroShotImageClassificationArgs,
46
- options?: Options
46
+ options?: Options,
47
47
  ): Promise<ZeroShotImageClassificationOutput> {
48
48
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
49
49
  const providerHelper = getProviderHelper(provider, "zero-shot-image-classification");
@@ -18,7 +18,7 @@ export type DocumentQuestionAnsweringArgs = BaseArgs &
18
18
  */
19
19
  export async function documentQuestionAnswering(
20
20
  args: DocumentQuestionAnsweringArgs,
21
- options?: Options
21
+ options?: Options,
22
22
  ): Promise<DocumentQuestionAnsweringOutput[number]> {
23
23
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
24
24
  const providerHelper = getProviderHelper(provider, "document-question-answering");
@@ -36,7 +36,7 @@ export async function documentQuestionAnswering(
36
36
  {
37
37
  ...options,
38
38
  task: "document-question-answering",
39
- }
39
+ },
40
40
  );
41
41
  return providerHelper.getResponse(res);
42
42
  }
@@ -18,7 +18,7 @@ export type VisualQuestionAnsweringArgs = BaseArgs &
18
18
  */
19
19
  export async function visualQuestionAnswering(
20
20
  args: VisualQuestionAnsweringArgs,
21
- options?: Options
21
+ options?: Options,
22
22
  ): Promise<VisualQuestionAnsweringOutput[number]> {
23
23
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
24
24
  const providerHelper = getProviderHelper(provider, "visual-question-answering");
@@ -11,7 +11,7 @@ import { AutoRouterConversationalTask } from "../../providers/providerHelper.js"
11
11
  */
12
12
  export async function chatCompletion(
13
13
  args: BaseArgs & ChatCompletionInput,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<ChatCompletionOutput> {
16
16
  let providerHelper: ConversationalTaskHelper & TaskProviderHelper;
17
17
  if (!args.provider || args.provider === "auto") {
@@ -11,7 +11,7 @@ import { AutoRouterConversationalTask } from "../../providers/providerHelper.js"
11
11
  */
12
12
  export async function* chatCompletionStream(
13
13
  args: BaseArgs & ChatCompletionInput,
14
- options?: Options
14
+ options?: Options,
15
15
  ): AsyncGenerator<ChatCompletionStreamOutput> {
16
16
  let providerHelper: ConversationalTaskHelper & TaskProviderHelper;
17
17
  if (!args.provider || args.provider === "auto") {
@@ -21,7 +21,7 @@ export type FeatureExtractionOutput = (number | number[] | number[][])[];
21
21
  */
22
22
  export async function featureExtraction(
23
23
  args: FeatureExtractionArgs,
24
- options?: Options
24
+ options?: Options,
25
25
  ): Promise<FeatureExtractionOutput> {
26
26
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
27
27
  const providerHelper = getProviderHelper(provider, "feature-extraction");
@@ -12,7 +12,7 @@ export type QuestionAnsweringArgs = BaseArgs & QuestionAnsweringInput;
12
12
  */
13
13
  export async function questionAnswering(
14
14
  args: QuestionAnsweringArgs,
15
- options?: Options
15
+ options?: Options,
16
16
  ): Promise<QuestionAnsweringOutput[number]> {
17
17
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
18
18
  const providerHelper = getProviderHelper(provider, "question-answering");
@@ -22,7 +22,7 @@ export async function questionAnswering(
22
22
  {
23
23
  ...options,
24
24
  task: "question-answering",
25
- }
25
+ },
26
26
  );
27
27
  return providerHelper.getResponse(res);
28
28
  }
@@ -11,7 +11,7 @@ export type SentenceSimilarityArgs = BaseArgs & SentenceSimilarityInput;
11
11
  */
12
12
  export async function sentenceSimilarity(
13
13
  args: SentenceSimilarityArgs,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<SentenceSimilarityOutput> {
16
16
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
17
17
  const providerHelper = getProviderHelper(provider, "sentence-similarity");
@@ -11,7 +11,7 @@ export type TableQuestionAnsweringArgs = BaseArgs & TableQuestionAnsweringInput;
11
11
  */
12
12
  export async function tableQuestionAnswering(
13
13
  args: TableQuestionAnsweringArgs,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<TableQuestionAnsweringOutput[number]> {
16
16
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
17
17
  const providerHelper = getProviderHelper(provider, "table-question-answering");
@@ -21,7 +21,7 @@ export async function tableQuestionAnswering(
21
21
  {
22
22
  ...options,
23
23
  task: "table-question-answering",
24
- }
24
+ },
25
25
  );
26
26
  return providerHelper.getResponse(res);
27
27
  }
@@ -11,7 +11,7 @@ export type TextClassificationArgs = BaseArgs & TextClassificationInput;
11
11
  */
12
12
  export async function textClassification(
13
13
  args: TextClassificationArgs,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<TextClassificationOutput> {
16
16
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
17
17
  const providerHelper = getProviderHelper(provider, "text-classification");
@@ -12,7 +12,7 @@ export type { TextGenerationInput, TextGenerationOutput };
12
12
  */
13
13
  export async function textGeneration(
14
14
  args: BaseArgs & TextGenerationInput,
15
- options?: Options
15
+ options?: Options,
16
16
  ): Promise<TextGenerationOutput> {
17
17
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
18
18
  const providerHelper = getProviderHelper(provider, "text-generation");
@@ -89,7 +89,7 @@ export interface TextGenerationStreamOutput {
89
89
  */
90
90
  export async function* textGenerationStream(
91
91
  args: BaseArgs & TextGenerationInput,
92
- options?: Options
92
+ options?: Options,
93
93
  ): AsyncGenerator<TextGenerationStreamOutput> {
94
94
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
95
95
  const providerHelper = getProviderHelper(provider, "text-generation");
@@ -11,7 +11,7 @@ export type TokenClassificationArgs = BaseArgs & TokenClassificationInput;
11
11
  */
12
12
  export async function tokenClassification(
13
13
  args: TokenClassificationArgs,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<TokenClassificationOutput> {
16
16
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
17
17
  const providerHelper = getProviderHelper(provider, "token-classification");
@@ -21,7 +21,7 @@ export async function tokenClassification(
21
21
  {
22
22
  ...options,
23
23
  task: "token-classification",
24
- }
24
+ },
25
25
  );
26
26
  return providerHelper.getResponse(res);
27
27
  }
@@ -11,7 +11,7 @@ export type ZeroShotClassificationArgs = BaseArgs & ZeroShotClassificationInput;
11
11
  */
12
12
  export async function zeroShotClassification(
13
13
  args: ZeroShotClassificationArgs,
14
- options?: Options
14
+ options?: Options,
15
15
  ): Promise<ZeroShotClassificationOutput> {
16
16
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
17
17
  const providerHelper = getProviderHelper(provider, "zero-shot-classification");
@@ -21,7 +21,7 @@ export async function zeroShotClassification(
21
21
  {
22
22
  ...options,
23
23
  task: "zero-shot-classification",
24
- }
24
+ },
25
25
  );
26
26
  return providerHelper.getResponse(res);
27
27
  }
@@ -24,7 +24,7 @@ export type TabularClassificationOutput = number[];
24
24
  */
25
25
  export async function tabularClassification(
26
26
  args: TabularClassificationArgs,
27
- options?: Options
27
+ options?: Options,
28
28
  ): Promise<TabularClassificationOutput> {
29
29
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
30
30
  const providerHelper = getProviderHelper(provider, "tabular-classification");
@@ -24,7 +24,7 @@ export type TabularRegressionOutput = number[];
24
24
  */
25
25
  export async function tabularRegression(
26
26
  args: TabularRegressionArgs,
27
- options?: Options
27
+ options?: Options,
28
28
  ): Promise<TabularRegressionOutput> {
29
29
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
30
30
  const providerHelper = getProviderHelper(provider, "tabular-regression");
package/src/types.ts CHANGED
@@ -59,6 +59,7 @@ export const INFERENCE_PROVIDERS = [
59
59
  "nebius",
60
60
  "novita",
61
61
  "nscale",
62
+ "nvidia",
62
63
  "openai",
63
64
  "ovhcloud",
64
65
  "publicai",
@@ -96,6 +97,7 @@ export const PROVIDERS_HUB_ORGS: Record<InferenceProvider, string> = {
96
97
  nebius: "nebius",
97
98
  novita: "novita",
98
99
  nscale: "nscale",
100
+ nvidia: "nvidia",
99
101
  openai: "openai",
100
102
  ovhcloud: "ovhcloud",
101
103
  publicai: "publicai",
package/src/utils/pick.ts CHANGED
@@ -8,6 +8,6 @@ export function pick<T, K extends keyof T>(o: T, props: K[] | ReadonlyArray<K>):
8
8
  if (o[prop] !== undefined) {
9
9
  return { [prop]: o[prop] };
10
10
  }
11
- })
11
+ }),
12
12
  );
13
13
  }
@@ -42,7 +42,7 @@ export async function innerRequest<T>(
42
42
  task?: InferenceTask;
43
43
  /** Is chat completion compatible */
44
44
  chatCompletion?: boolean;
45
- }
45
+ },
46
46
  ): Promise<ResponseWrapper<T>> {
47
47
  const { url, info } = await makeRequestOptions(args, providerHelper, options);
48
48
  const response = await (options?.fetch ?? fetch)(url, info);
@@ -68,7 +68,7 @@ export async function innerRequest<T>(
68
68
  headers: info.headers as Record<string, string>,
69
69
  body: bodyToJson(info.body),
70
70
  },
71
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
71
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
72
72
  );
73
73
  }
74
74
  if (typeof output.error === "string" || typeof output.detail === "string" || typeof output.message === "string") {
@@ -80,7 +80,7 @@ export async function innerRequest<T>(
80
80
  headers: info.headers as Record<string, string>,
81
81
  body: bodyToJson(info.body),
82
82
  },
83
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
83
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
84
84
  );
85
85
  } else {
86
86
  throw new InferenceClientProviderApiError(
@@ -91,7 +91,7 @@ export async function innerRequest<T>(
91
91
  headers: info.headers as Record<string, string>,
92
92
  body: bodyToJson(info.body),
93
93
  },
94
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
94
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
95
95
  );
96
96
  }
97
97
  }
@@ -104,7 +104,7 @@ export async function innerRequest<T>(
104
104
  headers: info.headers as Record<string, string>,
105
105
  body: bodyToJson(info.body),
106
106
  },
107
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" }
107
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: message ?? "" },
108
108
  );
109
109
  }
110
110
 
@@ -128,7 +128,7 @@ export async function* innerStreamingRequest<T>(
128
128
  task?: InferenceTask;
129
129
  /** Is chat completion compatible */
130
130
  chatCompletion?: boolean;
131
- }
131
+ },
132
132
  ): AsyncGenerator<T> {
133
133
  const { url, info } = await makeRequestOptions({ ...args, stream: true }, providerHelper, options);
134
134
  const response = await (options?.fetch ?? fetch)(url, info);
@@ -150,7 +150,7 @@ export async function* innerStreamingRequest<T>(
150
150
  headers: info.headers as Record<string, string>,
151
151
  body: bodyToJson(info.body),
152
152
  },
153
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
153
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
154
154
  );
155
155
  }
156
156
  if (typeof output.error === "string") {
@@ -162,7 +162,7 @@ export async function* innerStreamingRequest<T>(
162
162
  headers: info.headers as Record<string, string>,
163
163
  body: bodyToJson(info.body),
164
164
  },
165
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
165
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
166
166
  );
167
167
  }
168
168
  if (output.error && "message" in output.error && typeof output.error.message === "string") {
@@ -175,7 +175,7 @@ export async function* innerStreamingRequest<T>(
175
175
  headers: info.headers as Record<string, string>,
176
176
  body: bodyToJson(info.body),
177
177
  },
178
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
178
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
179
179
  );
180
180
  }
181
181
  // Sambanova errors
@@ -188,7 +188,7 @@ export async function* innerStreamingRequest<T>(
188
188
  headers: info.headers as Record<string, string>,
189
189
  body: bodyToJson(info.body),
190
190
  },
191
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output }
191
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: output },
192
192
  );
193
193
  }
194
194
  }
@@ -201,7 +201,7 @@ export async function* innerStreamingRequest<T>(
201
201
  headers: info.headers as Record<string, string>,
202
202
  body: bodyToJson(info.body),
203
203
  },
204
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
204
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" },
205
205
  );
206
206
  }
207
207
  if (!response.headers.get("content-type")?.startsWith("text/event-stream")) {
@@ -214,7 +214,7 @@ export async function* innerStreamingRequest<T>(
214
214
  headers: info.headers as Record<string, string>,
215
215
  body: bodyToJson(info.body),
216
216
  },
217
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" }
217
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: "" },
218
218
  );
219
219
  }
220
220
 
@@ -234,8 +234,8 @@ export async function* innerStreamingRequest<T>(
234
234
  getMessages(
235
235
  () => {},
236
236
  () => {},
237
- onEvent
238
- )
237
+ onEvent,
238
+ ),
239
239
  );
240
240
 
241
241
  try {
@@ -256,11 +256,11 @@ export async function* innerStreamingRequest<T>(
256
256
  typeof data.error === "string"
257
257
  ? data.error
258
258
  : typeof data.error === "object" &&
259
- data.error &&
260
- "message" in data.error &&
261
- typeof data.error.message === "string"
262
- ? data.error.message
263
- : JSON.stringify(data.error);
259
+ data.error &&
260
+ "message" in data.error &&
261
+ typeof data.error.message === "string"
262
+ ? data.error.message
263
+ : JSON.stringify(data.error);
264
264
  throw new InferenceClientProviderApiError(
265
265
  `Failed to perform inference: an occurred while streaming the response: ${errorStr}`,
266
266
  {
@@ -269,7 +269,7 @@ export async function* innerStreamingRequest<T>(
269
269
  headers: info.headers as Record<string, string>,
270
270
  body: bodyToJson(info.body),
271
271
  },
272
- { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data }
272
+ { requestId: response.headers.get("x-request-id") ?? "", status: response.status, body: data },
273
273
  );
274
274
  }
275
275
  yield data as T;
@@ -1,5 +1,5 @@
1
1
  export function typedEntries<T extends { [s: string]: T[keyof T] } | ArrayLike<T[keyof T]>>(
2
- obj: T
2
+ obj: T,
3
3
  ): [keyof T, T[keyof T]][] {
4
4
  return Object.entries(obj) as [keyof T, T[keyof T]][];
5
5
  }