1.0.0-beta.9 (2023-11-06)
Breaking Changes
This update includes a number of version-to-version breaking changes to the API.
Streaming for completions and chat completions
Streaming Completions and Streaming Chat Completions have been significantly updated to use simpler, shallower usage
patterns and data representations. The goal of these changes is to make streaming much easier to consume in common
cases while still retaining full functionality in more complex ones (e.g. with multiple choices requested).
- A new
StreamingResponse<T>
type is introduced that implicitly exposes anIAsyncEnumerable<T>
derived from
the underlying response. OpenAI.GetCompletionsStreaming()
now returns aStreamingResponse<Completions>
that may be directly
enumerated over.StreamingCompletions
,StreamingChoice
, and the corresponding methods are removed.- Because Chat Completions use a distinct structure for their streaming response messages, a new
StreamingChatCompletionsUpdate
type is introduced that encapsulates this update data. - Correspondingly,
OpenAI.GetChatCompletionsStreaming()
now returns a
StreamingResponse<StreamingChatCompletionsUpdate>
that may be enumerated over directly.
StreamingChatCompletions
,StreamingChatChoice
, and related methods are removed. - For more information, please see
the related pull request description as well as the
updated snippets in the project README.
deploymentOrModelName
moved to *Options.DeploymentName
deploymentOrModelName
and related method parameters on OpenAIClient
have been moved to DeploymentName
properties in the corresponding method options. This is intended to promote consistency across scenario,
language, and Azure/non-Azure OpenAI use.
As an example, the following:
ChatCompletionsOptions chatCompletionsOptions = new()
{
Messages = { new(ChatRole.User, "Hello, assistant!") },
};
Response<ChatCompletions> response = client.GetChatCompletions("gpt-4", chatCompletionsOptions);
...is now re-written as:
ChatCompletionsOptions chatCompletionsOptions = new()
{
DeploymentName = "gpt-4",
Messages = { new(ChatRole.User, "Hello, assistant!") },
};
Response<ChatCompletions> response = client.GetChatCompletions(chatCompletionsOptions);
Consistency in complex method options type constructors
With the migration of DeploymentName
into method complex options types, these options types have now been snapped to
follow a common pattern: each complex options type will feature a default constructor that allows init
-style setting
of properties as well as a single additional constructor that accepts all required parameters for the corresponding
method. Existing constructors that no longer meet that "all" requirement, including those impacted by the addition of
DeploymentName
, have been removed. The "convenience" constructors that represented required parameter data
differently -- for example, EmbeddingsOptions(string)
, have also been removed in favor of the consistent "set of
directly provide" choice.
More exhaustively, removed are:
AudioTranscriptionOptions(BinaryData)
AudioTranslationOptions(BinaryData)
ChatCompletionsOptions(IEnumerable<ChatMessage>)
CompletionsOptions(IEnumerable<string>)
EmbeddingsOptions(string)
EmbeddingsOptions(IEnumerable<string>)
And added as replacements are:
AudioTranscriptionOptions(string, BinaryData)
AudioTranslationOptions(string, BinaryData)
ChatCompletionsOptions(string, IEnumerable<ChatMessage>)
CompletionsOptions(string, IEnumerable<string>)
EmbeddingsOptions(string, IEnumerable<string>)
Embeddings now represented as ReadOnlyMemory<float>
Changed the representation of embeddings (specifically, the type of the Embedding
property of the EmbeddingItem
class)
from IReadOnlyList<float>
to ReadOnlyMemory<float>
as part of a broader effort to establish consistency across the
.NET ecosystem.
SearchKey
and EmbeddingKey
properties replaced by SetSearchKey
and SetEmbeddingKey
methods
Replaced the SearchKey
and EmbeddingKey
properties of the AzureCognitiveSearchChatExtensionConfiguration
class with
new SetSearchKey
and SetEmbeddingKey
methods respectively. These methods simplify the configuration of the Azure Cognitive
Search chat extension by receiving a plain string instead of an AzureKeyCredential
, promote more sensible key and secret
management, and align with the Azure SDK guidelines.