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
- Refactored `ModerationResult` by merging `ModerationCategories` and `ModerationCategoryScores` into individual `ModerationCategory` properties, each with `Flagged` and `Score` properties.
- Renamed type `OpenAIFileInfo` to `OpenAIFile` and `OpenAIFileInfoCollection` to `OpenAIFileCollection`.
- Renamed type `OpenAIModelInfo` to `OpenAIModel` and `OpenAIModelInfoCollection` to `OpenAIModelCollection`.
- Renamed type `Embedding` to `OpenAIEmbedding` and `EmbeddingCollection` to `OpenAIEmbeddingCollection`.
- Renamed property `ImageUrl` to `ImageUri` and method `FromImageUrl` to `FromImageUri` in the `MessageContent` type.
- Renamed property `ParallelToolCallsEnabled` to `AllowParallelToolCalls` in the `RunCreationOptions`, `ThreadRun`, and `ChatCompletionOptions` types.
- Renamed properties `PromptTokens` to `InputTokenCount`, `CompletionTokens` to `OutputTokenCount`, and `TotalTokens` to `TotalTokenCount` in the `RunTokenUsage` and `RunStepTokenUsage` types.
- Renamed properties `InputTokens` to `InputTokenCount` and `TotalTokens` to `TotalTokenCount` in the `EmbeddingTokenUsage` type.
- Renamed properties `MaxPromptTokens` to `MaxInputTokenCount` and `MaxCompletionTokens` to `MaxOutputTokenCount` in the `ThreadRun`, `RunCreationOptions`, and `RunIncompleteReason` types.
- Removed the `virtual` keyword from the `Pipeline` property across all clients.
- Renamed the `Granularities` property of `AudioTranscriptionOptions` to `TimestampGranularities`.
- Changed `AudioTranscriptionFormat` from an enum to an "extensible enum".
- Changed `AudioTranslationFormat` from an enum to an "extensible enum".
- Changed `GenerateImageFormat` from an enum to an "extensible enum".
- Changed `GeneratedImageQuality` from an enum to an "extensible enum".
- Changed `GeneratedImageStyle` from an enum to an "extensible enum".
- Removed method overloads in `AssistantClient` and `VectorStoreClient` that take complex parameters in favor of methods that take simple string IDs.
- Updated the `TokenIds` property type in the `TranscribedSegment` type from `IReadOnlyList<int>` to `ReadOnlyMemory<int>`.
- Updated the `inputs` parameter type in the `GenerateEmbeddings` and `GenerateEmbeddingsAsync` methods of `EmbeddingClient` from `IEnumerable<IEnumerable<int>>` to `IEnumerable<ReadOnlyMemory<int>>`.
- Changed `ChatMessageContentPartKind` from an extensible enum to an enum.
- Changed `ChatToolCallKind` from an extensible enum to an enum.
- Changed `ChatToolKind` from an extensible enum to an enum.
- Changed `OpenAIFilePurpose` from an extensible enum to an enum.
- Changed `OpenAIFileStatus` from an extensible enum to an enum.
- Renamed `OpenAIFilePurpose` to `FilePurpose`.
- Renamed `OpenAIFileStatus` to `FileStatus`.
- Removed constructors that take string API key and options.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+27-10Lines changed: 27 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,16 +6,33 @@
6
6
7
7
### Breaking Changes
8
8
9
-
- Refactored `ModerationResult` by merging `ModerationCategories` and `ModerationCategoryScores` into individual `ModerationCategory` properties, each with `Flagged` and `Score` properties. (commit_id)
10
-
- Renamed type `OpenAIFileInfo` to `OpenAIFile` and `OpenAIFileInfoCollection` to `OpenAIFileCollection`. (commit_id)
11
-
- Renamed type `OpenAIModelInfo` to `OpenAIModel` and `OpenAIModelInfoCollection` to `OpenAIModelCollection`. (commit_id)
12
-
- Renamed type `Embedding` to `OpenAIEmbedding` and `EmbeddingCollection` to `OpenAIEmbeddingCollection`. (commit_id)
13
-
- Renamed property `ImageUrl` to `ImageUri` and method `FromImageUrl` to `FromImageUri` in the `MessageContent` type. (commit_id)
14
-
- Renamed property `ParallelToolCallsEnabled` to `AllowParallelToolCalls` in the `RunCreationOptions`, `ThreadRun`, and `ChatCompletionOptions` types. (commit_id)
15
-
- Renamed properties `PromptTokens` to `InputTokenCount`, `CompletionTokens` to `OutputTokenCount`, and `TotalTokens` to `TotalTokenCount` in the `RunTokenUsage` and `RunStepTokenUsage` types. (commit_id)
16
-
- Renamed properties `InputTokens` to `InputTokenCount` and `TotalTokens` to `TotalTokenCount` in the `EmbeddingTokenUsage` type. (commit_id)
17
-
- Renamed properties `MaxPromptTokens` to `MaxInputTokenCount` and `MaxCompletionTokens` to `MaxOutputTokenCount` in the `ThreadRun`, `RunCreationOptions`, and `RunIncompleteReason` types. (commit_id)
18
-
- Removed the `virtual` keyword from the `Pipeline` property across all clients. (commit_id)
9
+
- Refactored `ModerationResult` by merging `ModerationCategories` and `ModerationCategoryScores` into individual `ModerationCategory` properties, each with `Flagged` and `Score` properties. (commit_hash)
10
+
- Renamed type `OpenAIFileInfo` to `OpenAIFile` and `OpenAIFileInfoCollection` to `OpenAIFileCollection`. (commit_hash)
11
+
- Renamed type `OpenAIModelInfo` to `OpenAIModel` and `OpenAIModelInfoCollection` to `OpenAIModelCollection`. (commit_hash)
12
+
- Renamed type `Embedding` to `OpenAIEmbedding` and `EmbeddingCollection` to `OpenAIEmbeddingCollection`. (commit_hash)
13
+
- Renamed property `ImageUrl` to `ImageUri` and method `FromImageUrl` to `FromImageUri` in the `MessageContent` type. (commit_hash)
14
+
- Renamed property `ParallelToolCallsEnabled` to `AllowParallelToolCalls` in the `RunCreationOptions`, `ThreadRun`, and `ChatCompletionOptions` types. (commit_hash)
15
+
- Renamed properties `PromptTokens` to `InputTokenCount`, `CompletionTokens` to `OutputTokenCount`, and `TotalTokens` to `TotalTokenCount` in the `RunTokenUsage` and `RunStepTokenUsage` types. (commit_hash)
16
+
- Renamed properties `InputTokens` to `InputTokenCount` and `TotalTokens` to `TotalTokenCount` in the `EmbeddingTokenUsage` type. (commit_hash)
17
+
- Renamed properties `MaxPromptTokens` to `MaxInputTokenCount` and `MaxCompletionTokens` to `MaxOutputTokenCount` in the `ThreadRun`, `RunCreationOptions`, and `RunIncompleteReason` types. (commit_hash)
18
+
- Removed the `virtual` keyword from the `Pipeline` property across all clients. (commit_hash)
19
+
- Renamed the `Granularities` property of `AudioTranscriptionOptions` to `TimestampGranularities`. (commit_hash)
20
+
- Changed `AudioTranscriptionFormat` from an enum to an "extensible enum". (commit_hash)
21
+
- Changed `AudioTranslationFormat` from an enum to an "extensible enum". (commit_hash)
22
+
- Changed `GenerateImageFormat` from an enum to an "extensible enum". (commit_hash)
23
+
- Changed `GeneratedImageQuality` from an enum to an "extensible enum". (commit_hash)
24
+
- Changed `GeneratedImageStyle` from an enum to an "extensible enum". (commit_hash)
25
+
- Removed method overloads in `AssistantClient` and `VectorStoreClient` that take complex parameters in favor of methods that take simple string IDs. (commit_hash)
26
+
- Updated the `TokenIds` property type in the `TranscribedSegment` type from `IReadOnlyList<int>` to `ReadOnlyMemory<int>`. (commit_hash)
27
+
- Updated the `inputs` parameter type in the `GenerateEmbeddings` and `GenerateEmbeddingsAsync` methods of `EmbeddingClient` from `IEnumerable<IEnumerable<int>>` to `IEnumerable<ReadOnlyMemory<int>>`. (commit_hash)
28
+
- Changed `ChatMessageContentPartKind` from an extensible enum to an enum. (commit_hash)
29
+
- Changed `ChatToolCallKind` from an extensible enum to an enum. (commit_hash)
30
+
- Changed `ChatToolKind` from an extensible enum to an enum. (commit_hash)
31
+
- Changed `OpenAIFilePurpose` from an extensible enum to an enum. (commit_hash)
32
+
- Changed `OpenAIFileStatus` from an extensible enum to an enum. (commit_hash)
33
+
- Renamed `OpenAIFilePurpose` to `FilePurpose`. (commit_hash)
34
+
- Renamed `OpenAIFileStatus` to `FileStatus`. (commit_hash)
35
+
- Removed constructors that take string API key and options. (commit_hash)
Notice that the resulting embedding is a list (also called a vector) of floating point numbers represented as an instance of `ReadOnlyMemory<float>`. By default, the length of the embedding vector will be 1536 when using the `text-embedding-3-small` model or 3072 when using the `text-embedding-3-large` model. Generally, larger embeddings perform better, but using them also tends to cost more in terms of compute, memory, and storage. You can reduce the dimensions of the embedding by creating an instance of the `EmbeddingGenerationOptions` class, setting the `Dimensions` property, and passing it as an argument in your call to the `GenerateEmbedding` method:
Generating an image always requires a `prompt` that describes what should be generated. To further tailor the image generation to your specific needs, you can create an instance of the `ImageGenerationOptions` class and set the `Quality`, `Size`, and `Style` properties accordingly. Note that you can also set the `ResponseFormat` property of `ImageGenerationOptions` to `GeneratedImageFormat.Bytes` in order to receive the resulting PNG as `BinaryData` (instead of the default remote `Uri`) if this is convenient for your use case.
@@ -431,14 +432,14 @@ In this example, an audio file is transcribed using the Whisper speech-to-text m
@@ -516,7 +517,7 @@ using Stream document = BinaryData.FromString("""
516
517
Upload this document to OpenAI using the `FileClient`'s `UploadFile` method, ensuring that you use `FileUploadPurpose.Assistants` to allow your assistant to access it later:
517
518
518
519
```csharp
519
-
OpenAIFileInfosalesFile=fileClient.UploadFile(
520
+
OpenAIFilesalesFile=fileClient.UploadFile(
520
521
document,
521
522
"monthly_sales.json",
522
523
FileUploadPurpose.Assistants);
@@ -584,8 +585,8 @@ Finally, you can use the `AssistantClient`'s `GetMessages` method to retrieve th
584
585
For illustrative purposes, you could print the messages to the console and also save any images produced by the assistant to local storage:
For this example, we will use both image data from a local file as well as an image located at a URL. For the local data, we upload the file with the `Vision` upload purpose, which would also allow it to be downloaded and retrieved later.
With the assistant and thread prepared, use the `CreateRunStreaming` method to get an enumerable `CollectionResult<StreamingUpdate>`. You can then iterate over this collection with `foreach`. For async calling patterns, use `CreateRunStreamingAsync` and iterate over the `AsyncCollectionResult<StreamingUpdate>` with `await foreach`, instead. Note that streaming variants also exist for `CreateThreadAndRunStreaming` and `SubmitToolOutputsToRunStreaming`.
Notice how you can then call the resulting `ClientResult`'s `GetRawResponse` method and retrieve the response body as `BinaryData` via the `PipelineResponse`'s `Content` property.
797
799
800
+
### Mock a client for testing
801
+
802
+
The OpenAI .NET library has been designed to support mocking, providing key features such as:
803
+
- Client methods made virtual to allow overriding.
804
+
- Model factories to assist in instantiating API output models that lack public constructors.
805
+
806
+
To illustrate how mocking works, suppose you want to validate the behavior of the following method using the [Moq](https://github.com/devlooped/moq) library. Given the path to an audio file, it determines whether it contains a specified secret word:
Create mocks of `AudioClient` and `ClientResult<AudioTranscription>`, set up methods and properties that will be invoked, then test the behavior of the `ContainsSecretWord` method. Since the `AudioTranscription` class does not provide public constructors, it must be instantiated by the `OpenAIAudioModelFactory` static class:
817
+
818
+
```csharp
819
+
// Instantiate mocks and the AudioTranscription object.
All namespaces have their corresponding model factory to support mocking with the exception of the `OpenAI.Assistants` and `OpenAI.VectorStores` namespaces, for which model factories are coming soon.
845
+
798
846
### Automatically retrying errors
799
847
800
848
By default, the client classes will automatically retry the following errors up to three additional times using exponential backoff:
0 commit comments