You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
109
+
110
+
__Request__
111
+
112
+
```HTTP/1.1
113
+
POST /chat/completions?api-version=2024-04-01-preview
114
+
Authorization: Bearer <bearer-token>
115
+
Content-Type: application/json
116
+
```
117
+
118
+
---
119
+
69
120
### Extensibility
70
121
71
122
The Azure AI Model Inference API specifies a set of modalities and parameters that models can subscribe to. However, some models may have further capabilities that the ones the API indicates. On those cases, the API allows the developer to pass them as extra parameters in the payload.
@@ -74,6 +125,38 @@ By setting a header `extra-parameters: allow`, the API will attempt to pass any
74
125
75
126
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:
76
127
128
+
# [REST](#tab/python)
129
+
130
+
```python
131
+
response = model.complete(
132
+
messages=[
133
+
SystemMessage(content="You are a helpful assistant."),
134
+
UserMessage(content="How many languages are in the world?"),
135
+
],
136
+
model_extras={
137
+
"safe_mode": True
138
+
}
139
+
)
140
+
```
141
+
142
+
# [REST](#tab/javascript)
143
+
144
+
```javascript
145
+
var messages = [
146
+
{ role:"system", content:"You are a helpful assistant" },
147
+
{ role:"user", content:"How many languages are in the world?" },
148
+
];
149
+
150
+
var response =awaitclient.path("/chat/completions").post({
151
+
body: {
152
+
messages: messages,
153
+
safe_mode:true
154
+
}
155
+
});
156
+
```
157
+
158
+
# [REST](#tab/rest)
159
+
77
160
__Request__
78
161
79
162
```HTTP/1.1
@@ -102,6 +185,8 @@ extra-parameters: allow
102
185
}
103
186
```
104
187
188
+
---
189
+
105
190
> [!TIP]
106
191
> 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.
107
192
@@ -111,6 +196,71 @@ The Azure AI Model Inference API indicates a general set of capabilities but eac
111
196
112
197
The following example shows the response for a chat completion request indicating the parameter `reponse_format` and asking for a reply in `JSON` format. In the example, since the model doesn't support such capability an error 422 is returned to the user.
113
198
199
+
# [REST](#tab/python)
200
+
201
+
```python
202
+
from azure.ai.inference.models import ChatCompletionsResponseFormat
203
+
from azure.core.exceptions import HttpResponseError
204
+
import json
205
+
206
+
try:
207
+
response = model.complete(
208
+
messages=[
209
+
SystemMessage(content="You are a helpful assistant."),
210
+
UserMessage(content="How many languages are in the world?"),
f"Looks like the model doesn't support the parameter '{param}' with value '{value}'"
223
+
)
224
+
else:
225
+
raise ex
226
+
```
227
+
228
+
# [REST](#tab/python)
229
+
230
+
```javascript
231
+
try {
232
+
var messages = [
233
+
{ role:"system", content:"You are a helpful assistant" },
234
+
{ role:"user", content:"How many languages are in the world?" },
235
+
];
236
+
237
+
var response =awaitclient.path("/chat/completions").post({
238
+
body: {
239
+
messages: messages,
240
+
response_format: { type:"json_object" }
241
+
}
242
+
});
243
+
}
244
+
catch (error) {
245
+
if (error.status_code==422) {
246
+
var response =JSON.parse(error.response._content)
247
+
if (response.detail) {
248
+
for (constoffendingofresponse.detail) {
249
+
var param =offending.loc.join(".")
250
+
var value =offending.input
251
+
console.log(`Looks like the model doesn't support the parameter '${param}' with value '${value}'`)
252
+
}
253
+
}
254
+
}
255
+
else
256
+
{
257
+
throw error
258
+
}
259
+
}
260
+
```
261
+
262
+
# [REST](#tab/rest)
263
+
114
264
__Request__
115
265
116
266
```HTTP/1.1
@@ -150,6 +300,7 @@ __Response__
150
300
"message": "One of the parameters contain invalid values."
151
301
}
152
302
```
303
+
---
153
304
154
305
> [!TIP]
155
306
> You can inspect the property `details.loc` to understand the location of the offending parameter and `details.input` to see the value that was passed in the request.
@@ -160,6 +311,65 @@ The Azure AI model inference API supports [Azure AI Content Safety](../concepts/
160
311
161
312
The following example shows the response for a chat completion request that has triggered content safety.
162
313
314
+
# [REST](#tab/python)
315
+
316
+
```python
317
+
from azure.ai.inference.models import AssistantMessage, UserMessage, SystemMessage
318
+
319
+
try:
320
+
response = model.complete(
321
+
messages=[
322
+
SystemMessage(content="You are an AI assistant that helps people find information."),
323
+
UserMessage(content="Chopping tomatoes and cutting them into cubes or wedges are great ways to practice your knife skills."),
console.log(`Your request triggered an ${response.error.code} error:\n\t${response.error.message}`)
362
+
}
363
+
else
364
+
{
365
+
throw error
366
+
}
367
+
}
368
+
}
369
+
```
370
+
371
+
# [REST](#tab/rest)
372
+
163
373
__Request__
164
374
165
375
```HTTP/1.1
@@ -196,95 +406,4 @@ __Response__
196
406
"type": null
197
407
}
198
408
```
199
-
200
-
## Getting started
201
-
202
-
The Azure AI Model Inference API is currently supported in models deployed as [Serverless API endpoints](../how-to/deploy-models-serverless.md). Deploy any of the [supported models](#availability) to a new [Serverless API endpoints](../how-to/deploy-models-serverless.md) to get started. Then you can consume the API in the following ways:
203
-
204
-
# [Studio](#tab/azure-studio)
205
-
206
-
You can use the Azure AI Model Inference API to run evaluations or while building with *Prompt flow*. Create a [Serverless Model connection](../how-to/deploy-models-serverless-connect.md) to a *Serverless API endpoint* and consume its predictions. The Azure AI Model Inference API is used under the hood.
207
-
208
-
# [Python](#tab/python)
209
-
210
-
Since the API is OpenAI-compatible, you can use any supported SDK that already supports Azure OpenAI. In the following example, we show how you can use LiteLLM with the common API:
"content": "Who is the most renowned French painter?",
224
-
"role": "user"
225
-
}
226
-
],
227
-
model="azureai",
228
-
custom_llm_provider="custom_openai",
229
-
)
230
-
231
-
print(response.choices[0].message.content)
232
-
```
233
-
234
-
# [REST](#tab/rest)
235
-
236
-
Models deployed in Azure Machine Learning and Azure AI studio in Serverless API endpoints support the Azure AI Model Inference API. Each endpoint exposes the OpenAPI specification for the modalities the model support. Use the **Endpoint URI** and the **Key** to download the OpenAPI definition for the model. In the following example, we download it from a bash console. Replace `<TOKEN>` by the **Key** and `<ENDPOINT_URI>` for the **Endpoint URI**.
0 commit comments