Skip to content

Commit ffeb577

Browse files
authored
Update reference-model-inference-api.md
1 parent 2acb38a commit ffeb577

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

articles/ai-studio/reference/reference-model-inference-api.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ model = ChatCompletionsClient(
103103
)
104104
```
105105

106+
If you are using an endpoint with support for Entra ID, you can create your client as follows:
107+
108+
```python
109+
import os
110+
from azure.ai.inference import ChatCompletionsClient
111+
from azure.identity import AzureDefaultCredential
112+
113+
model = ChatCompletionsClient(
114+
endpoint=os.environ["AZUREAI_ENDPOINT_URL"],
115+
credential=AzureDefaultCredential(),
116+
)
117+
```
118+
106119
# [JavaScript](#tab/javascript)
107120

108121
Install the package `@azure-rest/ai-inference` using npm:
@@ -124,6 +137,19 @@ const client = new ModelClient(
124137
);
125138
```
126139

140+
For endpoint with support for Microsoft Entra ID, you can create your client as follows:
141+
142+
```javascript
143+
import ModelClient from "@azure-rest/ai-inference";
144+
import { isUnexpected } from "@azure-rest/ai-inference";
145+
import { AzureDefaultCredential } from "@azure/identity";
146+
147+
const client = new ModelClient(
148+
process.env.AZUREAI_ENDPOINT_URL,
149+
new AzureDefaultCredential()
150+
);
151+
```
152+
127153
# [REST](#tab/rest)
128154

129155
Use the reference section to explore the API design and which parameters are available. For example, the reference section for [Chat completions](reference-model-inference-chat-completions.md) details how to use the route `/chat/completions` to generate predictions based on chat-formatted instructions:
@@ -143,11 +169,13 @@ The Azure AI Model Inference API specifies a set of modalities and parameters th
143169

144170
By setting a header `extra-parameters: pass-through`, the API will attempt to pass any unknown parameter directly to the underlying model. If the model can handle that parameter, the request completes.
145171

146-
The following example shows a request passing the parameter `safe_prompt` supported by Mistral-Large, which isn't specified in the Azure AI Model Inference API:
172+
The following example shows a request passing the parameter `safe_prompt` supported by Mistral-Large, which isn't specified in the Azure AI Model Inference API.
147173

148174
# [Python](#tab/python)
149175

150176
```python
177+
from azure.ai.inference.models import SystemMessage, UserMessage
178+
151179
response = model.complete(
152180
messages=[
153181
SystemMessage(content="You are a helpful assistant."),
@@ -157,8 +185,13 @@ response = model.complete(
157185
"safe_mode": True
158186
}
159187
)
188+
189+
print(response.choices[0].message.content)
160190
```
161191

192+
> [!TIP]
193+
> When using Azure AI Inference SDK, using passing extra parameters using `model_extras` configures the request with `extra-parameters: pass-through` automatically for you.
194+
162195
# [JavaScript](#tab/javascript)
163196

164197
```javascript
@@ -174,6 +207,8 @@ var response = await client.path("/chat/completions").post({
174207
safe_mode: true
175208
}
176209
});
210+
211+
console.log(response.choices[0].message.content)
177212
```
178213

179214
# [REST](#tab/rest)
@@ -208,8 +243,8 @@ extra-parameters: pass-through
208243

209244
---
210245

211-
> [!TIP]
212-
> The default value for `extra-parameters` is `error` which returns an error if an extra parameter is indicated in the payload. Alternatively, you can set `extra-parameters: ignore` to drop any unknown parameter in the request. Use this capability in case you happen to be sending requests with extra parameters that you know the model won't support but you want the request to completes anyway. A typical example of this is indicating `seed` parameter.
246+
> [!NOTE]
247+
> The default value for `extra-parameters` is `error` which returns an error if an extra parameter is indicated in the payload. Alternatively, you can set `extra-parameters: drop` to drop any unknown parameter in the request. Use this capability in case you happen to be sending requests with extra parameters that you know the model won't support but you want the request to completes anyway. A typical example of this is indicating `seed` parameter.
213248
214249
### Models with disparate set of capabilities
215250

@@ -220,7 +255,7 @@ The following example shows the response for a chat completion request indicatin
220255
# [Python](#tab/python)
221256

222257
```python
223-
from azure.ai.inference.models import ChatCompletionsResponseFormat
258+
from azure.ai.inference.models import SystemMessage, UserMessage, ChatCompletionsResponseFormat
224259
from azure.core.exceptions import HttpResponseError
225260
import json
226261

0 commit comments

Comments
 (0)