Skip to content

Commit 22ab606

Browse files
authored
Address some more analyzer warnings (#47)
1 parent 1af6569 commit 22ab606

13 files changed

+21
-37
lines changed

src/Custom/Assistants/AssistantResponseFormat.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ internal AssistantResponseFormat(string plainTextValue, string objectType, IDict
7373
/// <inheritdoc />
7474
public static implicit operator AssistantResponseFormat(string value)
7575
{
76-
if (string.Equals(value, AutoValue, StringComparison.InvariantCultureIgnoreCase))
76+
if (string.Equals(value, AutoValue, StringComparison.OrdinalIgnoreCase))
7777
{
7878
return Auto;
7979
}
80-
if (string.Equals(value, TextValue, StringComparison.InvariantCultureIgnoreCase))
80+
if (string.Equals(value, TextValue, StringComparison.OrdinalIgnoreCase))
8181
{
8282
return Text;
8383
}
84-
if (string.Equals(value, JsonObjectValue, StringComparison.InvariantCultureIgnoreCase))
84+
if (string.Equals(value, JsonObjectValue, StringComparison.OrdinalIgnoreCase))
8585
{
8686
return JsonObject;
8787
}

src/Custom/Audio/AudioTranscription.Serialization.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public partial class AudioTranscription
99
internal static AudioTranscription FromResponse(PipelineResponse response)
1010
{
1111
// Customization: handle plain text responses (SRT/VTT formats)
12-
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && contentType.StartsWith("text/plain"))
12+
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true &&
13+
contentType.StartsWith("text/plain", StringComparison.Ordinal))
1314
{
1415
return new AudioTranscription(
1516
InternalCreateTranscriptionResponseVerboseJsonTask.Transcribe,

src/Custom/Audio/AudioTranslation.Serialization.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public partial class AudioTranslation
99
internal static AudioTranslation FromResponse(PipelineResponse response)
1010
{
1111
// Customization: handle plain text responses (SRT/VTT formats)
12-
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && contentType.StartsWith("text/plain"))
12+
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true &&
13+
contentType.StartsWith("text/plain", StringComparison.Ordinal))
1314
{
1415
return new AudioTranslation(
1516
InternalCreateTranslationResponseVerboseJsonTask.Translate,

src/Custom/Chat/ChatCompletionOptions.Serialization.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Globalization;
23
using System.Runtime.CompilerServices;
34
using System.Text.Json;
45

@@ -49,7 +50,7 @@ private void SerializeLogitBiasesValue(Utf8JsonWriter writer)
4950
writer.WriteStartObject();
5051
foreach (var item in LogitBiases)
5152
{
52-
writer.WritePropertyName(item.Key.ToString());
53+
writer.WritePropertyName(item.Key.ToString(CultureInfo.InvariantCulture));
5354
writer.WriteNumberValue(item.Value);
5455
}
5556
writer.WriteEndObject();
@@ -68,7 +69,7 @@ private static void DeserializeLogitBiasesValue(JsonProperty property, ref IDict
6869
Dictionary<int, int> dictionary = new Dictionary<int, int>();
6970
foreach (var property0 in property.Value.EnumerateObject())
7071
{
71-
dictionary.Add(int.Parse(property0.Name), property0.Value.GetInt32());
72+
dictionary.Add(int.Parse(property0.Name, CultureInfo.InvariantCulture), property0.Value.GetInt32());
7273
}
7374
logitBias = dictionary;
7475
}

src/Custom/Chat/Internal/InternalChatCompletionRequestMessageContentPartImageImageUrl.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ internal partial class InternalChatCompletionRequestMessageContentPartImageImage
1616
private static readonly Regex s_parseDataUriRegex = new(@"^data:(?<type>.+?);base64,(?<data>.+)$", RegexOptions.Compiled);
1717
#endif
1818

19-
private readonly Uri _imageUri = default;
20-
private readonly BinaryData _imageBytes = default;
21-
private readonly string _imageBytesMediaType = default;
19+
private readonly Uri _imageUri;
20+
private readonly BinaryData _imageBytes;
21+
private readonly string _imageBytesMediaType;
2222

2323
// CUSTOM: Changed type from Uri to string to be able to support data URIs properly.
2424
/// <summary> Either a URL of the image or the base64 encoded image data. </summary>

src/Custom/Embeddings/Embedding.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ internal Embedding(int index, BinaryData embeddingProperty, InternalEmbeddingObj
9191
public ReadOnlyMemory<float> Vector { get; }
9292

9393
// CUSTOM: Implemented custom logic to transform from BinaryData to ReadOnlyMemory<float>.
94-
private ReadOnlyMemory<float> ConvertToVectorOfFloats(BinaryData binaryData)
94+
private static ReadOnlyMemory<float> ConvertToVectorOfFloats(BinaryData binaryData)
9595
{
9696
ReadOnlySpan<byte> base64 = binaryData.ToMemory().Span;
9797

src/Custom/OpenAIClient.cs

-19
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,6 @@ public partial class OpenAIClient
4646
{
4747
private readonly OpenAIClientOptions _options;
4848

49-
// CUSTOM: Applied the Experimental attribute as needed.
50-
private AudioClient _cachedAudioClient;
51-
[Experimental("OPENAI001")]
52-
private AssistantClient _cachedAssistantClient;
53-
private BatchClient _cachedBatchClient;
54-
private ChatClient _cachedChatClient;
55-
private LegacyCompletionClient _cachedLegacyCompletionClient;
56-
private EmbeddingClient _cachedEmbeddingClient;
57-
private FileClient _cachedFileClient;
58-
private FineTuningClient _cachedFineTuningClient;
59-
private ImageClient _cachedImageClient;
60-
private InternalAssistantMessageClient _cachedInternalAssistantMessageClient;
61-
private ModelClient _cachedModelClient;
62-
private ModerationClient _cachedModerationClient;
63-
private InternalAssistantRunClient _cachedInternalAssistantRunClient;
64-
private InternalAssistantThreadClient _cachedInternalAssistantThreadClient;
65-
[Experimental("OPENAI001")]
66-
private VectorStoreClient _cachedVectorStoreClient;
67-
6849
/// <summary>
6950
/// The configured connection endpoint.
7051
/// </summary>

src/Custom/OpenAIError.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ OpenAIErrorResponse errorResponse
3535
public string ToExceptionMessage(int httpStatus)
3636
{
3737
StringBuilder messageBuilder = new();
38-
messageBuilder.AppendLine($"HTTP {httpStatus} ({Type}: {Code})");
38+
messageBuilder.Append("HTTP ").Append(httpStatus).Append(" (").Append(Type).Append(": ").Append(Code).AppendLine(")");
3939
if (!string.IsNullOrEmpty(Param))
4040
{
41-
messageBuilder.AppendLine($"Parameter: {Param}");
41+
messageBuilder.Append("Parameter: ").AppendLine(Param);
4242
}
4343
messageBuilder.AppendLine();
4444
messageBuilder.Append(Message);

src/Utility/Generator/CodeGenClientAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace OpenAI;
66

77
[AttributeUsage(AttributeTargets.Class)]
8-
internal class CodeGenClientAttribute : CodeGenTypeAttribute
8+
internal sealed class CodeGenClientAttribute : CodeGenTypeAttribute
99
{
1010
public Type? ParentClient { get; set; }
1111

src/Utility/Generator/CodeGenMemberAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace OpenAI;
66

77
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
8-
internal class CodeGenMemberAttribute : CodeGenTypeAttribute
8+
internal sealed class CodeGenMemberAttribute : CodeGenTypeAttribute
99
{
1010
public CodeGenMemberAttribute() : base(null)
1111
{

src/Utility/Generator/CodeGenModelAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace OpenAI;
66

77
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct)]
8-
internal class CodeGenModelAttribute : CodeGenTypeAttribute
8+
internal sealed class CodeGenModelAttribute : CodeGenTypeAttribute
99
{
1010
/// <summary>
1111
/// Gets or sets a coma separated list of additional model usage modes. Allowed values: model, error, intput, output.

src/Utility/Generator/CodeGenSerializationAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace OpenAI;
66

77
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
8-
internal class CodeGenSerializationAttribute : Attribute
8+
internal sealed class CodeGenSerializationAttribute : Attribute
99
{
1010
/// <summary>
1111
/// Gets or sets the property name which these hooks should apply to

src/Utility/Generator/CodeGenSuppressAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace OpenAI;
44

55
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct, AllowMultiple = true)]
6-
internal class CodeGenSuppressAttribute : Attribute
6+
internal sealed class CodeGenSuppressAttribute : Attribute
77
{
88
public string Member { get; }
99
public Type[] Parameters { get; }

0 commit comments

Comments
 (0)