Skip to content

Commit d8a1e49

Browse files
authored
AOAI: beta-7 changelog, readme, sample snippet (Azure#38371)
1 parent 70c5d14 commit d8a1e49

File tree

3 files changed

+121
-6
lines changed

3 files changed

+121
-6
lines changed

sdk/openai/Azure.AI.OpenAI/CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Release History
22

3-
## 1.0.0-beta.7 (Unreleased)
3+
## 1.0.0-beta.7 (2023-08-25)
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- The Azure OpenAI "using your own data" feature is now supported. See [the Azure OpenAI using your own data quickstart](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart) for conceptual background and detailed setup instructions.
8+
- Azure OpenAI chat extensions are configured via a new `AzureChatExtensionsOptions` property on `ChatCompletionsOptions`. When an `AzureChatExtensionsOptions` is provided, configured requests will only work with clients configured to use the Azure OpenAI service, as the capabilities are unique to that service target.
9+
- `AzureChatExtensionsOptions` then has `AzureChatExtensionConfiguration` instances added to its `Extensions` property, with these instances representing the supplementary information needed for Azure OpenAI to use desired data sources to supplement chat completions behavior.
10+
- `ChatChoice` instances on a `ChatCompletions` response value that used chat extensions will then also have their `Message` property supplemented by an `AzureChatExtensionMessageContext` instance. This context contains a collection of supplementary `Messages` that describe the behavior of extensions that were used and supplementary response data, such as citations, provided along with the response.
11+
- See the README sample snippet for a simplified example of request/response use with "using your own data"
1212

1313
## 1.0.0-beta.6 (2023-07-19)
1414

sdk/openai/Azure.AI.OpenAI/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,54 @@ if (responseChoice.FinishReason == CompletionsFinishReason.FunctionCall)
330330
}
331331
```
332332

333+
### Use your own data with Azure OpenAI
334+
335+
The use your own data feature is unique to Azure OpenAI and won't work with a client configured to use the non-Azure service.
336+
See [the Azure OpenAI using your own data quickstart](https://learn.microsoft.com/azure/ai-services/openai/use-your-data-quickstart) for conceptual background and detailed setup instructions.
337+
338+
```C# Snippet:ChatUsingYourOwnData
339+
var chatCompletionsOptions = new ChatCompletionsOptions()
340+
{
341+
Messages =
342+
{
343+
new ChatMessage(
344+
ChatRole.System,
345+
"You are a helpful assistant that answers questions about the Contoso product database."),
346+
new ChatMessage(ChatRole.User, "What are the best-selling Contoso products this month?")
347+
},
348+
// The addition of AzureChatExtensionsOptions enables the use of Azure OpenAI capabilities that add to
349+
// the behavior of Chat Completions, here the "using your own data" feature to supplement the context
350+
// with information from an Azure Cognitive Search resource with documents that have been indexed.
351+
AzureExtensionsOptions = new AzureChatExtensionsOptions()
352+
{
353+
Extensions =
354+
{
355+
new AzureCognitiveSearchChatExtensionConfiguration()
356+
{
357+
SearchEndpoint = new Uri("https://your-contoso-search-resource.search.windows.net"),
358+
IndexName = "contoso-products-index",
359+
SearchKey = new AzureKeyCredential("<your Cognitive Search resource API key>"),
360+
}
361+
}
362+
}
363+
};
364+
Response<ChatCompletions> response = await client.GetChatCompletionsAsync(
365+
"gpt-35-turbo-0613",
366+
chatCompletionsOptions);
367+
ChatMessage message = response.Value.Choices[0].Message;
368+
// The final, data-informed response still appears in the ChatMessages as usual
369+
Console.WriteLine($"{message.Role}: {message.Content}");
370+
// Responses that used extensions will also have Context information that includes special Tool messages
371+
// to explain extension activity and provide supplemental information like citations.
372+
Console.WriteLine($"Citations and other information:");
373+
foreach (ChatMessage contextMessage in message.AzureExtensionsContext.Messages)
374+
{
375+
// Note: citations and other extension payloads from the "tool" role are often encoded JSON documents
376+
// and need to be parsed as such; that step is omitted here for brevity.
377+
Console.WriteLine($"{contextMessage.Role}: {contextMessage.Content}");
378+
}
379+
```
380+
333381
### Generate images with DALL-E image generation models
334382

335383
```C# Snippet:GenerateImages
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Text.Json;
8+
using System.Threading.Tasks;
9+
using Azure.Identity;
10+
using NUnit.Framework;
11+
12+
namespace Azure.AI.OpenAI.Tests.Samples
13+
{
14+
public partial class StreamingChat
15+
{
16+
[Test]
17+
[Ignore("Only verifying that the sample builds")]
18+
public async Task ChatUsingYourOwnData()
19+
{
20+
string endpoint = "https://myaccount.openai.azure.com/";
21+
var client = new OpenAIClient(new Uri(endpoint), new DefaultAzureCredential());
22+
23+
#region Snippet:ChatUsingYourOwnData
24+
var chatCompletionsOptions = new ChatCompletionsOptions()
25+
{
26+
Messages =
27+
{
28+
new ChatMessage(
29+
ChatRole.System,
30+
"You are a helpful assistant that answers questions about the Contoso product database."),
31+
new ChatMessage(ChatRole.User, "What are the best-selling Contoso products this month?")
32+
},
33+
// The addition of AzureChatExtensionsOptions enables the use of Azure OpenAI capabilities that add to
34+
// the behavior of Chat Completions, here the "using your own data" feature to supplement the context
35+
// with information from an Azure Cognitive Search resource with documents that have been indexed.
36+
AzureExtensionsOptions = new AzureChatExtensionsOptions()
37+
{
38+
Extensions =
39+
{
40+
new AzureCognitiveSearchChatExtensionConfiguration()
41+
{
42+
SearchEndpoint = new Uri("https://your-contoso-search-resource.search.windows.net"),
43+
IndexName = "contoso-products-index",
44+
SearchKey = new AzureKeyCredential("<your Cognitive Search resource API key>"),
45+
}
46+
}
47+
}
48+
};
49+
Response<ChatCompletions> response = await client.GetChatCompletionsAsync(
50+
"gpt-35-turbo-0613",
51+
chatCompletionsOptions);
52+
ChatMessage message = response.Value.Choices[0].Message;
53+
// The final, data-informed response still appears in the ChatMessages as usual
54+
Console.WriteLine($"{message.Role}: {message.Content}");
55+
// Responses that used extensions will also have Context information that includes special Tool messages
56+
// to explain extension activity and provide supplemental information like citations.
57+
Console.WriteLine($"Citations and other information:");
58+
foreach (ChatMessage contextMessage in message.AzureExtensionsContext.Messages)
59+
{
60+
// Note: citations and other extension payloads from the "tool" role are often encoded JSON documents
61+
// and need to be parsed as such; that step is omitted here for brevity.
62+
Console.WriteLine($"{contextMessage.Role}: {contextMessage.Content}");
63+
}
64+
#endregion
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)