Skip to content

Commit 0ce3f92

Browse files
committed
add openai and image generation
1 parent 2e2401e commit 0ce3f92

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

docs/hub/models-inference.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ You can integrate Inference Providers into your own applications using our SDKs
2121

2222
<hfoption id="python">
2323

24+
You can use our Python SDK to interact with Inference Providers.
25+
2426
```python
2527
from huggingface_hub import InferenceClient
2628

@@ -34,14 +36,47 @@ client = InferenceClient(
3436
# Chat completion
3537
completion = client.chat.completions.create(
3638
model="deepseek-ai/DeepSeek-V3-0324",
37-
messages=[{"role": "user", "content": "Hello!"}]
39+
messages=[{"role": "user", "content": "A story about hiking in the mountains"}]
40+
)
41+
42+
# Image generation
43+
image = client.text_to_image(
44+
prompt="A serene lake surrounded by mountains at sunset, photorealistic style",
45+
model="black-forest-labs/FLUX.1-dev"
46+
)
47+
48+
```
49+
50+
Or, you can just use the OpenAI API compatible client.
51+
52+
```python
53+
import os
54+
from huggingface_hub import InferenceClient
55+
56+
client = InferenceClient(
57+
api_key=os.environ["HF_TOKEN"],
58+
)
59+
60+
completion = client.chat.completions.create(
61+
model="deepseek-ai/DeepSeek-V3-0324",
62+
messages=[
63+
{
64+
"role": "user",
65+
"content": "A story about hiking in the mountains"
66+
}
67+
],
3868
)
3969
```
4070

71+
> [!NOTE]
72+
> The OpenAI API compatible client is not supported for image generation.
73+
4174
</hfoption>
4275

4376
<hfoption id="javascript">
4477

78+
You can use our JavaScript SDK to interact with Inference Providers.
79+
4580
```javascript
4681
import { InferenceClient } from "@huggingface/inference";
4782

@@ -52,8 +87,34 @@ const chatCompletion = await client.chatCompletion({
5287
model: "deepseek-ai/DeepSeek-V3-0324",
5388
messages: [{ role: "user", content: "Hello!" }]
5489
});
90+
91+
const imageBlob = await client.textToImage({
92+
model: "black-forest-labs/FLUX.1-dev",
93+
inputs:
94+
"A serene lake surrounded by mountains at sunset, photorealistic style",
95+
});
96+
```
97+
98+
Or, you can just use the OpenAI API compatible client.
99+
100+
```javascript
101+
import { OpenAI } from "openai";
102+
103+
const client = new OpenAI({
104+
baseURL: "https://router.huggingface.co/v1",
105+
apiKey: process.env.HF_TOKEN,
106+
});
107+
108+
const completion = await client.chat.completions.create({
109+
model: "meta-llama/Llama-3.1-8B-Instruct",
110+
messages: [{ role: "user", content: "A story about hiking in the mountains" }],
111+
});
112+
55113
```
56114

115+
> [!NOTE]
116+
> The OpenAI API compatible client is not supported for image generation.
117+
57118
</hfoption>
58119

59120
</hfoptions>

0 commit comments

Comments
 (0)