@huggingface/inference 4.3.1 → 4.4.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.
Files changed (71) hide show
  1. package/dist/commonjs/index.d.ts +1 -0
  2. package/dist/commonjs/index.d.ts.map +1 -1
  3. package/dist/commonjs/index.js +3 -1
  4. package/dist/commonjs/lib/getInferenceProviderMapping.d.ts.map +1 -1
  5. package/dist/commonjs/lib/getInferenceProviderMapping.js +8 -3
  6. package/dist/commonjs/lib/logger.d.ts +4 -0
  7. package/dist/commonjs/lib/logger.d.ts.map +1 -0
  8. package/dist/commonjs/lib/logger.js +11 -0
  9. package/dist/commonjs/package.d.ts +1 -1
  10. package/dist/commonjs/package.js +1 -1
  11. package/dist/commonjs/providers/black-forest-labs.d.ts.map +1 -1
  12. package/dist/commonjs/providers/black-forest-labs.js +3 -1
  13. package/dist/commonjs/providers/nebius.d.ts +2 -0
  14. package/dist/commonjs/providers/nebius.d.ts.map +1 -1
  15. package/dist/commonjs/providers/nebius.js +8 -0
  16. package/dist/commonjs/providers/sambanova.d.ts +2 -0
  17. package/dist/commonjs/providers/sambanova.d.ts.map +1 -1
  18. package/dist/commonjs/providers/sambanova.js +10 -0
  19. package/dist/commonjs/providers/together.d.ts +2 -0
  20. package/dist/commonjs/providers/together.d.ts.map +1 -1
  21. package/dist/commonjs/providers/together.js +11 -0
  22. package/dist/commonjs/snippets/getInferenceSnippets.d.ts.map +1 -1
  23. package/dist/commonjs/snippets/getInferenceSnippets.js +4 -2
  24. package/dist/commonjs/tasks/custom/request.d.ts.map +1 -1
  25. package/dist/commonjs/tasks/custom/request.js +3 -1
  26. package/dist/commonjs/tasks/custom/streamingRequest.d.ts.map +1 -1
  27. package/dist/commonjs/tasks/custom/streamingRequest.js +3 -1
  28. package/dist/commonjs/types.d.ts +7 -0
  29. package/dist/commonjs/types.d.ts.map +1 -1
  30. package/dist/esm/index.d.ts +1 -0
  31. package/dist/esm/index.d.ts.map +1 -1
  32. package/dist/esm/index.js +1 -0
  33. package/dist/esm/lib/getInferenceProviderMapping.d.ts.map +1 -1
  34. package/dist/esm/lib/getInferenceProviderMapping.js +8 -3
  35. package/dist/esm/lib/logger.d.ts +4 -0
  36. package/dist/esm/lib/logger.d.ts.map +1 -0
  37. package/dist/esm/lib/logger.js +7 -0
  38. package/dist/esm/package.d.ts +1 -1
  39. package/dist/esm/package.js +1 -1
  40. package/dist/esm/providers/black-forest-labs.d.ts.map +1 -1
  41. package/dist/esm/providers/black-forest-labs.js +3 -1
  42. package/dist/esm/providers/nebius.d.ts +2 -0
  43. package/dist/esm/providers/nebius.d.ts.map +1 -1
  44. package/dist/esm/providers/nebius.js +8 -0
  45. package/dist/esm/providers/sambanova.d.ts +2 -0
  46. package/dist/esm/providers/sambanova.d.ts.map +1 -1
  47. package/dist/esm/providers/sambanova.js +10 -0
  48. package/dist/esm/providers/together.d.ts +2 -0
  49. package/dist/esm/providers/together.d.ts.map +1 -1
  50. package/dist/esm/providers/together.js +11 -0
  51. package/dist/esm/snippets/getInferenceSnippets.d.ts.map +1 -1
  52. package/dist/esm/snippets/getInferenceSnippets.js +4 -2
  53. package/dist/esm/tasks/custom/request.d.ts.map +1 -1
  54. package/dist/esm/tasks/custom/request.js +3 -1
  55. package/dist/esm/tasks/custom/streamingRequest.d.ts.map +1 -1
  56. package/dist/esm/tasks/custom/streamingRequest.js +3 -1
  57. package/dist/esm/types.d.ts +7 -0
  58. package/dist/esm/types.d.ts.map +1 -1
  59. package/package.json +3 -3
  60. package/src/index.ts +1 -0
  61. package/src/lib/getInferenceProviderMapping.ts +18 -4
  62. package/src/lib/logger.ts +11 -0
  63. package/src/package.ts +1 -1
  64. package/src/providers/black-forest-labs.ts +3 -1
  65. package/src/providers/nebius.ts +12 -0
  66. package/src/providers/sambanova.ts +14 -0
  67. package/src/providers/together.ts +17 -0
  68. package/src/snippets/getInferenceSnippets.ts +4 -2
  69. package/src/tasks/custom/request.ts +3 -1
  70. package/src/tasks/custom/streamingRequest.ts +3 -1
  71. package/src/types.ts +8 -0
@@ -5,5 +5,6 @@ export * from "./tasks/index.js";
5
5
  import * as snippets from "./snippets/index.js";
6
6
  export * from "./lib/getProviderHelper.js";
7
7
  export * from "./lib/makeRequestOptions.js";
8
+ export { setLogger } from "./lib/logger.js";
8
9
  export { snippets };
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -36,7 +36,7 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.snippets = exports.HfInference = exports.InferenceClientEndpoint = exports.InferenceClient = void 0;
39
+ exports.snippets = exports.setLogger = exports.HfInference = exports.InferenceClientEndpoint = exports.InferenceClient = void 0;
40
40
  var InferenceClient_js_1 = require("./InferenceClient.js");
41
41
  Object.defineProperty(exports, "InferenceClient", { enumerable: true, get: function () { return InferenceClient_js_1.InferenceClient; } });
42
42
  Object.defineProperty(exports, "InferenceClientEndpoint", { enumerable: true, get: function () { return InferenceClient_js_1.InferenceClientEndpoint; } });
@@ -48,3 +48,5 @@ const snippets = __importStar(require("./snippets/index.js"));
48
48
  exports.snippets = snippets;
49
49
  __exportStar(require("./lib/getProviderHelper.js"), exports);
50
50
  __exportStar(require("./lib/makeRequestOptions.js"), exports);
51
+ var logger_js_1 = require("./lib/logger.js");
52
+ Object.defineProperty(exports, "setLogger", { enumerable: true, get: function () { return logger_js_1.setLogger; } });
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AAiCjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CACjB,EACD,OAAO,EAAE;IACR,KAAK,CAA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,CAyB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CA2B5B"}
@@ -9,6 +9,7 @@ const consts_js_1 = require("../providers/consts.js");
9
9
  const hf_inference_js_1 = require("../providers/hf-inference.js");
10
10
  const typedInclude_js_1 = require("../utils/typedInclude.js");
11
11
  const errors_js_1 = require("../errors.js");
12
+ const logger_js_1 = require("./logger.js");
12
13
  exports.inferenceProviderMappingCache = new Map();
13
14
  /**
14
15
  * Normalize inferenceProviderMapping to always return an array format.
@@ -31,6 +32,8 @@ function normalizeInferenceProviderMapping(modelId, inferenceProviderMapping) {
31
32
  providerId: mapping.providerId,
32
33
  status: mapping.status,
33
34
  task: mapping.task,
35
+ adapter: mapping.adapter,
36
+ adapterWeightsPath: mapping.adapterWeightsPath,
34
37
  }));
35
38
  }
36
39
  async function fetchInferenceProviderMappingForModel(modelId, accessToken, options) {
@@ -71,6 +74,7 @@ async function fetchInferenceProviderMappingForModel(modelId, accessToken, optio
71
74
  return inferenceProviderMapping;
72
75
  }
73
76
  async function getInferenceProviderMapping(params, options) {
77
+ const logger = (0, logger_js_1.getLogger)();
74
78
  if (consts_js_1.HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId]) {
75
79
  return consts_js_1.HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId];
76
80
  }
@@ -84,13 +88,14 @@ async function getInferenceProviderMapping(params, options) {
84
88
  throw new errors_js_1.InferenceClientInputError(`Model ${params.modelId} is not supported for task ${params.task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`);
85
89
  }
86
90
  if (providerMapping.status === "staging") {
87
- console.warn(`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`);
91
+ logger.warn(`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`);
88
92
  }
89
93
  return providerMapping;
90
94
  }
91
95
  return null;
92
96
  }
93
97
  async function resolveProvider(provider, modelId, endpointUrl) {
98
+ const logger = (0, logger_js_1.getLogger)();
94
99
  if (endpointUrl) {
95
100
  if (provider) {
96
101
  throw new errors_js_1.InferenceClientInputError("Specifying both endpointUrl and provider is not supported.");
@@ -99,7 +104,7 @@ async function resolveProvider(provider, modelId, endpointUrl) {
99
104
  return "hf-inference";
100
105
  }
101
106
  if (!provider) {
102
- console.log("Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.");
107
+ logger.log("Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.");
103
108
  provider = "auto";
104
109
  }
105
110
  if (provider === "auto") {
@@ -108,7 +113,7 @@ async function resolveProvider(provider, modelId, endpointUrl) {
108
113
  }
109
114
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
110
115
  provider = mappings[0]?.provider;
111
- console.log("Auto selected provider:", provider);
116
+ logger.log("Auto selected provider:", provider);
112
117
  }
113
118
  if (!provider) {
114
119
  throw new errors_js_1.InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
@@ -0,0 +1,4 @@
1
+ import type { Logger } from "../types.js";
2
+ export declare function setLogger(logger: Logger): void;
3
+ export declare function getLogger(): Logger;
4
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setLogger = setLogger;
4
+ exports.getLogger = getLogger;
5
+ let globalLogger = console;
6
+ function setLogger(logger) {
7
+ globalLogger = logger;
8
+ }
9
+ function getLogger() {
10
+ return globalLogger;
11
+ }
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "4.3.1";
1
+ export declare const PACKAGE_VERSION = "4.4.0";
2
2
  export declare const PACKAGE_NAME = "@huggingface/inference";
3
3
  //# sourceMappingURL=package.d.ts.map
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
4
4
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
5
- exports.PACKAGE_VERSION = "4.3.1";
5
+ exports.PACKAGE_VERSION = "4.4.0";
6
6
  exports.PACKAGE_NAME = "@huggingface/inference";
@@ -1 +1 @@
1
- {"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGrF,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,qBAAqB;;IAKtG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQlD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWtF,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAO9B,WAAW,CAChB,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAsCzB"}
1
+ {"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGrF,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,qBAAqB;;IAKtG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQlD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWtF,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAO9B,WAAW,CAChB,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAuCzB"}
@@ -18,6 +18,7 @@ exports.BlackForestLabsTextToImageTask = void 0;
18
18
  * Thanks!
19
19
  */
20
20
  const errors_js_1 = require("../errors.js");
21
+ const logger_js_1 = require("../lib/logger.js");
21
22
  const delay_js_1 = require("../utils/delay.js");
22
23
  const omit_js_1 = require("../utils/omit.js");
23
24
  const providerHelper_js_1 = require("./providerHelper.js");
@@ -49,10 +50,11 @@ class BlackForestLabsTextToImageTask extends providerHelper_js_1.TaskProviderHel
49
50
  return `/v1/${params.model}`;
50
51
  }
51
52
  async getResponse(response, url, headers, outputType) {
53
+ const logger = (0, logger_js_1.getLogger)();
52
54
  const urlObj = new URL(response.polling_url);
53
55
  for (let step = 0; step < 5; step++) {
54
56
  await (0, delay_js_1.delay)(1000);
55
- console.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
57
+ logger.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
56
58
  urlObj.searchParams.set("attempt", step.toString(10));
57
59
  const resp = await fetch(urlObj, { headers: { "Content-Type": "application/json" } });
58
60
  if (!resp.ok) {
@@ -17,6 +17,7 @@
17
17
  import type { FeatureExtractionOutput, TextGenerationOutput } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import { BaseConversationalTask, BaseTextGenerationTask, TaskProviderHelper, type FeatureExtractionTaskHelper, type TextToImageTaskHelper } from "./providerHelper.js";
20
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
20
21
  interface NebiusBase64ImageGeneration {
21
22
  data: Array<{
22
23
  b64_json: string;
@@ -34,6 +35,7 @@ interface NebiusTextGenerationOutput extends Omit<TextGenerationOutput, "choices
34
35
  }
35
36
  export declare class NebiusConversationalTask extends BaseConversationalTask {
36
37
  constructor();
38
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
37
39
  }
38
40
  export declare class NebiusTextGenerationTask extends BaseTextGenerationTask {
39
41
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"nebius.d.ts","sourceRoot":"","sources":["../../../src/providers/nebius.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAK7B,UAAU,2BAA2B;IAC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BAA2B,EACrC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkBzB;AAED,qBAAa,2BAA4B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKzG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAO3D,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC;CAGvF"}
@@ -9,6 +9,14 @@ class NebiusConversationalTask extends providerHelper_js_1.BaseConversationalTas
9
9
  constructor() {
10
10
  super("nebius", NEBIUS_API_BASE_URL);
11
11
  }
12
+ preparePayload(params) {
13
+ const payload = super.preparePayload(params);
14
+ const responseFormat = params.args.response_format;
15
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema?.schema) {
16
+ payload["guided_json"] = responseFormat.json_schema.schema;
17
+ }
18
+ return payload;
19
+ }
12
20
  }
13
21
  exports.NebiusConversationalTask = NebiusConversationalTask;
14
22
  class NebiusTextGenerationTask extends providerHelper_js_1.BaseTextGenerationTask {
@@ -18,8 +18,10 @@ import type { FeatureExtractionOutput } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
20
20
  import { BaseConversationalTask, TaskProviderHelper } from "./providerHelper.js";
21
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
21
22
  export declare class SambanovaConversationalTask extends BaseConversationalTask {
22
23
  constructor();
24
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
23
25
  }
24
26
  export declare class SambanovaFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
25
27
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,qBAAa,2BAA4B,SAAQ,sBAAsB;;CAItE;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKnG,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAStF,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpE"}
1
+ {"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAEjF,qBAAa,2BAA4B,SAAQ,sBAAsB;;IAK7D,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAYzF;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKnG,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAStF,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpE"}
@@ -7,6 +7,16 @@ class SambanovaConversationalTask extends providerHelper_js_1.BaseConversational
7
7
  constructor() {
8
8
  super("sambanova", "https://api.sambanova.ai");
9
9
  }
10
+ preparePayload(params) {
11
+ const responseFormat = params.args.response_format;
12
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema) {
13
+ if (responseFormat.json_schema.strict ?? true) {
14
+ responseFormat.json_schema.strict = false;
15
+ }
16
+ }
17
+ const payload = super.preparePayload(params);
18
+ return payload;
19
+ }
10
20
  }
11
21
  exports.SambanovaConversationalTask = SambanovaConversationalTask;
12
22
  class SambanovaFeatureExtractionTask extends providerHelper_js_1.TaskProviderHelper {
@@ -17,6 +17,7 @@
17
17
  import type { ChatCompletionOutput, TextGenerationOutput, TextGenerationOutputFinishReason } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import { BaseConversationalTask, BaseTextGenerationTask, TaskProviderHelper, type TextToImageTaskHelper } from "./providerHelper.js";
20
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
20
21
  interface TogetherTextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
21
22
  choices: Array<{
22
23
  text: string;
@@ -33,6 +34,7 @@ interface TogetherBase64ImageGeneration {
33
34
  }
34
35
  export declare class TogetherConversationalTask extends BaseConversationalTask {
35
36
  constructor();
37
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
36
38
  }
37
39
  export declare class TogetherTextGenerationTask extends BaseTextGenerationTask {
38
40
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../../src/providers/together.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,oBAAoB,EA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MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkB/G"}
@@ -9,6 +9,17 @@ class TogetherConversationalTask extends providerHelper_js_1.BaseConversationalT
9
9
  constructor() {
10
10
  super("together", TOGETHER_API_BASE_URL);
11
11
  }
12
+ preparePayload(params) {
13
+ const payload = super.preparePayload(params);
14
+ const response_format = payload.response_format;
15
+ if (response_format?.type === "json_schema" && response_format?.json_schema?.schema) {
16
+ payload.response_format = {
17
+ type: "json_schema",
18
+ schema: response_format.json_schema.schema,
19
+ };
20
+ }
21
+ return payload;
22
+ }
12
23
  }
13
24
  exports.TogetherConversationalTask = TogetherConversationalTask;
14
25
  class TogetherTextGenerationTask extends providerHelper_js_1.BaseTextGenerationTask {
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceSnippets.d.ts","sourceRoot":"","sources":["../../../src/snippets/getInferenceSnippets.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAGxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA2V5B,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,yBAAyB,EACnC,wBAAwB,CAAC,EAAE,6BAA6B,EACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CAIpB"}
1
+ {"version":3,"file":"getInferenceSnippets.d.ts","sourceRoot":"","sources":["../../../src/snippets/getInferenceSnippets.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,KAAK,EAAE,6BAA6B,EAAE,yBAAyB,EAA8B,MAAM,aAAa,CAAC;AAIxH,MAAM,MAAM,uBAAuB,GAAG;IACrC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AA4V5B,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,gBAAgB,EACvB,QAAQ,EAAE,yBAAyB,EACnC,wBAAwB,CAAC,EAAE,6BAA6B,EACxD,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,gBAAgB,EAAE,CAIpB"}
@@ -6,6 +6,7 @@ const tasks_1 = require("@huggingface/tasks");
6
6
  const getProviderHelper_js_1 = require("../lib/getProviderHelper.js");
7
7
  const makeRequestOptions_js_1 = require("../lib/makeRequestOptions.js");
8
8
  const templates_exported_js_1 = require("./templates.exported.js");
9
+ const logger_js_1 = require("../lib/logger.js");
9
10
  const PYTHON_CLIENTS = ["huggingface_hub", "fal_client", "requests", "openai"];
10
11
  const JS_CLIENTS = ["fetch", "huggingface.js", "openai"];
11
12
  const SH_CLIENTS = ["curl"];
@@ -83,6 +84,7 @@ const ACCESS_TOKEN_DIRECT_REQUEST_PLACEHOLDER = "not_hf_token_placeholder";
83
84
  // Snippet generators
84
85
  const snippetGenerator = (templateName, inputPreparationFn) => {
85
86
  return (model, provider, inferenceProviderMapping, opts) => {
87
+ const logger = (0, logger_js_1.getLogger)();
86
88
  const providerModelId = inferenceProviderMapping?.providerId ?? model.id;
87
89
  /// Hacky: hard-code conversational templates here
88
90
  let task = model.pipeline_tag;
@@ -98,7 +100,7 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
98
100
  providerHelper = (0, getProviderHelper_js_1.getProviderHelper)(provider, task);
99
101
  }
100
102
  catch (e) {
101
- console.error(`Failed to get provider helper for ${provider} (${task})`, e);
103
+ logger.error(`Failed to get provider helper for ${provider} (${task})`, e);
102
104
  return [];
103
105
  }
104
106
  const placeholder = opts?.directRequest
@@ -125,7 +127,7 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
125
127
  providerInputs = JSON.parse(bodyAsObj);
126
128
  }
127
129
  catch (e) {
128
- console.error("Failed to parse body as JSON", e);
130
+ logger.error("Failed to parse body as JSON", e);
129
131
  }
130
132
  }
131
133
  /// Prepare template injection data
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,OAAO,CAAC,CAAC,CAAC,CAQZ"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1E;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,OAAO,CAAC,CAAC,CAAC,CASZ"}
@@ -4,12 +4,14 @@ exports.request = request;
4
4
  const getInferenceProviderMapping_js_1 = require("../../lib/getInferenceProviderMapping.js");
5
5
  const getProviderHelper_js_1 = require("../../lib/getProviderHelper.js");
6
6
  const request_js_1 = require("../../utils/request.js");
7
+ const logger_js_1 = require("../../lib/logger.js");
7
8
  /**
8
9
  * Primitive to make custom calls to the inference provider
9
10
  * @deprecated Use specific task functions instead. This function will be removed in a future version.
10
11
  */
11
12
  async function request(args, options) {
12
- console.warn("The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
13
+ const logger = (0, logger_js_1.getLogger)();
14
+ logger.warn("The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
13
15
  const provider = await (0, getInferenceProviderMapping_js_1.resolveProvider)(args.provider, args.model, args.endpointUrl);
14
16
  const providerHelper = (0, getProviderHelper_js_1.getProviderHelper)(provider, options?.task);
15
17
  const result = await (0, request_js_1.innerRequest)(args, providerHelper, options);
@@ -1 +1 @@
1
- {"version":3,"file":"streamingRequest.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/streamingRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;GAGG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EACxC,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,cAAc,CAAC,CAAC,CAAC,CAOnB"}
1
+ {"version":3,"file":"streamingRequest.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/streamingRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1E;;;GAGG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EACxC,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,cAAc,CAAC,CAAC,CAAC,CAQnB"}
@@ -4,12 +4,14 @@ exports.streamingRequest = streamingRequest;
4
4
  const getInferenceProviderMapping_js_1 = require("../../lib/getInferenceProviderMapping.js");
5
5
  const getProviderHelper_js_1 = require("../../lib/getProviderHelper.js");
6
6
  const request_js_1 = require("../../utils/request.js");
7
+ const logger_js_1 = require("../../lib/logger.js");
7
8
  /**
8
9
  * Primitive to make custom inference calls that expect server-sent events, and returns the response through a generator
9
10
  * @deprecated Use specific task functions instead. This function will be removed in a future version.
10
11
  */
11
12
  async function* streamingRequest(args, options) {
12
- console.warn("The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
13
+ const logger = (0, logger_js_1.getLogger)();
14
+ logger.warn("The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
13
15
  const provider = await (0, getInferenceProviderMapping_js_1.resolveProvider)(args.provider, args.model, args.endpointUrl);
14
16
  const providerHelper = (0, getProviderHelper_js_1.getProviderHelper)(provider, options?.task);
15
17
  yield* (0, request_js_1.innerStreamingRequest)(args, providerHelper, options);
@@ -3,6 +3,13 @@ import type { ChatCompletionInput, PipelineType, WidgetType } from "@huggingface
3
3
  * HF model id, like "meta-llama/Llama-3.3-70B-Instruct"
4
4
  */
5
5
  export type ModelId = string;
6
+ export interface Logger {
7
+ debug: (message: string, ...args: unknown[]) => void;
8
+ info: (message: string, ...args: unknown[]) => void;
9
+ warn: (message: string, ...args: unknown[]) => void;
10
+ error: (message: string, ...args: unknown[]) => void;
11
+ log: (message: string, ...args: unknown[]) => void;
12
+ }
6
13
  export interface Options {
7
14
  /**
8
15
  * (Default: true) Boolean. If a request 503s, the request will be retried with the same parameters.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAA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E,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;IACpD,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
@@ -5,5 +5,6 @@ export * from "./tasks/index.js";
5
5
  import * as snippets from "./snippets/index.js";
6
6
  export * from "./lib/getProviderHelper.js";
7
7
  export * from "./lib/makeRequestOptions.js";
8
+ export { setLogger } from "./lib/logger.js";
8
9
  export { snippets };
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7F,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,CAAC"}
package/dist/esm/index.js CHANGED
@@ -5,4 +5,5 @@ export * from "./tasks/index.js";
5
5
  import * as snippets from "./snippets/index.js";
6
6
  export * from "./lib/getProviderHelper.js";
7
7
  export * from "./lib/makeRequestOptions.js";
8
+ export { setLogger } from "./lib/logger.js";
8
9
  export { snippets };
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAIxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AAiCjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CACjB,EACD,OAAO,EAAE;IACR,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAwB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CA0B5B"}
1
+ {"version":3,"file":"getInferenceProviderMapping.d.ts","sourceRoot":"","sources":["../../../src/lib/getInferenceProviderMapping.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAKxH,eAAO,MAAM,6BAA6B,8CAAsD,CAAC;AA4CjG,wBAAsB,qCAAqC,CAC1D,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE;IACT,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,EAAE,CAAC,CAqD1C;AAED,wBAAsB,2BAA2B,CAChD,MAAM,EAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,IAAI,EAAE,UAAU,CAAC;CACjB,EACD,OAAO,EAAE;IACR,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtE,GACC,OAAO,CAAC,6BAA6B,GAAG,IAAI,CAAC,CAyB/C;AAED,wBAAsB,eAAe,CACpC,QAAQ,CAAC,EAAE,yBAAyB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,iBAAiB,CAAC,CA2B5B"}
@@ -3,6 +3,7 @@ import { HARDCODED_MODEL_INFERENCE_MAPPING } from "../providers/consts.js";
3
3
  import { EQUIVALENT_SENTENCE_TRANSFORMERS_TASKS } from "../providers/hf-inference.js";
4
4
  import { typedInclude } from "../utils/typedInclude.js";
5
5
  import { InferenceClientHubApiError, InferenceClientInputError } from "../errors.js";
6
+ import { getLogger } from "./logger.js";
6
7
  export const inferenceProviderMappingCache = new Map();
7
8
  /**
8
9
  * Normalize inferenceProviderMapping to always return an array format.
@@ -25,6 +26,8 @@ function normalizeInferenceProviderMapping(modelId, inferenceProviderMapping) {
25
26
  providerId: mapping.providerId,
26
27
  status: mapping.status,
27
28
  task: mapping.task,
29
+ adapter: mapping.adapter,
30
+ adapterWeightsPath: mapping.adapterWeightsPath,
28
31
  }));
29
32
  }
30
33
  export async function fetchInferenceProviderMappingForModel(modelId, accessToken, options) {
@@ -65,6 +68,7 @@ export async function fetchInferenceProviderMappingForModel(modelId, accessToken
65
68
  return inferenceProviderMapping;
66
69
  }
67
70
  export async function getInferenceProviderMapping(params, options) {
71
+ const logger = getLogger();
68
72
  if (HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId]) {
69
73
  return HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId];
70
74
  }
@@ -78,13 +82,14 @@ export async function getInferenceProviderMapping(params, options) {
78
82
  throw new InferenceClientInputError(`Model ${params.modelId} is not supported for task ${params.task} and provider ${params.provider}. Supported task: ${providerMapping.task}.`);
79
83
  }
80
84
  if (providerMapping.status === "staging") {
81
- console.warn(`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`);
85
+ logger.warn(`Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`);
82
86
  }
83
87
  return providerMapping;
84
88
  }
85
89
  return null;
86
90
  }
87
91
  export async function resolveProvider(provider, modelId, endpointUrl) {
92
+ const logger = getLogger();
88
93
  if (endpointUrl) {
89
94
  if (provider) {
90
95
  throw new InferenceClientInputError("Specifying both endpointUrl and provider is not supported.");
@@ -93,7 +98,7 @@ export async function resolveProvider(provider, modelId, endpointUrl) {
93
98
  return "hf-inference";
94
99
  }
95
100
  if (!provider) {
96
- console.log("Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.");
101
+ logger.log("Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers.");
97
102
  provider = "auto";
98
103
  }
99
104
  if (provider === "auto") {
@@ -102,7 +107,7 @@ export async function resolveProvider(provider, modelId, endpointUrl) {
102
107
  }
103
108
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
104
109
  provider = mappings[0]?.provider;
105
- console.log("Auto selected provider:", provider);
110
+ logger.log("Auto selected provider:", provider);
106
111
  }
107
112
  if (!provider) {
108
113
  throw new InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
@@ -0,0 +1,4 @@
1
+ import type { Logger } from "../types.js";
2
+ export declare function setLogger(logger: Logger): void;
3
+ export declare function getLogger(): Logger;
4
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED,wBAAgB,SAAS,IAAI,MAAM,CAElC"}
@@ -0,0 +1,7 @@
1
+ let globalLogger = console;
2
+ export function setLogger(logger) {
3
+ globalLogger = logger;
4
+ }
5
+ export function getLogger() {
6
+ return globalLogger;
7
+ }
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "4.3.1";
1
+ export declare const PACKAGE_VERSION = "4.4.0";
2
2
  export declare const PACKAGE_NAME = "@huggingface/inference";
3
3
  //# sourceMappingURL=package.d.ts.map
@@ -1,3 +1,3 @@
1
1
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
2
- export const PACKAGE_VERSION = "4.3.1";
2
+ export const PACKAGE_VERSION = "4.4.0";
3
3
  export const PACKAGE_NAME = "@huggingface/inference";
@@ -1 +1 @@
1
- {"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGrF,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,qBAAqB;;IAKtG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQlD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWtF,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAO9B,WAAW,CAChB,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAsCzB"}
1
+ {"version":3,"file":"black-forest-labs.d.ts","sourceRoot":"","sources":["../../../src/providers/black-forest-labs.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGvE,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGrF,UAAU,uBAAuB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,qBAAqB;;IAKtG,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQlD,cAAc,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAWtF,SAAS,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAO9B,WAAW,CAChB,QAAQ,EAAE,uBAAuB,EACjC,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GACzB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAuCzB"}
@@ -15,6 +15,7 @@
15
15
  * Thanks!
16
16
  */
17
17
  import { InferenceClientInputError, InferenceClientProviderApiError, InferenceClientProviderOutputError, } from "../errors.js";
18
+ import { getLogger } from "../lib/logger.js";
18
19
  import { delay } from "../utils/delay.js";
19
20
  import { omit } from "../utils/omit.js";
20
21
  import { TaskProviderHelper } from "./providerHelper.js";
@@ -46,10 +47,11 @@ export class BlackForestLabsTextToImageTask extends TaskProviderHelper {
46
47
  return `/v1/${params.model}`;
47
48
  }
48
49
  async getResponse(response, url, headers, outputType) {
50
+ const logger = getLogger();
49
51
  const urlObj = new URL(response.polling_url);
50
52
  for (let step = 0; step < 5; step++) {
51
53
  await delay(1000);
52
- console.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
54
+ logger.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
53
55
  urlObj.searchParams.set("attempt", step.toString(10));
54
56
  const resp = await fetch(urlObj, { headers: { "Content-Type": "application/json" } });
55
57
  if (!resp.ok) {
@@ -17,6 +17,7 @@
17
17
  import type { FeatureExtractionOutput, TextGenerationOutput } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import { BaseConversationalTask, BaseTextGenerationTask, TaskProviderHelper, type FeatureExtractionTaskHelper, type TextToImageTaskHelper } from "./providerHelper.js";
20
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
20
21
  interface NebiusBase64ImageGeneration {
21
22
  data: Array<{
22
23
  b64_json: string;
@@ -34,6 +35,7 @@ interface NebiusTextGenerationOutput extends Omit<TextGenerationOutput, "choices
34
35
  }
35
36
  export declare class NebiusConversationalTask extends BaseConversationalTask {
36
37
  constructor();
38
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
37
39
  }
38
40
  export declare class NebiusTextGenerationTask extends BaseTextGenerationTask {
39
41
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"nebius.d.ts","sourceRoot":"","sources":["../../../src/providers/nebius.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAK7B,UAAU,2BAA2B;IACpC,IAAI,EAAE,KAAK,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACH;AAED,UAAU,wBAAwB;IACjC,IAAI,EAAE,KAAK,CAAC;QACX,SAAS,EAAE,MAAM,EAAE,CAAC;KACpB,CAAC,CAAC;CACH;AAED,UAAU,0BAA2B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IACjF,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACb,CAAC,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,sBAAsB;;CAInE;AAED,qBAAa,wBAAyB,SAAQ,sBAAsB;;IAK1D,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQrD,WAAW,CAAC,QAAQ,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10
+ const payload = super.preparePayload(params);
11
+ const responseFormat = params.args.response_format;
12
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema?.schema) {
13
+ payload["guided_json"] = responseFormat.json_schema.schema;
14
+ }
15
+ return payload;
16
+ }
9
17
  }
10
18
  export class NebiusTextGenerationTask extends BaseTextGenerationTask {
11
19
  constructor() {
@@ -18,8 +18,10 @@ import type { FeatureExtractionOutput } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
20
20
  import { BaseConversationalTask, TaskProviderHelper } from "./providerHelper.js";
21
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
21
22
  export declare class SambanovaConversationalTask extends BaseConversationalTask {
22
23
  constructor();
24
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
23
25
  }
24
26
  export declare class SambanovaFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
25
27
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,qBAAa,2BAA4B,SAAQ,sBAAsB;;CAItE;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKnG,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAStF,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpE"}
1
+ {"version":3,"file":"sambanova.d.ts","sourceRoot":"","sources":["../../../src/providers/sambanova.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AAEjF,qBAAa,2BAA4B,SAAQ,sBAAsB;;IAK7D,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAYzF;AAED,qBAAa,8BAA+B,SAAQ,kBAAmB,YAAW,2BAA2B;;IAKnG,SAAS,IAAI,MAAM;IAIb,WAAW,CAAC,QAAQ,EAAE,uBAAuB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IAStF,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAOpE"}
@@ -4,6 +4,16 @@ export class SambanovaConversationalTask extends BaseConversationalTask {
4
4
  constructor() {
5
5
  super("sambanova", "https://api.sambanova.ai");
6
6
  }
7
+ preparePayload(params) {
8
+ const responseFormat = params.args.response_format;
9
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema) {
10
+ if (responseFormat.json_schema.strict ?? true) {
11
+ responseFormat.json_schema.strict = false;
12
+ }
13
+ }
14
+ const payload = super.preparePayload(params);
15
+ return payload;
16
+ }
7
17
  }
8
18
  export class SambanovaFeatureExtractionTask extends TaskProviderHelper {
9
19
  constructor() {
@@ -17,6 +17,7 @@
17
17
  import type { ChatCompletionOutput, TextGenerationOutput, TextGenerationOutputFinishReason } from "@huggingface/tasks";
18
18
  import type { BodyParams } from "../types.js";
19
19
  import { BaseConversationalTask, BaseTextGenerationTask, TaskProviderHelper, type TextToImageTaskHelper } from "./providerHelper.js";
20
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
20
21
  interface TogetherTextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
21
22
  choices: Array<{
22
23
  text: string;
@@ -33,6 +34,7 @@ interface TogetherBase64ImageGeneration {
33
34
  }
34
35
  export declare class TogetherConversationalTask extends BaseConversationalTask {
35
36
  constructor();
37
+ preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown>;
36
38
  }
37
39
  export declare class TogetherTextGenerationTask extends BaseTextGenerationTask {
38
40
  constructor();
@@ -1 +1 @@
1
- {"version":3,"file":"together.d.ts","sourceRoot":"","sources":["../../../src/providers/together.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACvH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EACN,sBAAsB,EACtB,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,MAAM,qBAAqB,CAAC;AAK7B,UAAU,4BAA6B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,CAAC;IACnF,OAAO,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,aAAa,EAAE,gCAAgC,CAAC;QAChD,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,OAAO,CAAC;QAClB,KAAK,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;CACH;AAED,UAAU,6BAA6B;IACtC,IAAI,EAAE,KAAK,CAAC;QACX,QAAQ,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACH;AAED,qBAAa,0BAA2B,SAAQ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ACX,QAAQ,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACH;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;IAK5D,cAAc,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAezF;AAED,qBAAa,0BAA2B,SAAQ,sBAAsB;;IAK5D,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAQrD,WAAW,CAAC,QAAQ,EAAE,4BAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAcjG;AAED,qBAAa,uBAAwB,SAAQ,kBAAmB,YAAW,qBAAqB;;IAK/F,SAAS,IAAI,MAAM;IAInB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAUrD,WAAW,CAAC,QAAQ,EAAE,6BAA6B,EAAE,UAAU,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAkB/G"}
@@ -6,6 +6,17 @@ export class TogetherConversationalTask extends BaseConversationalTask {
6
6
  constructor() {
7
7
  super("together", TOGETHER_API_BASE_URL);
8
8
  }
9
+ preparePayload(params) {
10
+ const payload = super.preparePayload(params);
11
+ const response_format = payload.response_format;
12
+ if (response_format?.type === "json_schema" && response_format?.json_schema?.schema) {
13
+ payload.response_format = {
14
+ type: "json_schema",
15
+ schema: response_format.json_schema.schema,
16
+ };
17
+ }
18
+ return payload;
19
+ }
9
20
  }
10
21
  export class TogetherTextGenerationTask extends BaseTextGenerationTask {
11
22
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"file":"getInferenceSnippets.d.ts","sourceRoot":"","sources":["../../../src/snippets/getInferenceSnippets.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,gBAAgB,EAErB,KAAK,gBAAgB,EAGrB,MAAM,oBAAoB,CAAC;AAK5B,OA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BAAgB,EAAE,CAIpB"}
@@ -3,6 +3,7 @@ import { getModelInputSnippet, inferenceSnippetLanguages, } from "@huggingface/t
3
3
  import { getProviderHelper } from "../lib/getProviderHelper.js";
4
4
  import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions.js";
5
5
  import { templates } from "./templates.exported.js";
6
+ import { getLogger } from "../lib/logger.js";
6
7
  const PYTHON_CLIENTS = ["huggingface_hub", "fal_client", "requests", "openai"];
7
8
  const JS_CLIENTS = ["fetch", "huggingface.js", "openai"];
8
9
  const SH_CLIENTS = ["curl"];
@@ -80,6 +81,7 @@ const ACCESS_TOKEN_DIRECT_REQUEST_PLACEHOLDER = "not_hf_token_placeholder";
80
81
  // Snippet generators
81
82
  const snippetGenerator = (templateName, inputPreparationFn) => {
82
83
  return (model, provider, inferenceProviderMapping, opts) => {
84
+ const logger = getLogger();
83
85
  const providerModelId = inferenceProviderMapping?.providerId ?? model.id;
84
86
  /// Hacky: hard-code conversational templates here
85
87
  let task = model.pipeline_tag;
@@ -95,7 +97,7 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
95
97
  providerHelper = getProviderHelper(provider, task);
96
98
  }
97
99
  catch (e) {
98
- console.error(`Failed to get provider helper for ${provider} (${task})`, e);
100
+ logger.error(`Failed to get provider helper for ${provider} (${task})`, e);
99
101
  return [];
100
102
  }
101
103
  const placeholder = opts?.directRequest
@@ -122,7 +124,7 @@ const snippetGenerator = (templateName, inputPreparationFn) => {
122
124
  providerInputs = JSON.parse(bodyAsObj);
123
125
  }
124
126
  catch (e) {
125
- console.error("Failed to parse body as JSON", e);
127
+ logger.error("Failed to parse body as JSON", e);
126
128
  }
127
129
  }
128
130
  /// Prepare template injection data
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,OAAO,CAAC,CAAC,CAAC,CAQZ"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/request.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1E;;;GAGG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC9B,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,OAAO,CAAC,CAAC,CAAC,CASZ"}
@@ -1,12 +1,14 @@
1
1
  import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
2
2
  import { getProviderHelper } from "../../lib/getProviderHelper.js";
3
3
  import { innerRequest } from "../../utils/request.js";
4
+ import { getLogger } from "../../lib/logger.js";
4
5
  /**
5
6
  * Primitive to make custom calls to the inference provider
6
7
  * @deprecated Use specific task functions instead. This function will be removed in a future version.
7
8
  */
8
9
  export async function request(args, options) {
9
- console.warn("The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
10
+ const logger = getLogger();
11
+ logger.warn("The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
10
12
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
11
13
  const providerHelper = getProviderHelper(provider, options?.task);
12
14
  const result = await innerRequest(args, providerHelper, options);
@@ -1 +1 @@
1
- {"version":3,"file":"streamingRequest.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/streamingRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG1E;;;GAGG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EACxC,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,cAAc,CAAC,CAAC,CAAC,CAOnB"}
1
+ {"version":3,"file":"streamingRequest.d.ts","sourceRoot":"","sources":["../../../../src/tasks/custom/streamingRequest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI1E;;;GAGG;AACH,wBAAuB,gBAAgB,CAAC,CAAC,EACxC,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,OAAO,GAAG;IACnB,oEAAoE;IACpE,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB,GACC,cAAc,CAAC,CAAC,CAAC,CAQnB"}
@@ -1,12 +1,14 @@
1
1
  import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
2
2
  import { getProviderHelper } from "../../lib/getProviderHelper.js";
3
3
  import { innerStreamingRequest } from "../../utils/request.js";
4
+ import { getLogger } from "../../lib/logger.js";
4
5
  /**
5
6
  * Primitive to make custom inference calls that expect server-sent events, and returns the response through a generator
6
7
  * @deprecated Use specific task functions instead. This function will be removed in a future version.
7
8
  */
8
9
  export async function* streamingRequest(args, options) {
9
- console.warn("The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
10
+ const logger = getLogger();
11
+ logger.warn("The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead.");
10
12
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
11
13
  const providerHelper = getProviderHelper(provider, options?.task);
12
14
  yield* innerStreamingRequest(args, providerHelper, options);
@@ -3,6 +3,13 @@ import type { ChatCompletionInput, PipelineType, WidgetType } from "@huggingface
3
3
  * HF model id, like "meta-llama/Llama-3.3-70B-Instruct"
4
4
  */
5
5
  export type ModelId = string;
6
+ export interface Logger {
7
+ debug: (message: string, ...args: unknown[]) => void;
8
+ info: (message: string, ...args: unknown[]) => void;
9
+ warn: (message: string, ...args: unknown[]) => void;
10
+ error: (message: string, ...args: unknown[]) => void;
11
+ log: (message: string, ...args: unknown[]) => void;
12
+ }
6
13
  export interface Options {
7
14
  /**
8
15
  * (Default: true) Boolean. If a request 503s, the request will be retried with the same parameters.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAExF;;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;IAEtC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,gBAAgB,CAAC;AAE9E,eAAO,MAAM,mBAAmB,kOAkBtB,CAAC;AAEX,eAAO,MAAM,qBAAqB,0OAA4C,CAAC;AAE/E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/E,MAAM,WAAW,6BAA6B;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,CAAC;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MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,qBAAqB,GAAG,cAAc,CAAC;AAEtF,MAAM,WAAW,YAAY;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtF,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,6BAA6B,GAAG,SAAS,CAAC;IACpD,IAAI,CAAC,EAAE,aAAa,CAAC;CACrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "4.3.1",
3
+ "version": "4.4.0",
4
4
  "license": "MIT",
5
5
  "author": "Hugging Face and Tim Mikeladze <tim.mikeladze@gmail.com>",
6
6
  "description": "Typescript client for the Hugging Face Inference Providers and Inference Endpoints",
@@ -40,8 +40,8 @@
40
40
  },
41
41
  "type": "module",
42
42
  "dependencies": {
43
- "@huggingface/jinja": "^0.5.0",
44
- "@huggingface/tasks": "^0.19.22"
43
+ "@huggingface/tasks": "^0.19.22",
44
+ "@huggingface/jinja": "^0.5.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/node": "18.13.0"
package/src/index.ts CHANGED
@@ -5,5 +5,6 @@ export * from "./tasks/index.js";
5
5
  import * as snippets from "./snippets/index.js";
6
6
  export * from "./lib/getProviderHelper.js";
7
7
  export * from "./lib/makeRequestOptions.js";
8
+ export { setLogger } from "./lib/logger.js";
8
9
 
9
10
  export { snippets };
@@ -5,6 +5,7 @@ import { EQUIVALENT_SENTENCE_TRANSFORMERS_TASKS } from "../providers/hf-inferenc
5
5
  import type { InferenceProvider, InferenceProviderMappingEntry, InferenceProviderOrPolicy, ModelId } from "../types.js";
6
6
  import { typedInclude } from "../utils/typedInclude.js";
7
7
  import { InferenceClientHubApiError, InferenceClientInputError } from "../errors.js";
8
+ import { getLogger } from "./logger.js";
8
9
 
9
10
  export const inferenceProviderMappingCache = new Map<ModelId, InferenceProviderMappingEntry[]>();
10
11
 
@@ -18,7 +19,16 @@ function normalizeInferenceProviderMapping(
18
19
  modelId: ModelId,
19
20
  inferenceProviderMapping?:
20
21
  | InferenceProviderMappingEntry[]
21
- | Record<string, { providerId: string; status: "live" | "staging"; task: WidgetType }>
22
+ | Record<
23
+ string,
24
+ {
25
+ providerId: string;
26
+ status: "live" | "staging";
27
+ task: WidgetType;
28
+ adapter?: string;
29
+ adapterWeightsPath?: string;
30
+ }
31
+ >
22
32
  ): InferenceProviderMappingEntry[] {
23
33
  if (!inferenceProviderMapping) {
24
34
  return [];
@@ -36,6 +46,8 @@ function normalizeInferenceProviderMapping(
36
46
  providerId: mapping.providerId,
37
47
  status: mapping.status,
38
48
  task: mapping.task,
49
+ adapter: mapping.adapter,
50
+ adapterWeightsPath: mapping.adapterWeightsPath,
39
51
  }));
40
52
  }
41
53
 
@@ -111,6 +123,7 @@ export async function getInferenceProviderMapping(
111
123
  fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
112
124
  }
113
125
  ): Promise<InferenceProviderMappingEntry | null> {
126
+ const logger = getLogger();
114
127
  if (HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId]) {
115
128
  return HARDCODED_MODEL_INFERENCE_MAPPING[params.provider][params.modelId];
116
129
  }
@@ -127,7 +140,7 @@ export async function getInferenceProviderMapping(
127
140
  );
128
141
  }
129
142
  if (providerMapping.status === "staging") {
130
- console.warn(
143
+ logger.warn(
131
144
  `Model ${params.modelId} is in staging mode for provider ${params.provider}. Meant for test purposes only.`
132
145
  );
133
146
  }
@@ -141,6 +154,7 @@ export async function resolveProvider(
141
154
  modelId?: string,
142
155
  endpointUrl?: string
143
156
  ): Promise<InferenceProvider> {
157
+ const logger = getLogger();
144
158
  if (endpointUrl) {
145
159
  if (provider) {
146
160
  throw new InferenceClientInputError("Specifying both endpointUrl and provider is not supported.");
@@ -149,7 +163,7 @@ export async function resolveProvider(
149
163
  return "hf-inference";
150
164
  }
151
165
  if (!provider) {
152
- console.log(
166
+ logger.log(
153
167
  "Defaulting to 'auto' which will select the first provider available for the model, sorted by the user's order in https://hf.co/settings/inference-providers."
154
168
  );
155
169
  provider = "auto";
@@ -160,7 +174,7 @@ export async function resolveProvider(
160
174
  }
161
175
  const mappings = await fetchInferenceProviderMappingForModel(modelId);
162
176
  provider = mappings[0]?.provider as InferenceProvider | undefined;
163
- console.log("Auto selected provider:", provider);
177
+ logger.log("Auto selected provider:", provider);
164
178
  }
165
179
  if (!provider) {
166
180
  throw new InferenceClientInputError(`No Inference Provider available for model ${modelId}.`);
@@ -0,0 +1,11 @@
1
+ import type { Logger } from "../types.js";
2
+
3
+ let globalLogger: Logger = console;
4
+
5
+ export function setLogger(logger: Logger): void {
6
+ globalLogger = logger;
7
+ }
8
+
9
+ export function getLogger(): Logger {
10
+ return globalLogger;
11
+ }
package/src/package.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // Generated file from package.json. Issues importing JSON directly when publishing on commonjs/ESM - see https://github.com/microsoft/TypeScript/issues/51783
2
- export const PACKAGE_VERSION = "4.3.1";
2
+ export const PACKAGE_VERSION = "4.4.0";
3
3
  export const PACKAGE_NAME = "@huggingface/inference";
@@ -19,6 +19,7 @@ import {
19
19
  InferenceClientProviderApiError,
20
20
  InferenceClientProviderOutputError,
21
21
  } from "../errors.js";
22
+ import { getLogger } from "../lib/logger.js";
22
23
  import type { BodyParams, HeaderParams, UrlParams } from "../types.js";
23
24
  import { delay } from "../utils/delay.js";
24
25
  import { omit } from "../utils/omit.js";
@@ -67,10 +68,11 @@ export class BlackForestLabsTextToImageTask extends TaskProviderHelper implement
67
68
  headers?: HeadersInit,
68
69
  outputType?: "url" | "blob"
69
70
  ): Promise<string | Blob> {
71
+ const logger = getLogger();
70
72
  const urlObj = new URL(response.polling_url);
71
73
  for (let step = 0; step < 5; step++) {
72
74
  await delay(1000);
73
- console.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
75
+ logger.debug(`Polling Black Forest Labs API for the result... ${step + 1}/5`);
74
76
  urlObj.searchParams.set("attempt", step.toString(10));
75
77
  const resp = await fetch(urlObj, { headers: { "Content-Type": "application/json" } });
76
78
  if (!resp.ok) {
@@ -25,6 +25,7 @@ import {
25
25
  type TextToImageTaskHelper,
26
26
  } from "./providerHelper.js";
27
27
  import { InferenceClientProviderOutputError } from "../errors.js";
28
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
28
29
 
29
30
  const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
30
31
 
@@ -50,6 +51,17 @@ export class NebiusConversationalTask extends BaseConversationalTask {
50
51
  constructor() {
51
52
  super("nebius", NEBIUS_API_BASE_URL);
52
53
  }
54
+
55
+ override preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown> {
56
+ const payload = super.preparePayload(params) as Record<string, unknown>;
57
+
58
+ const responseFormat = params.args.response_format;
59
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema?.schema) {
60
+ payload["guided_json"] = responseFormat.json_schema.schema;
61
+ }
62
+
63
+ return payload;
64
+ }
53
65
  }
54
66
 
55
67
  export class NebiusTextGenerationTask extends BaseTextGenerationTask {
@@ -19,11 +19,25 @@ import type { BodyParams } from "../types.js";
19
19
  import type { FeatureExtractionTaskHelper } from "./providerHelper.js";
20
20
  import { BaseConversationalTask, TaskProviderHelper } from "./providerHelper.js";
21
21
  import { InferenceClientProviderOutputError } from "../errors.js";
22
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
22
23
 
23
24
  export class SambanovaConversationalTask extends BaseConversationalTask {
24
25
  constructor() {
25
26
  super("sambanova", "https://api.sambanova.ai");
26
27
  }
28
+
29
+ override preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown> {
30
+ const responseFormat = params.args.response_format;
31
+
32
+ if (responseFormat?.type === "json_schema" && responseFormat.json_schema) {
33
+ if (responseFormat.json_schema.strict ?? true) {
34
+ responseFormat.json_schema.strict = false;
35
+ }
36
+ }
37
+ const payload = super.preparePayload(params) as Record<string, unknown>;
38
+
39
+ return payload;
40
+ }
27
41
  }
28
42
 
29
43
  export class SambanovaFeatureExtractionTask extends TaskProviderHelper implements FeatureExtractionTaskHelper {
@@ -24,6 +24,7 @@ import {
24
24
  type TextToImageTaskHelper,
25
25
  } from "./providerHelper.js";
26
26
  import { InferenceClientProviderOutputError } from "../errors.js";
27
+ import type { ChatCompletionInput } from "../../../tasks/dist/commonjs/index.js";
27
28
 
28
29
  const TOGETHER_API_BASE_URL = "https://api.together.xyz";
29
30
 
@@ -47,6 +48,22 @@ export class TogetherConversationalTask extends BaseConversationalTask {
47
48
  constructor() {
48
49
  super("together", TOGETHER_API_BASE_URL);
49
50
  }
51
+
52
+ override preparePayload(params: BodyParams<ChatCompletionInput>): Record<string, unknown> {
53
+ const payload = super.preparePayload(params);
54
+ const response_format = payload.response_format as
55
+ | { type: "json_schema"; json_schema: { schema: unknown } }
56
+ | undefined;
57
+
58
+ if (response_format?.type === "json_schema" && response_format?.json_schema?.schema) {
59
+ payload.response_format = {
60
+ type: "json_schema",
61
+ schema: response_format.json_schema.schema,
62
+ };
63
+ }
64
+
65
+ return payload;
66
+ }
50
67
  }
51
68
 
52
69
  export class TogetherTextGenerationTask extends BaseTextGenerationTask {
@@ -12,6 +12,7 @@ import { getProviderHelper } from "../lib/getProviderHelper.js";
12
12
  import { makeRequestOptionsFromResolvedModel } from "../lib/makeRequestOptions.js";
13
13
  import type { InferenceProviderMappingEntry, InferenceProviderOrPolicy, InferenceTask, RequestArgs } from "../types.js";
14
14
  import { templates } from "./templates.exported.js";
15
+ import { getLogger } from "../lib/logger.js";
15
16
 
16
17
  export type InferenceSnippetOptions = {
17
18
  streaming?: boolean;
@@ -140,6 +141,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
140
141
  inferenceProviderMapping?: InferenceProviderMappingEntry,
141
142
  opts?: InferenceSnippetOptions
142
143
  ): InferenceSnippet[] => {
144
+ const logger = getLogger();
143
145
  const providerModelId = inferenceProviderMapping?.providerId ?? model.id;
144
146
  /// Hacky: hard-code conversational templates here
145
147
  let task = model.pipeline_tag as InferenceTask;
@@ -156,7 +158,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
156
158
  try {
157
159
  providerHelper = getProviderHelper(provider, task);
158
160
  } catch (e) {
159
- console.error(`Failed to get provider helper for ${provider} (${task})`, e);
161
+ logger.error(`Failed to get provider helper for ${provider} (${task})`, e);
160
162
  return [];
161
163
  }
162
164
 
@@ -191,7 +193,7 @@ const snippetGenerator = (templateName: string, inputPreparationFn?: InputPrepar
191
193
  try {
192
194
  providerInputs = JSON.parse(bodyAsObj);
193
195
  } catch (e) {
194
- console.error("Failed to parse body as JSON", e);
196
+ logger.error("Failed to parse body as JSON", e);
195
197
  }
196
198
  }
197
199
 
@@ -2,6 +2,7 @@ import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
2
2
  import { getProviderHelper } from "../../lib/getProviderHelper.js";
3
3
  import type { InferenceTask, Options, RequestArgs } from "../../types.js";
4
4
  import { innerRequest } from "../../utils/request.js";
5
+ import { getLogger } from "../../lib/logger.js";
5
6
 
6
7
  /**
7
8
  * Primitive to make custom calls to the inference provider
@@ -14,7 +15,8 @@ export async function request<T>(
14
15
  task?: InferenceTask;
15
16
  }
16
17
  ): Promise<T> {
17
- console.warn(
18
+ const logger = getLogger();
19
+ logger.warn(
18
20
  "The request method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead."
19
21
  );
20
22
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
@@ -2,6 +2,7 @@ import { resolveProvider } from "../../lib/getInferenceProviderMapping.js";
2
2
  import { getProviderHelper } from "../../lib/getProviderHelper.js";
3
3
  import type { InferenceTask, Options, RequestArgs } from "../../types.js";
4
4
  import { innerStreamingRequest } from "../../utils/request.js";
5
+ import { getLogger } from "../../lib/logger.js";
5
6
 
6
7
  /**
7
8
  * Primitive to make custom inference calls that expect server-sent events, and returns the response through a generator
@@ -14,7 +15,8 @@ export async function* streamingRequest<T>(
14
15
  task?: InferenceTask;
15
16
  }
16
17
  ): AsyncGenerator<T> {
17
- console.warn(
18
+ const logger = getLogger();
19
+ logger.warn(
18
20
  "The streamingRequest method is deprecated and will be removed in a future version of huggingface.js. Use specific task functions instead."
19
21
  );
20
22
  const provider = await resolveProvider(args.provider, args.model, args.endpointUrl);
package/src/types.ts CHANGED
@@ -5,6 +5,14 @@ import type { ChatCompletionInput, PipelineType, WidgetType } from "@huggingface
5
5
  */
6
6
  export type ModelId = string;
7
7
 
8
+ export interface Logger {
9
+ debug: (message: string, ...args: unknown[]) => void;
10
+ info: (message: string, ...args: unknown[]) => void;
11
+ warn: (message: string, ...args: unknown[]) => void;
12
+ error: (message: string, ...args: unknown[]) => void;
13
+ log: (message: string, ...args: unknown[]) => void;
14
+ }
15
+
8
16
  export interface Options {
9
17
  /**
10
18
  * (Default: true) Boolean. If a request 503s, the request will be retried with the same parameters.