Skip to content

Commit

Permalink
OpenAI-DotNet 7.3.1
Browse files Browse the repository at this point in the history
- Fixed json serialization settings when EnableDebug is disabled
  • Loading branch information
StephenHodgson committed Nov 21, 2023
1 parent 08e95b4 commit 72c5ace
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
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
19 changes: 11 additions & 8 deletions OpenAI-DotNet/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public OpenAIClient(OpenAIAuthentication openAIAuthentication = null, OpenAIClie
throw new AuthenticationException("You must provide API authentication. Please refer to https://github.com/RageAgainstThePixel/OpenAI-DotNet#authentication for details.");
}

JsonSerializationOptions = DefaultJsonSerializerOptions;
Client = SetupClient(client);
ModelsEndpoint = new ModelsEndpoint(this);
CompletionsEndpoint = new CompletionsEndpoint(this);
Expand Down Expand Up @@ -107,10 +108,18 @@ 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 JsonSerializationOptions { get; private set; }

internal static JsonSerializerOptions DefaultJsonSerializerOptions { get; } = new JsonSerializerOptions
{
WriteIndented = false,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverterFactory() }
};

private static JsonSerializerOptions DebugJsonSerializerOptions { get; } = new JsonSerializerOptions
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverterFactory() }
};
Expand All @@ -136,15 +145,9 @@ public bool EnableDebug
set
{
enableDebug = value;

JsonSerializationOptions = enableDebug
? DefaultJsonSerializerOptions
: new JsonSerializerOptions
{
WriteIndented = enableDebug,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Converters = { new JsonStringEnumConverterFactory() }
};
: DebugJsonSerializerOptions;
}
}

Expand Down

0 comments on commit 72c5ace

Please sign in to comment.