@huggingface/inference 3.5.0 → 3.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ var HF_HUB_URL = "https://huggingface.co";
46
46
  var HF_ROUTER_URL = "https://router.huggingface.co";
47
47
 
48
48
  // src/providers/black-forest-labs.ts
49
- var BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
49
+ var BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai";
50
50
  var makeBody = (params) => {
51
51
  return params.args;
52
52
  };
@@ -58,7 +58,7 @@ var makeHeaders = (params) => {
58
58
  }
59
59
  };
60
60
  var makeUrl = (params) => {
61
- return `${params.baseUrl}/${params.model}`;
61
+ return `${params.baseUrl}/v1/${params.model}`;
62
62
  };
63
63
  var BLACK_FOREST_LABS_CONFIG = {
64
64
  baseUrl: BLACK_FOREST_LABS_AI_API_BASE_URL,
@@ -130,7 +130,7 @@ var FAL_AI_CONFIG = {
130
130
  };
131
131
 
132
132
  // src/providers/fireworks-ai.ts
133
- var FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
133
+ var FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai";
134
134
  var makeBody5 = (params) => {
135
135
  return {
136
136
  ...params.args,
@@ -142,9 +142,9 @@ var makeHeaders5 = (params) => {
142
142
  };
143
143
  var makeUrl5 = (params) => {
144
144
  if (params.task === "text-generation" && params.chatCompletion) {
145
- return `${params.baseUrl}/v1/chat/completions`;
145
+ return `${params.baseUrl}/inference/v1/chat/completions`;
146
146
  }
147
- return params.baseUrl;
147
+ return `${params.baseUrl}/inference`;
148
148
  };
149
149
  var FIREWORKS_AI_CONFIG = {
150
150
  baseUrl: FIREWORKS_AI_API_BASE_URL,
@@ -269,7 +269,7 @@ var makeBody10 = (params) => {
269
269
  };
270
270
  };
271
271
  var makeHeaders10 = (params) => {
272
- return { Authorization: `Bearer ${params.accessToken}` };
272
+ return { Authorization: `Bearer ${params.accessToken}`, Prefer: "wait" };
273
273
  };
274
274
  var makeUrl10 = (params) => {
275
275
  if (params.model.includes(":")) {
@@ -373,7 +373,7 @@ function isUrl(modelOrUrl) {
373
373
 
374
374
  // package.json
375
375
  var name = "@huggingface/inference";
376
- var version = "3.5.0";
376
+ var version = "3.5.2";
377
377
 
378
378
  // src/providers/consts.ts
379
379
  var HARDCODED_MODEL_ID_MAPPING = {
@@ -1526,8 +1526,8 @@ async function tabularClassification(args, options) {
1526
1526
  return res;
1527
1527
  }
1528
1528
 
1529
- // src/HfInference.ts
1530
- var HfInference = class {
1529
+ // src/InferenceClient.ts
1530
+ var InferenceClient = class {
1531
1531
  accessToken;
1532
1532
  defaultOptions;
1533
1533
  constructor(accessToken = "", defaultOptions = {}) {
@@ -1544,13 +1544,13 @@ var HfInference = class {
1544
1544
  }
1545
1545
  }
1546
1546
  /**
1547
- * Returns copy of HfInference tied to a specified endpoint.
1547
+ * Returns copy of InferenceClient tied to a specified endpoint.
1548
1548
  */
1549
1549
  endpoint(endpointUrl) {
1550
- return new HfInferenceEndpoint(endpointUrl, this.accessToken, this.defaultOptions);
1550
+ return new InferenceClientEndpoint(endpointUrl, this.accessToken, this.defaultOptions);
1551
1551
  }
1552
1552
  };
1553
- var HfInferenceEndpoint = class {
1553
+ var InferenceClientEndpoint = class {
1554
1554
  constructor(endpointUrl, accessToken = "", defaultOptions = {}) {
1555
1555
  accessToken;
1556
1556
  defaultOptions;
@@ -1565,6 +1565,8 @@ var HfInferenceEndpoint = class {
1565
1565
  }
1566
1566
  }
1567
1567
  };
1568
+ var HfInference = class extends InferenceClient {
1569
+ };
1568
1570
 
1569
1571
  // src/types.ts
1570
1572
  var INFERENCE_PROVIDERS = [
@@ -1722,18 +1724,7 @@ function getCurlInferenceSnippet(model, accessToken, provider, providerModelId,
1722
1724
  // src/snippets/python.ts
1723
1725
  var python_exports = {};
1724
1726
  __export(python_exports, {
1725
- getPythonInferenceSnippet: () => getPythonInferenceSnippet,
1726
- pythonSnippets: () => pythonSnippets,
1727
- snippetBasic: () => snippetBasic2,
1728
- snippetConversational: () => snippetConversational,
1729
- snippetDocumentQuestionAnswering: () => snippetDocumentQuestionAnswering,
1730
- snippetFile: () => snippetFile2,
1731
- snippetTabular: () => snippetTabular,
1732
- snippetTextToAudio: () => snippetTextToAudio,
1733
- snippetTextToImage: () => snippetTextToImage,
1734
- snippetTextToVideo: () => snippetTextToVideo,
1735
- snippetZeroShotClassification: () => snippetZeroShotClassification2,
1736
- snippetZeroShotImageClassification: () => snippetZeroShotImageClassification
1727
+ getPythonInferenceSnippet: () => getPythonInferenceSnippet
1737
1728
  });
1738
1729
  import { openAIbaseUrl } from "@huggingface/tasks";
1739
1730
  import {
@@ -1773,8 +1764,8 @@ var HFH_INFERENCE_CLIENT_METHODS = {
1773
1764
  var snippetImportInferenceClient = (accessToken, provider) => `from huggingface_hub import InferenceClient
1774
1765
 
1775
1766
  client = InferenceClient(
1776
- provider="${provider}",
1777
- api_key="${accessToken || "{API_TOKEN}"}"
1767
+ provider="${provider}",
1768
+ api_key="${accessToken || "{API_TOKEN}"}",
1778
1769
  )`;
1779
1770
  var snippetConversational = (model, accessToken, provider, providerModelId, opts) => {
1780
1771
  const streaming = opts?.streaming ?? true;
@@ -1802,7 +1793,7 @@ stream = client.chat.completions.create(
1802
1793
  model="${model.id}",
1803
1794
  messages=messages,
1804
1795
  ${configStr}
1805
- stream=True
1796
+ stream=True,
1806
1797
  )
1807
1798
 
1808
1799
  for chunk in stream:
@@ -1912,9 +1903,8 @@ var snippetBasic2 = (model, accessToken, provider) => {
1912
1903
  content: `${snippetImportInferenceClient(accessToken, provider)}
1913
1904
 
1914
1905
  result = client.${HFH_INFERENCE_CLIENT_METHODS[model.pipeline_tag]}(
1915
- model="${model.id}",
1916
1906
  inputs=${getModelInputSnippet2(model)},
1917
- provider="${provider}",
1907
+ model="${model.id}",
1918
1908
  )
1919
1909
 
1920
1910
  print(result)
@@ -1956,7 +1946,7 @@ var snippetTextToImage = (model, accessToken, provider, providerModelId) => {
1956
1946
  # output is a PIL.Image object
1957
1947
  image = client.text_to_image(
1958
1948
  ${getModelInputSnippet2(model)},
1959
- model="${model.id}"
1949
+ model="${model.id}",
1960
1950
  )`
1961
1951
  },
1962
1952
  ...provider === "fal-ai" ? [
@@ -2001,7 +1991,7 @@ var snippetTextToVideo = (model, accessToken, provider) => {
2001
1991
 
2002
1992
  video = client.text_to_video(
2003
1993
  ${getModelInputSnippet2(model)},
2004
- model="${model.id}"
1994
+ model="${model.id}",
2005
1995
  )`
2006
1996
  }
2007
1997
  ] : [];
@@ -2055,23 +2045,79 @@ Audio(audio, rate=sampling_rate)`
2055
2045
  ];
2056
2046
  }
2057
2047
  };
2058
- var snippetDocumentQuestionAnswering = (model) => {
2048
+ var snippetAutomaticSpeechRecognition = (model, accessToken, provider) => {
2059
2049
  return [
2050
+ {
2051
+ client: "huggingface_hub",
2052
+ content: `${snippetImportInferenceClient(accessToken, provider)}
2053
+ output = client.automatic_speech_recognition(${getModelInputSnippet2(model)}, model="${model.id}")`
2054
+ },
2055
+ snippetFile2(model)[0]
2056
+ ];
2057
+ };
2058
+ var snippetDocumentQuestionAnswering = (model, accessToken, provider) => {
2059
+ const inputsAsStr = getModelInputSnippet2(model);
2060
+ const inputsAsObj = JSON.parse(inputsAsStr);
2061
+ return [
2062
+ {
2063
+ client: "huggingface_hub",
2064
+ content: `${snippetImportInferenceClient(accessToken, provider)}
2065
+ output = client.document_question_answering(
2066
+ "${inputsAsObj.image}",
2067
+ question="${inputsAsObj.question}",
2068
+ model="${model.id}",
2069
+ )`
2070
+ },
2060
2071
  {
2061
2072
  client: "requests",
2062
2073
  content: `def query(payload):
2063
2074
  with open(payload["image"], "rb") as f:
2064
2075
  img = f.read()
2065
- payload["image"] = base64.b64encode(img).decode("utf-8")
2076
+ payload["image"] = base64.b64encode(img).decode("utf-8")
2066
2077
  response = requests.post(API_URL, headers=headers, json=payload)
2067
2078
  return response.json()
2068
2079
 
2069
2080
  output = query({
2070
- "inputs": ${getModelInputSnippet2(model)},
2081
+ "inputs": ${inputsAsStr},
2071
2082
  })`
2072
2083
  }
2073
2084
  ];
2074
2085
  };
2086
+ var snippetImageToImage = (model, accessToken, provider) => {
2087
+ const inputsAsStr = getModelInputSnippet2(model);
2088
+ const inputsAsObj = JSON.parse(inputsAsStr);
2089
+ return [
2090
+ {
2091
+ client: "huggingface_hub",
2092
+ content: `${snippetImportInferenceClient(accessToken, provider)}
2093
+ # output is a PIL.Image object
2094
+ image = client.image_to_image(
2095
+ "${inputsAsObj.image}",
2096
+ prompt="${inputsAsObj.prompt}",
2097
+ model="${model.id}",
2098
+ )`
2099
+ },
2100
+ {
2101
+ client: "requests",
2102
+ content: `def query(payload):
2103
+ with open(payload["inputs"], "rb") as f:
2104
+ img = f.read()
2105
+ payload["inputs"] = base64.b64encode(img).decode("utf-8")
2106
+ response = requests.post(API_URL, headers=headers, json=payload)
2107
+ return response.content
2108
+
2109
+ image_bytes = query({
2110
+ "inputs": "${inputsAsObj.image}",
2111
+ "parameters": {"prompt": "${inputsAsObj.prompt}"},
2112
+ })
2113
+
2114
+ # You can access the image with PIL.Image for example
2115
+ import io
2116
+ from PIL import Image
2117
+ image = Image.open(io.BytesIO(image_bytes))`
2118
+ }
2119
+ ];
2120
+ };
2075
2121
  var pythonSnippets = {
2076
2122
  // Same order as in tasks/src/pipelines.ts
2077
2123
  "text-classification": snippetBasic2,
@@ -2087,7 +2133,7 @@ var pythonSnippets = {
2087
2133
  "image-text-to-text": snippetConversational,
2088
2134
  "fill-mask": snippetBasic2,
2089
2135
  "sentence-similarity": snippetBasic2,
2090
- "automatic-speech-recognition": snippetFile2,
2136
+ "automatic-speech-recognition": snippetAutomaticSpeechRecognition,
2091
2137
  "text-to-image": snippetTextToImage,
2092
2138
  "text-to-video": snippetTextToVideo,
2093
2139
  "text-to-speech": snippetTextToAudio,
@@ -2101,6 +2147,7 @@ var pythonSnippets = {
2101
2147
  "image-segmentation": snippetFile2,
2102
2148
  "document-question-answering": snippetDocumentQuestionAnswering,
2103
2149
  "image-to-text": snippetFile2,
2150
+ "image-to-image": snippetImageToImage,
2104
2151
  "zero-shot-image-classification": snippetZeroShotImageClassification
2105
2152
  };
2106
2153
  function getPythonInferenceSnippet(model, accessToken, provider, providerModelId, opts) {
@@ -2111,23 +2158,33 @@ function getPythonInferenceSnippet(model, accessToken, provider, providerModelId
2111
2158
  return snippets.map((snippet) => {
2112
2159
  return {
2113
2160
  ...snippet,
2114
- content: snippet.client === "requests" ? `import requests
2115
-
2116
- API_URL = "${openAIbaseUrl(provider)}"
2117
- headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
2118
-
2119
- ${snippet.content}` : snippet.content
2161
+ content: addImportsToSnippet(snippet.content, model, accessToken)
2120
2162
  };
2121
2163
  });
2122
2164
  }
2123
2165
  }
2166
+ var addImportsToSnippet = (snippet, model, accessToken) => {
2167
+ if (snippet.includes("requests")) {
2168
+ snippet = `import requests
2169
+
2170
+ API_URL = "https://router.huggingface.co/hf-inference/models/${model.id}"
2171
+ headers = {"Authorization": ${accessToken ? `"Bearer ${accessToken}"` : `f"Bearer {API_TOKEN}"`}}
2172
+
2173
+ ${snippet}`;
2174
+ }
2175
+ if (snippet.includes("base64")) {
2176
+ snippet = `import base64
2177
+ ${snippet}`;
2178
+ }
2179
+ return snippet;
2180
+ };
2124
2181
 
2125
2182
  // src/snippets/js.ts
2126
2183
  var js_exports = {};
2127
2184
  __export(js_exports, {
2128
2185
  getJsInferenceSnippet: () => getJsInferenceSnippet,
2129
2186
  jsSnippets: () => jsSnippets,
2130
- snippetAutomaticSpeechRecognition: () => snippetAutomaticSpeechRecognition,
2187
+ snippetAutomaticSpeechRecognition: () => snippetAutomaticSpeechRecognition2,
2131
2188
  snippetBasic: () => snippetBasic3,
2132
2189
  snippetFile: () => snippetFile3,
2133
2190
  snippetTextGeneration: () => snippetTextGeneration2,
@@ -2160,9 +2217,9 @@ var snippetBasic3 = (model, accessToken, provider) => {
2160
2217
  ...model.pipeline_tag && model.pipeline_tag in HFJS_METHODS ? [
2161
2218
  {
2162
2219
  client: "huggingface.js",
2163
- content: `import { HfInference } from "@huggingface/inference";
2220
+ content: `import { InferenceClient } from "@huggingface/inference";
2164
2221
 
2165
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2222
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2166
2223
 
2167
2224
  const output = await client.${HFJS_METHODS[model.pipeline_tag]}({
2168
2225
  model: "${model.id}",
@@ -2217,9 +2274,9 @@ var snippetTextGeneration2 = (model, accessToken, provider, providerModelId, opt
2217
2274
  return [
2218
2275
  {
2219
2276
  client: "huggingface.js",
2220
- content: `import { HfInference } from "@huggingface/inference";
2277
+ content: `import { InferenceClient } from "@huggingface/inference";
2221
2278
 
2222
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2279
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2223
2280
 
2224
2281
  let out = "";
2225
2282
 
@@ -2269,9 +2326,9 @@ for await (const chunk of stream) {
2269
2326
  return [
2270
2327
  {
2271
2328
  client: "huggingface.js",
2272
- content: `import { HfInference } from "@huggingface/inference";
2329
+ content: `import { InferenceClient } from "@huggingface/inference";
2273
2330
 
2274
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2331
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2275
2332
 
2276
2333
  const chatCompletion = await client.chatCompletion({
2277
2334
  model: "${model.id}",
@@ -2339,9 +2396,9 @@ var snippetTextToImage2 = (model, accessToken, provider) => {
2339
2396
  return [
2340
2397
  {
2341
2398
  client: "huggingface.js",
2342
- content: `import { HfInference } from "@huggingface/inference";
2399
+ content: `import { InferenceClient } from "@huggingface/inference";
2343
2400
 
2344
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2401
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2345
2402
 
2346
2403
  const image = await client.textToImage({
2347
2404
  model: "${model.id}",
@@ -2381,9 +2438,9 @@ var snippetTextToVideo2 = (model, accessToken, provider) => {
2381
2438
  return ["fal-ai", "replicate"].includes(provider) ? [
2382
2439
  {
2383
2440
  client: "huggingface.js",
2384
- content: `import { HfInference } from "@huggingface/inference";
2441
+ content: `import { InferenceClient } from "@huggingface/inference";
2385
2442
 
2386
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2443
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2387
2444
 
2388
2445
  const video = await client.textToVideo({
2389
2446
  model: "${model.id}",
@@ -2441,13 +2498,13 @@ var snippetTextToAudio2 = (model, accessToken, provider) => {
2441
2498
  ];
2442
2499
  }
2443
2500
  };
2444
- var snippetAutomaticSpeechRecognition = (model, accessToken, provider) => {
2501
+ var snippetAutomaticSpeechRecognition2 = (model, accessToken, provider) => {
2445
2502
  return [
2446
2503
  {
2447
2504
  client: "huggingface.js",
2448
- content: `import { HfInference } from "@huggingface/inference";
2505
+ content: `import { InferenceClient } from "@huggingface/inference";
2449
2506
 
2450
- const client = new HfInference("${accessToken || `{API_TOKEN}`}");
2507
+ const client = new InferenceClient("${accessToken || `{API_TOKEN}`}");
2451
2508
 
2452
2509
  const data = fs.readFileSync(${getModelInputSnippet3(model)});
2453
2510
 
@@ -2508,7 +2565,7 @@ var jsSnippets = {
2508
2565
  "text2text-generation": snippetBasic3,
2509
2566
  "fill-mask": snippetBasic3,
2510
2567
  "sentence-similarity": snippetBasic3,
2511
- "automatic-speech-recognition": snippetAutomaticSpeechRecognition,
2568
+ "automatic-speech-recognition": snippetAutomaticSpeechRecognition2,
2512
2569
  "text-to-image": snippetTextToImage2,
2513
2570
  "text-to-video": snippetTextToVideo2,
2514
2571
  "text-to-speech": snippetTextToAudio2,
@@ -2525,8 +2582,9 @@ function getJsInferenceSnippet(model, accessToken, provider, providerModelId, op
2525
2582
  }
2526
2583
  export {
2527
2584
  HfInference,
2528
- HfInferenceEndpoint,
2529
2585
  INFERENCE_PROVIDERS,
2586
+ InferenceClient,
2587
+ InferenceClientEndpoint,
2530
2588
  InferenceOutputError,
2531
2589
  audioClassification,
2532
2590
  audioToAudio,
@@ -8,21 +8,26 @@ type TaskWithNoAccessToken = {
8
8
  type TaskWithNoAccessTokenNoEndpointUrl = {
9
9
  [key in keyof Task]: (args: DistributiveOmit<Parameters<Task[key]>[0], "accessToken" | "endpointUrl">, options?: Parameters<Task[key]>[1]) => ReturnType<Task[key]>;
10
10
  };
11
- export declare class HfInference {
11
+ export declare class InferenceClient {
12
12
  private readonly accessToken;
13
13
  private readonly defaultOptions;
14
14
  constructor(accessToken?: string, defaultOptions?: Options);
15
15
  /**
16
- * Returns copy of HfInference tied to a specified endpoint.
16
+ * Returns copy of InferenceClient tied to a specified endpoint.
17
17
  */
18
- endpoint(endpointUrl: string): HfInferenceEndpoint;
18
+ endpoint(endpointUrl: string): InferenceClientEndpoint;
19
19
  }
20
- export declare class HfInferenceEndpoint {
20
+ export declare class InferenceClientEndpoint {
21
21
  constructor(endpointUrl: string, accessToken?: string, defaultOptions?: Options);
22
22
  }
23
- export interface HfInference extends TaskWithNoAccessToken {
23
+ export interface InferenceClient extends TaskWithNoAccessToken {
24
24
  }
25
- export interface HfInferenceEndpoint extends TaskWithNoAccessTokenNoEndpointUrl {
25
+ export interface InferenceClientEndpoint extends TaskWithNoAccessTokenNoEndpointUrl {
26
+ }
27
+ /**
28
+ * For backward compatibility only.
29
+ */
30
+ export declare class HfInference extends InferenceClient {
26
31
  }
27
32
  export {};
28
- //# sourceMappingURL=HfInference.d.ts.map
33
+ //# sourceMappingURL=InferenceClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InferenceClient.d.ts","sourceRoot":"","sources":["../../src/InferenceClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,EAAE,OAAO,EAAe,MAA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;CAAG"}
@@ -1,4 +1,4 @@
1
- export { HfInference, HfInferenceEndpoint } from "./HfInference";
1
+ export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient";
2
2
  export { InferenceOutputError } from "./lib/InferenceOutputError";
3
3
  export * from "./types";
4
4
  export * from "./tasks";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,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,mBAAmB,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"cohere.d.ts","sourceRoot":"","sources":["../../../src/providers/cohere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,UAAU,CAAC;AAoBpF,eAAO,MAAM,aAAa,EAAE,cAK3B,CAAC"}
1
+ {"version":3,"file":"cohere.d.ts","sourceRoot":"","sources":["../../../src/providers/cohere.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,cAAc,EAAuC,MAAM,UAAU,CAAC;AAmBpF,eAAO,MAAM,aAAa,EAAE,cAK3B,CAAC"}
@@ -1,23 +1,4 @@
1
1
  import { type SnippetInferenceProvider } from "@huggingface/tasks";
2
- import type { PipelineType } from "@huggingface/tasks/src/pipelines.js";
3
- import type { ChatCompletionInputMessage, GenerationParameters } from "@huggingface/tasks/src/tasks/index.js";
4
2
  import { type InferenceSnippet, type ModelDataMinimal } from "@huggingface/tasks";
5
- export declare const snippetConversational: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: {
6
- streaming?: boolean;
7
- messages?: ChatCompletionInputMessage[];
8
- temperature?: GenerationParameters["temperature"];
9
- max_tokens?: GenerationParameters["max_tokens"];
10
- top_p?: GenerationParameters["top_p"];
11
- }) => InferenceSnippet[];
12
- export declare const snippetZeroShotClassification: (model: ModelDataMinimal) => InferenceSnippet[];
13
- export declare const snippetZeroShotImageClassification: (model: ModelDataMinimal) => InferenceSnippet[];
14
- export declare const snippetBasic: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
15
- export declare const snippetFile: (model: ModelDataMinimal) => InferenceSnippet[];
16
- export declare const snippetTextToImage: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string) => InferenceSnippet[];
17
- export declare const snippetTextToVideo: (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider) => InferenceSnippet[];
18
- export declare const snippetTabular: (model: ModelDataMinimal) => InferenceSnippet[];
19
- export declare const snippetTextToAudio: (model: ModelDataMinimal) => InferenceSnippet[];
20
- export declare const snippetDocumentQuestionAnswering: (model: ModelDataMinimal) => InferenceSnippet[];
21
- export declare const pythonSnippets: Partial<Record<PipelineType, (model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>) => InferenceSnippet[]>>;
22
3
  export declare function getPythonInferenceSnippet(model: ModelDataMinimal, accessToken: string, provider: SnippetInferenceProvider, providerModelId?: string, opts?: Record<string, unknown>): InferenceSnippet[];
23
4
  //# sourceMappingURL=python.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../../src/snippets/python.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,qCAAqC,CAAC;AACpF,OAAO,KAAK,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC9G,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EAIrB,MAAM,oBAAoB,CAAC;AAyC5B,eAAO,MAAM,qBAAqB,UAC1B,gBAAgB,eACV,MAAM,YACT,wBAAwB,oBAChB,MAAM,SACjB;IACN,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,0BAA0B,EAAE,CAAC;IACxC,WAAW,CAAC,EAAE,oBAAoB,CAAC,aAAa,CAAC,CAAC;IAClD,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;CACtC,KACC,gBAAgB,EAiGlB,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAAW,gBAAgB,KAAG,gBAAgB,EAevF,CAAC;AAEF,eAAO,MAAM,kCAAkC,UAAW,gBAAgB,KAAG,gBAAgB,EAqB5F,CAAC;AAEF,eAAO,MAAM,YAAY,UACjB,gBAAgB,eACV,MAAM,YACT,wBAAwB,KAChC,gBAAgB,EAgClB,CAAC;AAEF,eAAO,MAAM,WAAW,UAAW,gBAAgB,KAAG,gBAAgB,EAcrE,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACvB,gBAAgB,eACV,MAAM,YACT,wBAAwB,oBAChB,MAAM,KACtB,gBAAgB,EAoDlB,CAAC;AAEF,eAAO,MAAM,kBAAkB,UACvB,gBAAgB,eACV,MAAM,YAC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InferenceClient.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InferenceClient.spec.d.ts","sourceRoot":"","sources":["../../test/InferenceClient.spec.ts"],"names":[],"mappings":"AAeA,OAAO,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@huggingface/inference",
3
- "version": "3.5.0",
3
+ "version": "3.5.2",
4
4
  "packageManager": "pnpm@8.10.5",
5
5
  "license": "MIT",
6
- "author": "Tim Mikeladze <tim.mikeladze@gmail.com>",
7
- "description": "Typescript wrapper for the Hugging Face Inference Endpoints & Inference API",
6
+ "author": "Hugging Face and Tim Mikeladze <tim.mikeladze@gmail.com>",
7
+ "description": "Typescript client for the Hugging Face Inference Providers and Inference Endpoints",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/huggingface/huggingface.js.git"
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "type": "module",
41
41
  "dependencies": {
42
- "@huggingface/tasks": "^0.17.0"
42
+ "@huggingface/tasks": "^0.17.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "18.13.0"
@@ -21,7 +21,7 @@ type TaskWithNoAccessTokenNoEndpointUrl = {
21
21
  ) => ReturnType<Task[key]>;
22
22
  };
23
23
 
24
- export class HfInference {
24
+ export class InferenceClient {
25
25
  private readonly accessToken: string;
26
26
  private readonly defaultOptions: Options;
27
27
 
@@ -40,14 +40,14 @@ export class HfInference {
40
40
  }
41
41
 
42
42
  /**
43
- * Returns copy of HfInference tied to a specified endpoint.
43
+ * Returns copy of InferenceClient tied to a specified endpoint.
44
44
  */
45
- public endpoint(endpointUrl: string): HfInferenceEndpoint {
46
- return new HfInferenceEndpoint(endpointUrl, this.accessToken, this.defaultOptions);
45
+ public endpoint(endpointUrl: string): InferenceClientEndpoint {
46
+ return new InferenceClientEndpoint(endpointUrl, this.accessToken, this.defaultOptions);
47
47
  }
48
48
  }
49
49
 
50
- export class HfInferenceEndpoint {
50
+ export class InferenceClientEndpoint {
51
51
  constructor(endpointUrl: string, accessToken = "", defaultOptions: Options = {}) {
52
52
  accessToken;
53
53
  defaultOptions;
@@ -63,6 +63,11 @@ export class HfInferenceEndpoint {
63
63
  }
64
64
  }
65
65
 
66
- export interface HfInference extends TaskWithNoAccessToken {}
66
+ export interface InferenceClient extends TaskWithNoAccessToken {}
67
67
 
68
- export interface HfInferenceEndpoint extends TaskWithNoAccessTokenNoEndpointUrl {}
68
+ export interface InferenceClientEndpoint extends TaskWithNoAccessTokenNoEndpointUrl {}
69
+
70
+ /**
71
+ * For backward compatibility only.
72
+ */
73
+ export class HfInference extends InferenceClient {}
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { HfInference, HfInferenceEndpoint } from "./HfInference";
1
+ export { InferenceClient, InferenceClientEndpoint, HfInference } from "./InferenceClient";
2
2
  export { InferenceOutputError } from "./lib/InferenceOutputError";
3
3
  export * from "./types";
4
4
  export * from "./tasks";
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
18
18
 
19
- const BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai/v1";
19
+ const BLACK_FOREST_LABS_AI_API_BASE_URL = "https://api.us1.bfl.ai";
20
20
 
21
21
  const makeBody = (params: BodyParams): Record<string, unknown> => {
22
22
  return params.args;
@@ -31,7 +31,7 @@ const makeHeaders = (params: HeaderParams): Record<string, string> => {
31
31
  };
32
32
 
33
33
  const makeUrl = (params: UrlParams): string => {
34
- return `${params.baseUrl}/${params.model}`;
34
+ return `${params.baseUrl}/v1/${params.model}`;
35
35
  };
36
36
 
37
37
  export const BLACK_FOREST_LABS_CONFIG: ProviderConfig = {
@@ -18,7 +18,6 @@ import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../typ
18
18
 
19
19
  const COHERE_API_BASE_URL = "https://api.cohere.com";
20
20
 
21
-
22
21
  const makeBody = (params: BodyParams): Record<string, unknown> => {
23
22
  return {
24
23
  ...params.args,
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import type { ProviderConfig, UrlParams, HeaderParams, BodyParams } from "../types";
18
18
 
19
- const FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai/inference";
19
+ const FIREWORKS_AI_API_BASE_URL = "https://api.fireworks.ai";
20
20
 
21
21
  const makeBody = (params: BodyParams): Record<string, unknown> => {
22
22
  return {
@@ -31,9 +31,9 @@ const makeHeaders = (params: HeaderParams): Record<string, string> => {
31
31
 
32
32
  const makeUrl = (params: UrlParams): string => {
33
33
  if (params.task === "text-generation" && params.chatCompletion) {
34
- return `${params.baseUrl}/v1/chat/completions`;
34
+ return `${params.baseUrl}/inference/v1/chat/completions`;
35
35
  }
36
- return params.baseUrl;
36
+ return `${params.baseUrl}/inference`;
37
37
  };
38
38
 
39
39
  export const FIREWORKS_AI_CONFIG: ProviderConfig = {
@@ -26,7 +26,7 @@ const makeBody = (params: BodyParams): Record<string, unknown> => {
26
26
  };
27
27
 
28
28
  const makeHeaders = (params: HeaderParams): Record<string, string> => {
29
- return { Authorization: `Bearer ${params.accessToken}` };
29
+ return { Authorization: `Bearer ${params.accessToken}`, Prefer: "wait" };
30
30
  };
31
31
 
32
32
  const makeUrl = (params: UrlParams): string => {