Skip to content

Commit c5bc53a

Browse files
authored
Azure OpenAI: 2.0.0 stable release (#46378)
* initial cross-apply of 2.0.0 changes * minor: changelog update * correct Packages.Data.props * export-api * correct cross-repo assets.json change * prepare-release and assets re-fix * temporary exclusion for search projectref * exclusion via AOAI folder rather than search * exclusion from search test project * move exclusion to proper itemgroup * circumvent binarydata tostring issue on mac
1 parent 448d80d commit c5bc53a

File tree

112 files changed

+2097
-1346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2097
-1346
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
</ItemGroup>
176176

177177
<ItemGroup Condition="$(MSBuildProjectName.StartsWith('Azure.AI.OpenAI'))">
178-
<PackageReference Update="OpenAI" Version="2.0.0-beta.12" />
178+
<PackageReference Update="OpenAI" Version="2.0.0" />
179179
</ItemGroup>
180180

181181
<!--

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
# Release History
22

3+
## 2.0.0 (2024-09-30)
4+
5+
This update marks the first stable library version for `Azure.AI.OpenAI`. It snaps its dependency to `OpenAI`'s matched `2.0.0` stable version and targets the latest Azure OpenAI Service stable `api-version` label of `2024-06-01`. As a GA label, the `2.0.0` stable version exposes a subset of preview features, with preview library labels continuing to support preview features.
6+
7+
Specifically included in the GA library release:
8+
9+
- `AudioClient`, supporting transcription and translation using the `whisper` model
10+
- `ChatClient`, supporting chat completions, including Azure-specific features:
11+
- Embedded request and response content filter annotations
12+
- Azure Search and Cosmos DB data sources for Azure OpenAI On Your Data
13+
- `EmbeddingClient`, supporting `text-embedding` model embedding operations
14+
- `ImageClient`, supporting `dall-e-3` image generation
15+
16+
Assistants, Audio Generation, Batch, Files, Fine-Tuning, and Vector Stores are not yet included in the GA surface; they will continue to be available in preview library releases and the originating Azure OpenAI Service `api-version` labels.
17+
18+
### Breaking Changes
19+
20+
- `AzureOpenAIClient` constructors accepting `AzureKeyCredential` have been removed; please use the `ApiKeyCredential` constructors, instead. Note that `AzureKeyCredential` will inherit from `ApiKeyCredential` in a future update and that `AzureKeyCredential` has [a non-browsable Key property](https://github.com/Azure/azure-sdk-for-net/blob/448d80d80ad0f3df69b96df080da6cf8b537e9d2/sdk/core/Azure.Core/src/AzureKeyCredential.cs#L19) that may be used for conversion in the interim.
21+
- The `AzureOpenAIClientOptions` `ApplicationId` has been renamed to a more descriptive `UserAgentApplicationId`.
22+
23+
**From OpenAI 2.0.0 stable**
24+
25+
- Implemented `ChatMessageContent` to encapsulate the representation of content parts in `ChatMessage`, `ChatCompletion`, and `StreamingChatCompletionUpdate`. (commit_hash)
26+
- Changed the representation of function arguments to `BinaryData` in `ChatToolCall`, `StreamingChatToolCallUpdate`, `ChatFunctionCall`, and `StreamingChatFunctionCallUpdate`. (commit_hash)
27+
- Renamed `OpenAIClientOptions`'s `ApplicationId` to `UserAgentApplicationId` (commit_hash)
28+
- Renamed `StreamingChatToolCallUpdate`'s `Id` to `ToolCallId` (commit_hash)
29+
- Renamed `StreamingChatCompletionUpdate`'s `Id` to `CompletionId` (commit_hash)
30+
- Replaced `Auto` and `None` in the deprecated `ChatFunctionChoice` with `CreateAutoChoice()` and `CreateNoneChoice()` (commit_hash)
31+
- Replaced the deprecated `ChatFunctionChoice(ChatFunction)` constructor with `CreateNamedChoice(string functionName)` (commit_hash)
32+
- Renamed `FileClient` to `OpenAIFileClient` and the corresponding `GetFileClient()` method in `OpenAIClient` to `GetOpenAIFileClient()`. (commit_hash)
33+
- Renamed `ModelClient` to `OpenAIModelClient` and the corresponding `GetModelClient()` method in `OpenAIClient` to `GetOpenAIModelClient()`. (commit_hash)
34+
335
## 2.0.0-beta.6 (2024-09-23)
436

537
This version increments library compatibility to `OpenAI 2.0.0-beta.12`, including support for `o1` models with reasoning tokens and a number of breaking changes to method names.

sdk/openai/Azure.AI.OpenAI/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3+
<GAServiceVersionLabel>2024_06_01</GAServiceVersionLabel>
34
<!--
45
During development, we may want to get ahead of the published Nuget package versions. These next property flags
56
allow you to replace Nuget package references with external assembly .dll references, or even the source code

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

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ string keyFromEnvironment = Environment.GetEnvironmentVariable("AZURE_OPENAI_API
8888

8989
AzureOpenAIClient azureClient = new(
9090
new Uri("https://your-azure-openai-resource.com"),
91-
new AzureKeyCredential(keyFromEnvironment));
91+
new ApiKeyCredential(keyFromEnvironment));
9292
ChatClient chatClient = azureClient.GetChatClient("my-gpt-35-turbo-deployment");
9393
```
9494

@@ -319,10 +319,8 @@ tool call messages for assistant message history. Note that the model will ignor
319319
and that all streamed responses should map to a single, common choice index in the range of `[0..(ChoiceCount - 1)]`.
320320

321321
```C# Snippet:ChatTools:StreamingChatTools
322-
Dictionary<int, string> toolCallIdsByIndex = [];
323-
Dictionary<int, string> functionNamesByIndex = [];
324-
Dictionary<int, StringBuilder> functionArgumentBuildersByIndex = [];
325322
StringBuilder contentBuilder = new();
323+
StreamingChatToolCallsBuilder toolCallsBuilder = new();
326324

327325
foreach (StreamingChatCompletionUpdate streamingChatUpdate
328326
in chatClient.CompleteChatStreaming(conversationMessages, options))
@@ -331,40 +329,22 @@ foreach (StreamingChatCompletionUpdate streamingChatUpdate
331329
{
332330
contentBuilder.Append(contentPart.Text);
333331
}
332+
334333
foreach (StreamingChatToolCallUpdate toolCallUpdate in streamingChatUpdate.ToolCallUpdates)
335334
{
336-
if (!string.IsNullOrEmpty(toolCallUpdate.Id))
337-
{
338-
toolCallIdsByIndex[toolCallUpdate.Index] = toolCallUpdate.Id;
339-
}
340-
if (!string.IsNullOrEmpty(toolCallUpdate.FunctionName))
341-
{
342-
functionNamesByIndex[toolCallUpdate.Index] = toolCallUpdate.FunctionName;
343-
}
344-
if (!string.IsNullOrEmpty(toolCallUpdate.FunctionArgumentsUpdate))
345-
{
346-
StringBuilder argumentsBuilder
347-
= functionArgumentBuildersByIndex.TryGetValue(toolCallUpdate.Index, out StringBuilder existingBuilder)
348-
? existingBuilder
349-
: new();
350-
argumentsBuilder.Append(toolCallUpdate.FunctionArgumentsUpdate);
351-
functionArgumentBuildersByIndex[toolCallUpdate.Index] = argumentsBuilder;
352-
}
335+
toolCallsBuilder.Append(toolCallUpdate);
353336
}
354337
}
355338

356-
List<ChatToolCall> toolCalls = [];
357-
foreach (KeyValuePair<int, string> indexToIdPair in toolCallIdsByIndex)
339+
IReadOnlyList<ChatToolCall> toolCalls = toolCallsBuilder.Build();
340+
341+
AssistantChatMessage assistantMessage = new AssistantChatMessage(toolCalls);
342+
if (contentBuilder.Length > 0)
358343
{
359-
toolCalls.Add(ChatToolCall.CreateFunctionToolCall(
360-
indexToIdPair.Value,
361-
functionNamesByIndex[indexToIdPair.Key],
362-
functionArgumentBuildersByIndex[indexToIdPair.Key].ToString()));
344+
assistantMessage.Content.Add(ChatMessageContentPart.CreateTextPart(contentBuilder.ToString()));
363345
}
364346

365-
var assistantChatMessage = new AssistantChatMessage(toolCalls);
366-
assistantChatMessage.Content.Add(ChatMessageContentPart.CreateTextPart(contentBuilder.ToString()));
367-
conversationMessages.Add(assistantChatMessage);
347+
conversationMessages.Add(assistantMessage);
368348

369349
// Placeholder: each tool call must be resolved, like in the non-streaming case
370350
string GetToolCallOutput(ChatToolCall toolCall) => null;
@@ -404,13 +384,13 @@ ChatCompletion completion = chatClient.CompleteChat(
404384
],
405385
options);
406386

407-
AzureChatMessageContext onYourDataContext = completion.GetAzureMessageContext();
387+
ChatMessageContext onYourDataContext = completion.GetMessageContext();
408388

409389
if (onYourDataContext?.Intent is not null)
410390
{
411391
Console.WriteLine($"Intent: {onYourDataContext.Intent}");
412392
}
413-
foreach (AzureChatCitation citation in onYourDataContext?.Citations ?? [])
393+
foreach (ChatCitation citation in onYourDataContext?.Citations ?? [])
414394
{
415395
Console.WriteLine($"Citation: {citation.Content}");
416396
}
@@ -470,7 +450,7 @@ RunCreationOptions runOptions = new()
470450
AdditionalInstructions = "When possible, talk like a pirate."
471451
};
472452
await foreach (StreamingUpdate streamingUpdate
473-
in assistantClient.CreateRunStreamingAsync(thread, assistant, runOptions))
453+
in assistantClient.CreateRunStreamingAsync(thread.Id, assistant.Id, runOptions))
474454
{
475455
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
476456
{
@@ -492,8 +472,8 @@ reuse them later or, as demonstrated below, delete them when no longer desired.
492472

493473
```C# Snippet:Assistants:Cleanup
494474
// Optionally, delete persistent resources that are no longer needed.
495-
_ = await assistantClient.DeleteAssistantAsync(assistant);
496-
_ = await assistantClient.DeleteThreadAsync(thread);
475+
_ = await assistantClient.DeleteAssistantAsync(assistant.Id);
476+
_ = await assistantClient.DeleteThreadAsync(thread.Id);
497477
```
498478

499479
## Next steps

0 commit comments

Comments
 (0)