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-services/openai/how-to/integrate-synapseml.md
+76-7Lines changed: 76 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,9 +35,9 @@ This tutorial shows how to apply large language models at a distributed scale by
35
35
- To install SynapseML for your Apache Spark cluster, see [Install SynapseML](#install-synapseml).
36
36
37
37
> [!NOTE]
38
-
> This article is designed to work with the [Azure OpenAI Service legacy models](/azure/ai-services/openai/concepts/legacy-models) like `Text-Davinci-003`, which support prompt-based completions. Newer models like the current `GPT-3.5 Turbo` and `GPT-4` model series are designed to work with the new chat completion API that expects a specially formatted array of messages as input.
38
+
> The `OpenAICompletion()` transformer is designed to work with the [Azure OpenAI Service legacy models](/azure/ai-services/openai/concepts/legacy-models) like `Text-Davinci-003`, which supports prompt-based completions. Newer models like the current `GPT-3.5 Turbo` and `GPT-4` model series are designed to work with the new chat completion API that expects a specially formatted array of messages as input. If you working with embeddings or chat completion models, please check the [Chat Completion](#chat-completion) and [Generating Text Embeddings](#generating-text-embeddings) sections bellow.
39
39
>
40
-
> The Azure OpenAI SynapseML integration supports the latest models via the [OpenAIChatCompletion()](https://github.com/microsoft/SynapseML/blob/0836e40efd9c48424e91aa10c8aa3fbf0de39f31/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/cognitive/openai/OpenAIChatCompletion.scala#L24) transformer, which isn't demonstrated in this article. After the [release of the GPT-3.5 Turbo Instruct model](https://techcommunity.microsoft.com/t5/azure-ai-services-blog/announcing-updates-to-azure-openai-service-models/ba-p/3866757), the newer model will be the preferred model to use with this article.
40
+
> The Azure OpenAI SynapseML integration supports the latest models via the [OpenAIChatCompletion()](https://github.com/microsoft/SynapseML/blob/0836e40efd9c48424e91aa10c8aa3fbf0de39f31/cognitive/src/main/scala/com/microsoft/azure/synapse/ml/cognitive/openai/OpenAIChatCompletion.scala#L24) transformer.
41
41
42
42
We recommend that you [create an Azure Synapse workspace](../../../synapse-analytics/get-started-create-workspace.md). However, you can also use Azure Databricks, Azure HDInsight, Spark on Kubernetes, or the Python environment with the `pyspark` package.
43
43
@@ -187,15 +187,87 @@ The following image shows example output with completions in Azure Synapse Analy
187
187
188
188
Here are some other use cases for working with Azure OpenAI Service and large datasets.
189
189
190
-
### Improve throughput with request batching
190
+
### Generating Text Embeddings
191
+
192
+
In addition to completing text, we can also embed text for use in downstream algorithms or vector retrieval architectures. Creating embeddings allows you to search and retrieve documents from large collections and can be used when prompt engineering isn't sufficient for the task. For more information on using [OpenAIEmbedding](https://mmlspark.blob.core.windows.net/docs/0.11.1/pyspark/_modules/synapse/ml/cognitive/openai/OpenAIEmbedding.html), see our [embedding guide](https://microsoft.github.io/SynapseML/docs/Explore%20Algorithms/OpenAI/Quickstart%20-%20OpenAI%20Embedding/).
193
+
194
+
from synapse.ml.services.openai import OpenAIEmbedding
195
+
196
+
```python
197
+
embedding = (
198
+
OpenAIEmbedding()
199
+
.setSubscriptionKey(key)
200
+
.setDeploymentName(deployment_name_embeddings)
201
+
.setCustomServiceName(service_name)
202
+
.setTextCol("prompt")
203
+
.setErrorCol("error")
204
+
.setOutputCol("embeddings")
205
+
)
206
+
207
+
display(embedding.transform(df))
208
+
```
209
+
210
+
### Chat Completion
211
+
Models such as ChatGPT and GPT-4 are capable of understanding chats instead of single prompts. The [OpenAIChatCompletion](https://mmlspark.blob.core.windows.net/docs/0.11.1/pyspark/_modules/synapse/ml/cognitive/openai/OpenAIChatCompletion.html) transformer exposes this functionality at scale.
212
+
213
+
```python
214
+
from synapse.ml.services.openai import OpenAIChatCompletion
215
+
from pyspark.sql import Row
216
+
from pyspark.sql.types import*
217
+
218
+
219
+
defmake_message(role, content):
220
+
return Row(role=role, content=content, name=role)
221
+
222
+
223
+
chat_df = spark.createDataFrame(
224
+
[
225
+
(
226
+
[
227
+
make_message(
228
+
"system", "You are an AI chatbot with red as your favorite color"
229
+
),
230
+
make_message("user", "Whats your favorite color"),
### Improve throughput with request batching from OpenAICompletion
191
260
192
261
You can use Azure OpenAI Service with large datasets to improve throughput with request batching. In the previous example, you make several requests to the service, one for each prompt. To complete multiple prompts in a single request, you can use batch mode.
193
262
194
-
In the `OpenAICompletion` object definition, you specify the `"batchPrompt"` value to configure the dataframe to use a **batchPrompt** column. Create the dataframe with a list of prompts for each row.
263
+
In the [OpenAItCompletion](https://mmlspark.blob.core.windows.net/docs/0.11.1/pyspark/_modules/synapse/ml/cognitive/openai/OpenAICompletion.html) object definition, you specify the `"batchPrompt"` value to configure the dataframe to use a **batchPrompt** column. Create the dataframe with a list of prompts for each row.
195
264
196
265
> [!NOTE]
197
266
> There's currently a limit of 20 prompts in a single request and a limit of 2048 tokens, or approximately 1500 words.
198
267
268
+
> [!NOTE]
269
+
> Currently, request batching is not supported by the `OpenAIChatCompletion()` transformer.
> There's currently a limit of 20 prompts in a single request and a limit of 2048 tokens, or approximately 1500 words.
232
-
233
302
### Use an automatic mini-batcher
234
303
235
304
You can use Azure OpenAI Service with large datasets to transpose the data format. If your data is in column format, you can transpose it to row format by using the SynapseML `FixedMiniBatcherTransformer` object.
0 commit comments