Skip to content

Commit

Permalink
Address some more analyzer warnings (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Jun 14, 2024
1 parent 1af6569 commit 22ab606
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/Custom/Assistants/AssistantResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ internal AssistantResponseFormat(string plainTextValue, string objectType, IDict
/// <inheritdoc />
public static implicit operator AssistantResponseFormat(string value)
{
if (string.Equals(value, AutoValue, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(value, AutoValue, StringComparison.OrdinalIgnoreCase))
{
return Auto;
}
if (string.Equals(value, TextValue, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(value, TextValue, StringComparison.OrdinalIgnoreCase))
{
return Text;
}
if (string.Equals(value, JsonObjectValue, StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(value, JsonObjectValue, StringComparison.OrdinalIgnoreCase))
{
return JsonObject;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Custom/Audio/AudioTranscription.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public partial class AudioTranscription
internal static AudioTranscription FromResponse(PipelineResponse response)
{
// Customization: handle plain text responses (SRT/VTT formats)
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && contentType.StartsWith("text/plain"))
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true &&
contentType.StartsWith("text/plain", StringComparison.Ordinal))
{
return new AudioTranscription(
InternalCreateTranscriptionResponseVerboseJsonTask.Transcribe,
Expand Down
3 changes: 2 additions & 1 deletion src/Custom/Audio/AudioTranslation.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public partial class AudioTranslation
internal static AudioTranslation FromResponse(PipelineResponse response)
{
// Customization: handle plain text responses (SRT/VTT formats)
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && contentType.StartsWith("text/plain"))
if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true &&
contentType.StartsWith("text/plain", StringComparison.Ordinal))
{
return new AudioTranslation(
InternalCreateTranslationResponseVerboseJsonTask.Translate,
Expand Down
5 changes: 3 additions & 2 deletions src/Custom/Chat/ChatCompletionOptions.Serialization.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text.Json;

Expand Down Expand Up @@ -49,7 +50,7 @@ private void SerializeLogitBiasesValue(Utf8JsonWriter writer)
writer.WriteStartObject();
foreach (var item in LogitBiases)
{
writer.WritePropertyName(item.Key.ToString());
writer.WritePropertyName(item.Key.ToString(CultureInfo.InvariantCulture));
writer.WriteNumberValue(item.Value);
}
writer.WriteEndObject();
Expand All @@ -68,7 +69,7 @@ private static void DeserializeLogitBiasesValue(JsonProperty property, ref IDict
Dictionary<int, int> dictionary = new Dictionary<int, int>();
foreach (var property0 in property.Value.EnumerateObject())
{
dictionary.Add(int.Parse(property0.Name), property0.Value.GetInt32());
dictionary.Add(int.Parse(property0.Name, CultureInfo.InvariantCulture), property0.Value.GetInt32());
}
logitBias = dictionary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ internal partial class InternalChatCompletionRequestMessageContentPartImageImage
private static readonly Regex s_parseDataUriRegex = new(@"^data:(?<type>.+?);base64,(?<data>.+)$", RegexOptions.Compiled);
#endif

private readonly Uri _imageUri = default;
private readonly BinaryData _imageBytes = default;
private readonly string _imageBytesMediaType = default;
private readonly Uri _imageUri;
private readonly BinaryData _imageBytes;
private readonly string _imageBytesMediaType;

// CUSTOM: Changed type from Uri to string to be able to support data URIs properly.
/// <summary> Either a URL of the image or the base64 encoded image data. </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Custom/Embeddings/Embedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal Embedding(int index, BinaryData embeddingProperty, InternalEmbeddingObj
public ReadOnlyMemory<float> Vector { get; }

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

Expand Down
19 changes: 0 additions & 19 deletions src/Custom/OpenAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,6 @@ public partial class OpenAIClient
{
private readonly OpenAIClientOptions _options;

// CUSTOM: Applied the Experimental attribute as needed.
private AudioClient _cachedAudioClient;
[Experimental("OPENAI001")]
private AssistantClient _cachedAssistantClient;
private BatchClient _cachedBatchClient;
private ChatClient _cachedChatClient;
private LegacyCompletionClient _cachedLegacyCompletionClient;
private EmbeddingClient _cachedEmbeddingClient;
private FileClient _cachedFileClient;
private FineTuningClient _cachedFineTuningClient;
private ImageClient _cachedImageClient;
private InternalAssistantMessageClient _cachedInternalAssistantMessageClient;
private ModelClient _cachedModelClient;
private ModerationClient _cachedModerationClient;
private InternalAssistantRunClient _cachedInternalAssistantRunClient;
private InternalAssistantThreadClient _cachedInternalAssistantThreadClient;
[Experimental("OPENAI001")]
private VectorStoreClient _cachedVectorStoreClient;

/// <summary>
/// The configured connection endpoint.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Custom/OpenAIError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ OpenAIErrorResponse errorResponse
public string ToExceptionMessage(int httpStatus)
{
StringBuilder messageBuilder = new();
messageBuilder.AppendLine($"HTTP {httpStatus} ({Type}: {Code})");
messageBuilder.Append("HTTP ").Append(httpStatus).Append(" (").Append(Type).Append(": ").Append(Code).AppendLine(")");
if (!string.IsNullOrEmpty(Param))
{
messageBuilder.AppendLine($"Parameter: {Param}");
messageBuilder.Append("Parameter: ").AppendLine(Param);
}
messageBuilder.AppendLine();
messageBuilder.Append(Message);
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Generator/CodeGenClientAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI;

[AttributeUsage(AttributeTargets.Class)]
internal class CodeGenClientAttribute : CodeGenTypeAttribute
internal sealed class CodeGenClientAttribute : CodeGenTypeAttribute
{
public Type? ParentClient { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Generator/CodeGenMemberAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI;

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
internal class CodeGenMemberAttribute : CodeGenTypeAttribute
internal sealed class CodeGenMemberAttribute : CodeGenTypeAttribute
{
public CodeGenMemberAttribute() : base(null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Generator/CodeGenModelAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct)]
internal class CodeGenModelAttribute : CodeGenTypeAttribute
internal sealed class CodeGenModelAttribute : CodeGenTypeAttribute
{
/// <summary>
/// Gets or sets a coma separated list of additional model usage modes. Allowed values: model, error, intput, output.
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Generator/CodeGenSerializationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace OpenAI;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = true, Inherited = true)]
internal class CodeGenSerializationAttribute : Attribute
internal sealed class CodeGenSerializationAttribute : Attribute
{
/// <summary>
/// Gets or sets the property name which these hooks should apply to
Expand Down
2 changes: 1 addition & 1 deletion src/Utility/Generator/CodeGenSuppressAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace OpenAI;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct, AllowMultiple = true)]
internal class CodeGenSuppressAttribute : Attribute
internal sealed class CodeGenSuppressAttribute : Attribute
{
public string Member { get; }
public Type[] Parameters { get; }
Expand Down

0 comments on commit 22ab606

Please sign in to comment.