@huggingface/inference 2.8.0 → 3.0.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 (48) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +39 -16
  3. package/dist/index.cjs +364 -134
  4. package/dist/index.js +359 -134
  5. package/dist/src/config.d.ts +3 -0
  6. package/dist/src/config.d.ts.map +1 -0
  7. package/dist/src/index.d.ts +5 -0
  8. package/dist/src/index.d.ts.map +1 -1
  9. package/dist/src/lib/getDefaultTask.d.ts +0 -1
  10. package/dist/src/lib/getDefaultTask.d.ts.map +1 -1
  11. package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
  12. package/dist/src/providers/fal-ai.d.ts +6 -0
  13. package/dist/src/providers/fal-ai.d.ts.map +1 -0
  14. package/dist/src/providers/replicate.d.ts +6 -0
  15. package/dist/src/providers/replicate.d.ts.map +1 -0
  16. package/dist/src/providers/sambanova.d.ts +6 -0
  17. package/dist/src/providers/sambanova.d.ts.map +1 -0
  18. package/dist/src/providers/together.d.ts +12 -0
  19. package/dist/src/providers/together.d.ts.map +1 -0
  20. package/dist/src/providers/types.d.ts +4 -0
  21. package/dist/src/providers/types.d.ts.map +1 -0
  22. package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
  23. package/dist/src/tasks/custom/request.d.ts +1 -1
  24. package/dist/src/tasks/custom/request.d.ts.map +1 -1
  25. package/dist/src/tasks/custom/streamingRequest.d.ts.map +1 -1
  26. package/dist/src/tasks/cv/textToImage.d.ts +8 -0
  27. package/dist/src/tasks/cv/textToImage.d.ts.map +1 -1
  28. package/dist/src/tasks/nlp/chatCompletion.d.ts.map +1 -1
  29. package/dist/src/tasks/nlp/textGeneration.d.ts.map +1 -1
  30. package/dist/src/types.d.ts +16 -2
  31. package/dist/src/types.d.ts.map +1 -1
  32. package/package.json +2 -2
  33. package/src/config.ts +2 -0
  34. package/src/index.ts +5 -0
  35. package/src/lib/getDefaultTask.ts +1 -1
  36. package/src/lib/makeRequestOptions.ts +199 -59
  37. package/src/providers/fal-ai.ts +15 -0
  38. package/src/providers/replicate.ts +16 -0
  39. package/src/providers/sambanova.ts +23 -0
  40. package/src/providers/together.ts +58 -0
  41. package/src/providers/types.ts +6 -0
  42. package/src/tasks/audio/automaticSpeechRecognition.ts +10 -1
  43. package/src/tasks/custom/request.ts +12 -6
  44. package/src/tasks/custom/streamingRequest.ts +18 -3
  45. package/src/tasks/cv/textToImage.ts +44 -1
  46. package/src/tasks/nlp/chatCompletion.ts +2 -2
  47. package/src/tasks/nlp/textGeneration.ts +43 -9
  48. package/src/types.ts +20 -2
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Tim Mikeladze
3
+ Copyright (c) 2022 Tim Mikeladze and the Hugging Face team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # 🤗 Hugging Face Inference Endpoints
2
2
 
3
- A Typescript powered wrapper for the Hugging Face Inference Endpoints API. Learn more about Inference Endpoints at [Hugging Face](https://huggingface.co/inference-endpoints).
4
- It works with both [Inference API (serverless)](https://huggingface.co/docs/api-inference/index) and [Inference Endpoints (dedicated)](https://huggingface.co/docs/inference-endpoints/index).
3
+ A Typescript powered wrapper for the Hugging Face Inference API (serverless), Inference Endpoints (dedicated), and third-party Inference Providers.
4
+ It works with [Inference API (serverless)](https://huggingface.co/docs/api-inference/index) and [Inference Endpoints (dedicated)](https://huggingface.co/docs/inference-endpoints/index), and even with supported third-party Inference Providers.
5
5
 
6
6
  Check out the [full documentation](https://huggingface.co/docs/huggingface.js/inference/README).
7
7
 
@@ -42,6 +42,34 @@ const hf = new HfInference('your access token')
42
42
 
43
43
  Your access token should be kept private. If you need to protect it in front-end applications, we suggest setting up a proxy server that stores the access token.
44
44
 
45
+ ### Requesting third-party inference providers
46
+
47
+ You can request inference from third-party providers with the inference client.
48
+
49
+ Currently, we support the following providers: [Fal.ai](https://fal.ai), [Replicate](https://replicate.com), [Together](https://together.xyz) and [Sambanova](https://sambanova.ai).
50
+
51
+ To make request to a third-party provider, you have to pass the `provider` parameter to the inference function. Make sure your request is authenticated with an access token.
52
+ ```ts
53
+ const accessToken = "hf_..."; // Either a HF access token, or an API key from the 3rd party provider (Replicate in this example)
54
+
55
+ const client = new HfInference(accessToken);
56
+ await client.textToImage({
57
+ provider: "replicate",
58
+ model:"black-forest-labs/Flux.1-dev",
59
+ inputs: "A black forest cake"
60
+ })
61
+ ```
62
+
63
+ When authenticated with a Hugging Face access token, the request is routed through https://huggingface.co.
64
+ When authenticated with a third-party provider key, the request is made directly against that provider's inference API.
65
+
66
+ Only a subset of models are supported when requesting 3rd party providers. You can check the list of supported models per pipeline tasks here:
67
+ - [Fal.ai supported models](./src/providers/fal-ai.ts)
68
+ - [Replicate supported models](./src/providers/replicate.ts)
69
+ - [Sambanova supported models](./src/providers/sambanova.ts)
70
+ - [Together supported models](./src/providers/together.ts)
71
+ - [HF Inference API (serverless)](https://huggingface.co/models?inference=warm&sort=trending)
72
+
45
73
  #### Tree-shaking
46
74
 
47
75
  You can import the functions you need directly from the module instead of using the `HfInference` class.
@@ -91,23 +119,21 @@ Using the `chatCompletion` method, you can generate text with models compatible
91
119
  ```typescript
92
120
  // Non-streaming API
93
121
  const out = await hf.chatCompletion({
94
- model: "mistralai/Mistral-7B-Instruct-v0.2",
95
- messages: [{ role: "user", content: "Complete the this sentence with words one plus one is equal " }],
96
- max_tokens: 500,
122
+ model: "meta-llama/Llama-3.1-8B-Instruct",
123
+ messages: [{ role: "user", content: "Hello, nice to meet you!" }],
124
+ max_tokens: 512,
97
125
  temperature: 0.1,
98
- seed: 0,
99
126
  });
100
127
 
101
128
  // Streaming API
102
129
  let out = "";
103
130
  for await (const chunk of hf.chatCompletionStream({
104
- model: "mistralai/Mistral-7B-Instruct-v0.2",
131
+ model: "meta-llama/Llama-3.1-8B-Instruct",
105
132
  messages: [
106
- { role: "user", content: "Complete the equation 1+1= ,just the answer" },
133
+ { role: "user", content: "Can you help me solve an equation?" },
107
134
  ],
108
- max_tokens: 500,
135
+ max_tokens: 512,
109
136
  temperature: 0.1,
110
- seed: 0,
111
137
  })) {
112
138
  if (chunk.choices && chunk.choices.length > 0) {
113
139
  out += chunk.choices[0].delta.content;
@@ -396,11 +422,8 @@ Creates an image from a text prompt.
396
422
 
397
423
  ```typescript
398
424
  await hf.textToImage({
399
- inputs: 'award winning high resolution photo of a giant tortoise/((ladybird)) hybrid, [trending on artstation]',
400
- model: 'stabilityai/stable-diffusion-2',
401
- parameters: {
402
- negative_prompt: 'blurry',
403
- }
425
+ model: 'black-forest-labs/FLUX.1-dev',
426
+ inputs: 'a picture of a green bird'
404
427
  })
405
428
  ```
406
429
 
@@ -583,7 +606,7 @@ const { generated_text } = await gpt2.textGeneration({inputs: 'The answer to the
583
606
 
584
607
  // Chat Completion Example
585
608
  const ep = hf.endpoint(
586
- "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.2"
609
+ "https://api-inference.huggingface.co/models/meta-llama/Llama-3.1-8B-Instruct"
587
610
  );
588
611
  const stream = ep.chatCompletionStream({
589
612
  model: "tgi",