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
Copy file name to clipboardExpand all lines: articles/ai-foundry/model-inference/includes/use-chat-multi-modal/csharp.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,9 +62,6 @@ client = new ChatCompletionsClient(
62
62
63
63
Some models can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of Some models for vision in a chat fashion:
64
64
65
-
> [!IMPORTANT]
66
-
> Some models support only one image for each turn in the chat conversation and only the last image is retained in context. If you add multiple images, it results in an error.
67
-
68
65
To see this capability, download an image and encode the information as `base64` string. The resulting data should be inside of a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs):
69
66
70
67
@@ -126,6 +123,9 @@ Usage:
126
123
127
124
Images are broken into tokens and submitted to the model for processing. When referring to images, each of those tokens is typically referred as *patches*. Each model may break down a given image on a different number of patches. Read the model card to learn the details.
128
125
126
+
> [!IMPORTANT]
127
+
> Some models support only one image for each turn in the chat conversation and only the last image is retained in context. If you add multiple images, it results in an error.
128
+
129
129
## Use chat completions with audio
130
130
131
131
Some models can reason across text and audio inputs. The following example shows how you can send audio context to chat completions models that also supports audio. Use `InputAudio` to load the content of the audio file into the payload. The content is encoded in `base64` data and sent over the payload.
ASSISTANT: Thechartillustratesthatlargermodelstendtoperformbetterinquality, asindicatedbytheirsizeinbillionsofparameters. However, thereareexceptionstothistrend, suchasPhi-3-mediumandPhi-3-small, whichoutperformsmallermodelsinquality. Thissuggeststhatwhilelargermodelsgenerallyhaveanadvantage, theremightbeotherfactorsatplaythatinfluenceamodel's performance.
161
-
Model: Phi-4-multimodal-instruct
162
-
Usage:
163
-
Prompttokens:2380
164
-
Completiontokens:126
165
-
Totaltokens:2506
160
+
ASSISTANT: Hola. ¿Cómoestás?
161
+
Model:speech
162
+
Usage:
163
+
Prompttokens:77
164
+
Completiontokens:7
165
+
Totaltokens:84
166
166
```
167
167
168
168
Themodelcanreadthecontentfroman**accessiblecloudlocation**bypassingtheURLasaninput. ThePythonSDKdoesn't provide a direct way to do it, but you can indicate the payload as follows:
* A chat completions model deployment with support for **audio and images**. If you don't have one read [Add and configure models to Azure AI services](../../how-to/create-model-deployments.md) to add a chat completions model to your resource.
30
+
31
+
* This tutorial uses `Phi-4-multimodal-instruct`.
32
+
33
+
## Use chat completions
34
+
35
+
First, create the client to consume the model. The following code uses an endpoint URL and key that are stored in environment variables.
Some models can reason across text and images and generate text completions based on both kinds of input. In this section, you explore the capabilities of some models for vision in a chat fashion.
59
+
60
+
To see this capability, download an image and encode the information as `base64` string. The resulting data should be inside of a [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs):
:::image type="content" source="../../../../ai-foundry/media/how-to/sdks/small-language-models-chart-example.jpg" alt-text="A chart displaying the relative capabilities between large language models and small language models." lightbox="../../../../ai-foundry/media/how-to/sdks/small-language-models-chart-example.jpg":::
82
+
83
+
Now, create a chat completion request with the image:
84
+
85
+
86
+
```javascript
87
+
var messages = [
88
+
{ role:"system", content:"You are a helpful assistant that can generate responses based on images." },
89
+
{ role:"user", content:
90
+
[
91
+
{ type:"text", text:"Which conclusion can be extracted from the following chart?" },
92
+
{ type:"image_url", image:
93
+
{
94
+
url: data_url
95
+
}
96
+
}
97
+
]
98
+
}
99
+
];
100
+
101
+
var response =awaitclient.path("/chat/completions").post({
102
+
body: {
103
+
messages: messages,
104
+
model:"Phi-4-multimodal-instruct",
105
+
}
106
+
});
107
+
```
108
+
109
+
The response is as follows, where you can see the model's usage statistics:
ASSISTANT: The chart illustrates that larger models tend to perform better in quality, as indicated by their size in billions of parameters. However, there are exceptions to this trend, such as Phi-3-medium and Phi-3-small, which outperform smaller models in quality. This suggests that while larger models generally have an advantage, there might be other factors at play that influence a model's performance.
123
+
Model: Phi-4-multimodal-instruct
124
+
Usage:
125
+
Prompt tokens: 2380
126
+
Completion tokens: 126
127
+
Total tokens: 2506
128
+
```
129
+
130
+
Images are broken into tokens and submitted to the model for processing. When referring to images, each of those tokens is typically referred as *patches*. Each model may break down a given image on a different number of patches. Read the model card to learn the details.
131
+
132
+
> [!IMPORTANT]
133
+
> Some models support only one image for each turn in the chat conversation and only the last image is retained in context. If you add multiple images, it results in an error.
134
+
135
+
## Use chat completions with audio
136
+
137
+
Some models can reason across text and audio inputs. The following example shows how you can send audio context to chat completions models that also supports audio.
138
+
139
+
In this example, we create a function `getAudioData` to load the content of the audio file encoded in `base64` data as the model expects it.
140
+
141
+
```javascript
142
+
importfsfrom"node:fs";
143
+
144
+
/**
145
+
* Get the Base 64 data of an audio file.
146
+
* @param{string}audioFile - The path to the image file.
147
+
* @returns{string} Base64 data of the audio.
148
+
*/
149
+
functiongetAudioData(audioFile:string): string {
150
+
try {
151
+
constaudioBuffer=fs.readFileSync(audioFile);
152
+
returnaudioBuffer.toString("base64");
153
+
} catch (error) {
154
+
console.error(`Could not read '${audioFile}'.`);
155
+
console.error("Set the correct path to the audio file before running this sample.");
156
+
process.exit(1);
157
+
}
158
+
}
159
+
```
160
+
161
+
Let's now use this function to load the content of an audio file stored on disk. We send the content of the audio file in a user message. Notice that in the request we also indicate the format of the audio content:
162
+
163
+
```javascript
164
+
constaudioFilePath="hello_how_are_you.mp3"
165
+
constaudioFormat="mp3"
166
+
constaudioData=getAudioData(audioFilePath);
167
+
168
+
constsystemMessage= { role:"system", content:"You are an AI assistant for translating and transcribing audio clips." };
169
+
constaudioMessage= {
170
+
role:"user",
171
+
content: [
172
+
{ type:"text", text:"Translate this audio snippet to spanish."},
The model can read the content from an **accessible cloud location** by passing the URL as an input. The Python SDK doesn't provide a direct way to do it, but you can indicate the payload as follows:
218
+
219
+
```javascript
220
+
constsystemMessage= { role:"system", content:"You are a helpful assistant." };
Audio is broken into tokens and submitted to the model for processing. Some models may operate directly over audio tokens while other may use internal modules to perform speech-to-text, resulting in different strategies to compute tokens. Read the model card for details about how each model operates.
Copy file name to clipboardExpand all lines: articles/ai-foundry/model-inference/includes/use-chat-multi-modal/python.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -213,3 +213,5 @@ response = client.complete(
213
213
}
214
214
)
215
215
```
216
+
217
+
Audio is broken into tokens and submitted to the model for processing. Some models may operate directly over audio tokens while other may use internal modules to perform speech-to-text, resulting in different strategies to compute tokens. Read the model card for details about how each model operates.
Copy file name to clipboardExpand all lines: articles/ai-foundry/model-inference/includes/use-chat-multi-modal/rest.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -240,4 +240,6 @@ The response is as follows, where you can see the model's usage statistics:
240
240
"total_tokens": 84
241
241
}
242
242
}
243
-
```
243
+
```
244
+
245
+
Audio is broken into tokens and submitted to the model for processing. Some models may operate directly over audio tokens while other may use internal modules to perform speech-to-text, resulting in different strategies to compute tokens. Read the model card for details about how each model operates.
0 commit comments