Skip to content

Commit

Permalink
feat: Added OpenAIClient.RemoveCharSetFromContentType.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Apr 29, 2024
1 parent e45c6fe commit 7174f1b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<PropertyGroup Label="Nuget">
<Version>2.0.7</Version>
<Version>2.0.8</Version>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>tryAGI and contributors</Authors>
Expand Down
8 changes: 7 additions & 1 deletion src/libs/OpenAI/Client/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ public static StringContent ToJsonStringContent(this string json, bool debug)
Console.WriteLine(json);
}

return new StringContent(json, OpenAIClient.DefaultEncoding, jsonContent);
var content = new StringContent(json, OpenAIClient.DefaultEncoding, jsonContent);
if (OpenAIClient.RemoveCharSetFromContentType)
{
content.Headers.ContentType.CharSet = string.Empty;
}

return content;
}

public static string ToSnakeCase(string @string)
Expand Down
7 changes: 6 additions & 1 deletion src/libs/OpenAI/Client/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ namespace OpenAI
public sealed class OpenAIClient : IDisposable
{
/// <summary>
///
/// Default encoding to use when making calls to the API.
/// </summary>
public static Encoding? DefaultEncoding { get; set; } = Encoding.UTF8;

/// <summary>
/// Remove the charset from the content type.
/// </summary>
public static bool RemoveCharSetFromContentType { get; set; }

/// <summary>
/// Creates a new entry point to the OpenAPI API, handling auth and allowing access to the various API endpoints
/// </summary>
Expand Down

0 comments on commit 7174f1b

Please sign in to comment.