Skip to content

Commit

Permalink
OpenAI-DotNet 7.3.1 (#175)
Browse files Browse the repository at this point in the history
- Fixed json serialization settings when EnableDebug is disabled
  • Loading branch information
StephenHodgson authored Nov 21, 2023
1 parent 08e95b4 commit 0dfda4b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion OpenAI-DotNet-Tests/TestFixture_08_Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task Test_01_UploadFile()
{
Assert.IsNotNull(OpenAIClient.FilesEndpoint);
var testData = new Conversation(new List<Message> { new Message(Role.Assistant, "I'm a learning language model") });
await File.WriteAllTextAsync("test.jsonl", JsonSerializer.Serialize(testData, OpenAIClient.DefaultJsonSerializerOptions));
await File.WriteAllTextAsync("test.jsonl", JsonSerializer.Serialize(testData, OpenAIClient.JsonSerializationOptions));
Assert.IsTrue(File.Exists("test.jsonl"));
var result = await OpenAIClient.FilesEndpoint.UploadFileAsync("test.jsonl", "fine-tune");
Assert.IsNotNull(result);
Expand Down
2 changes: 1 addition & 1 deletion OpenAI-DotNet-Tests/TestFixture_09_FineTuning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private async Task<FileResponse> CreateTestTrainingDataAsync()
})
};
const string localTrainingDataPath = "fineTunesTestTrainingData.jsonl";
await File.WriteAllLinesAsync(localTrainingDataPath, conversations.Select(conversation => JsonSerializer.Serialize(conversation, OpenAIClient.DefaultJsonSerializerOptions)));
await File.WriteAllLinesAsync(localTrainingDataPath, conversations.Select(conversation => JsonSerializer.Serialize(conversation, OpenAIClient.JsonSerializationOptions)));
var fileData = await OpenAIClient.FilesEndpoint.UploadFileAsync(localTrainingDataPath, "fine-tune");
File.Delete(localTrainingDataPath);
Assert.IsFalse(File.Exists(localTrainingDataPath));
Expand Down
6 changes: 4 additions & 2 deletions OpenAI-DotNet/OpenAI-DotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ More context [on Roger Pincombe's blog](https://rogerpincombe.com/openai-dotnet-
<RepositoryUrl>https://github.com/RageAgainstThePixel/OpenAI-DotNet</RepositoryUrl>
<PackageTags>OpenAI, AI, ML, API, gpt-4, gpt-3.5-tubo, gpt-3, chatGPT, chat-gpt, gpt-2, gpt, dall-e-2, dall-e-3</PackageTags>
<Title>OpenAI API</Title>
<Version>7.3.0</Version>
<PackageReleaseNotes>Version 7.3.0
<Version>7.3.1</Version>
<PackageReleaseNotes>Version 7.3.1
- Fixed json serialization settings when EnableDebug is disabled
Version 7.3.0
- Added AgentsEndpoint
- Added ThreadsEndpoint
- Updated ImagesEndpoint return types to ImageResult list
Expand Down
24 changes: 2 additions & 22 deletions OpenAI-DotNet/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ private HttpClient SetupClient(HttpClient client = null)
/// <summary>
/// The <see cref="JsonSerializationOptions"/> to use when making calls to the API.
/// </summary>
internal static JsonSerializerOptions JsonSerializationOptions { get; private set; } = DefaultJsonSerializerOptions;

internal static JsonSerializerOptions DefaultJsonSerializerOptions { get; } = new JsonSerializerOptions
internal static JsonSerializerOptions JsonSerializationOptions { get; } = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverterFactory() }
Expand All @@ -125,28 +123,10 @@ private HttpClient SetupClient(HttpClient client = null)
/// </summary>
internal OpenAIClientSettings OpenAIClientSettings { get; }

private bool enableDebug;

/// <summary>
/// Enables or disables debugging for all endpoints.
/// </summary>
public bool EnableDebug
{
get => enableDebug;
set
{
enableDebug = value;

JsonSerializationOptions = enableDebug
? DefaultJsonSerializerOptions
: new JsonSerializerOptions
{
WriteIndented = enableDebug,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverterFactory() }
};
}
}
public bool EnableDebug { get; set; }

/// <summary>
/// List and describe the various models available in the API.
Expand Down

0 comments on commit 0dfda4b

Please sign in to comment.