Skip to content

Commit

Permalink
Fix amazon warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerBarreto committed Jan 6, 2025
1 parent 7503b39 commit cf968f5
Show file tree
Hide file tree
Showing 34 changed files with 150 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ public async Task GetStreamingChatMessageContentsAsyncShouldReturnStreamedChatMe
var chatHistory = CreateSampleChatHistory();

// Act
List<StreamingChatMessageContent> output = new();
List<StreamingChatMessageContent> output = [];
var result = service.GetStreamingChatMessageContentsAsync(chatHistory).ConfigureAwait(true);

// Assert
int iterations = 0;
await foreach (var item in result)
{
iterations += 1;
iterations++;
Assert.NotNull(item);
Assert.NotNull(item.Content);
Assert.NotNull(item.Role);
Expand Down Expand Up @@ -399,7 +399,7 @@ private ConverseResponse CreateConverseResponse(string text, ConversationRole ro
Message = new Message
{
Role = role,
Content = new List<ContentBlock> { new() { Text = text } }
Content = [new() { Text = text }]
}
},
Metrics = new ConverseMetrics(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ public async Task GetTextContentsAsyncShouldReturnTextContentsAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new TitanTextResponse
{
InputTextTokenCount = 5,
Results = new List<TitanTextResponse.Result>
{
Results =
[
new() {
TokenCount = 10,
OutputText = "This is a mock output.",
CompletionReason = "stop"
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -200,14 +200,14 @@ public async Task GetStreamingTextContentsAsyncShouldReturnStreamedTextContentsA
var service = kernel.GetRequiredService<ITextGenerationService>();

// Act
List<StreamingTextContent> result = new();
List<StreamingTextContent> result = [];
var output = service.GetStreamingTextContentsAsync(prompt).ConfigureAwait(true);

// Assert
int iterations = 0;
await foreach (var item in output)
{
iterations += 1;
iterations++;
Assert.NotNull(item);
Assert.NotNull(item.Text);
result.Add(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task ExecutionSettingsExtensionDataShouldOverridePropertyAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task TitanExecutionSettingsShouldSetExtensionDataAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -199,7 +199,7 @@ public async Task TitanExecutionSettingsShouldSetPropertiesAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -258,7 +258,7 @@ public async Task ClaudePromptExecutionSettingsExtensionDataSetsProperlyAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task ClaudePromptExecutionSettingsSetsPropertiesAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -371,7 +371,7 @@ public async Task LlamaGetChatMessageContentsAsyncShouldReturnChatMessageWithPro
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -429,7 +429,7 @@ public async Task CommandRExecutionSettingsShouldSetExtensionDataAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -484,7 +484,7 @@ public async Task CommandRExecutionSettingsShouldSetPropertiesAsync()
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down Expand Up @@ -544,7 +544,7 @@ public async Task JambaGetChatMessageContentsAsyncShouldReturnChatMessageWithPro
Message = new Message
{
Role = ConversationRole.Assistant,
Content = new List<ContentBlock> { new() { Text = "I'm doing well." } }
Content = [new() { Text = "I'm doing well." }]
}
},
Metrics = new ConverseMetrics(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
using Moq;
using Xunit;

#pragma warning disable RCS1261 // Resource can be disposed asynchronously

namespace Microsoft.SemanticKernel.Connectors.Amazon.UnitTests;

/// <summary>
Expand Down Expand Up @@ -154,14 +156,14 @@ public async Task TitanExecutionSettingsExtensionDataSetsProperlyAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new TitanTextResponse
{
InputTextTokenCount = 5,
Results = new List<TitanTextResponse.Result>
{
Results =
[
new() {
TokenCount = 10,
OutputText = "This is a mock output.",
CompletionReason = "stop"
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -224,7 +226,7 @@ public async Task TitanExecutionSettingsPropertySetsProperlyAsync()
Temperature = 0.1f,
TopP = 0.95f,
MaxTokenCount = 256,
StopSequences = new List<string> { "</end>" },
StopSequences = ["</end>"],
ModelId = modelId,
};
mockBedrockApi.Setup(m => m.DetermineServiceOperationEndpoint(It.IsAny<InvokeModelRequest>()))
Expand All @@ -249,14 +251,14 @@ public async Task TitanExecutionSettingsPropertySetsProperlyAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new TitanTextResponse
{
InputTextTokenCount = 5,
Results = new List<TitanTextResponse.Result>
{
Results =
[
new() {
TokenCount = 10,
OutputText = "This is a mock output.",
CompletionReason = "stop"
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -350,8 +352,8 @@ public async Task JambaExecutionSettingsExtensionDataSetsProperlyAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new AI21JambaResponse.AI21TextResponse
{
Id = "my-request-id",
Choices = new List<AI21JambaResponse.Choice>
{
Choices =
[
new() {
Index = 0,
Message = new AI21JambaResponse.Message
Expand All @@ -361,7 +363,7 @@ public async Task JambaExecutionSettingsExtensionDataSetsProperlyAsync()
},
FinishReason = "stop"
}
},
],
Usage = new AI21JambaResponse.JambaUsage
{
PromptTokens = 10,
Expand Down Expand Up @@ -441,7 +443,7 @@ public async Task JambaExecutionSettingsPropertySetsProperlyAsync()
Temperature = 0.8f,
TopP = 0.95f,
MaxTokens = 256,
Stop = new List<string> { "</end>" },
Stop = ["</end>"],
NumberOfResponses = 1,
FrequencyPenalty = 0.0,
PresencePenalty = 0.0,
Expand Down Expand Up @@ -469,8 +471,8 @@ public async Task JambaExecutionSettingsPropertySetsProperlyAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new AI21JambaResponse.AI21TextResponse
{
Id = "my-request-id",
Choices = new List<AI21JambaResponse.Choice>
{
Choices =
[
new() {
Index = 0,
Message = new AI21JambaResponse.Message
Expand All @@ -480,7 +482,7 @@ public async Task JambaExecutionSettingsPropertySetsProperlyAsync()
},
FinishReason = "stop"
}
},
],
Usage = new AI21JambaResponse.JambaUsage
{
PromptTokens = 10,
Expand Down Expand Up @@ -588,16 +590,16 @@ public async Task JurassicExecutionSettingsExtensionDataSetsProperlyAsync()
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new AI21JurassicResponse
{
Id = 10000000000,
Completions = new List<AI21JurassicResponse.Completion>
{
Completions =
[
new()
{
Data = new AI21JurassicResponse.JurassicData
{
Text = "Hello! This is a mock AI21 response."
}
}
}
]
})))
});
var kernel = Kernel.CreateBuilder().AddBedrockTextGenerationService(modelId, mockBedrockApi.Object).Build();
Expand Down Expand Up @@ -773,15 +775,15 @@ public async Task CommandExecutionSettingsSetsExtensionDataAsync()
{
Id = "my-request-id",
Prompt = "Write a greeting.",
Generations = new List<CommandResponse.Generation>
{
Generations =
[
new() {
Id = "generation-id",
Text = "Hello! This is a mock Cohere Command response.",
FinishReason = "COMPLETE",
IsFinished = true
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -839,7 +841,7 @@ public async Task CommandExecutionSettingsPropertySetsProperlyAsync()
Temperature = 0.8,
TopP = 0.95,
MaxTokens = 256,
StopSequences = new List<string> { "</end>" },
StopSequences = ["</end>"],
ModelId = modelId
};
mockBedrockApi.Setup(m => m.DetermineServiceOperationEndpoint(It.IsAny<InvokeModelRequest>()))
Expand All @@ -865,15 +867,15 @@ public async Task CommandExecutionSettingsPropertySetsProperlyAsync()
{
Id = "my-request-id",
Prompt = "Write a greeting.",
Generations = new List<CommandResponse.Generation>
{
Generations =
[
new() {
Id = "generation-id",
Text = "Hello! This is a mock Cohere Command response.",
FinishReason = "COMPLETE",
IsFinished = true
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -957,13 +959,13 @@ public async Task MistralExecutionSettingsSetExtensionDataAsync()
{
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new MistralResponse
{
Outputs = new List<MistralResponse.Output>
{
Outputs =
[
new() {
Text = "Hello! This is a mock Mistral response.",
StopReason = "stop_sequence"
}
}
]
}))),
ContentType = "application/json"
});
Expand Down Expand Up @@ -1040,13 +1042,13 @@ public async Task MistralExecutionSettingsPropertiesSetAsync()
{
Body = new MemoryStream(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(new MistralResponse
{
Outputs = new List<MistralResponse.Output>
{
Outputs =
[
new() {
Text = "Hello! This is a mock Mistral response.",
StopReason = "stop_sequence"
}
}
]
}))),
ContentType = "application/json"
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ internal sealed class BedrockClientUtilities
/// <returns>The ActivityStatusCode for the Semantic Kernel</returns>
internal static ActivityStatusCode ConvertHttpStatusCodeToActivityStatusCode(HttpStatusCode httpStatusCode)
{
if ((int)httpStatusCode >= 200 && (int)httpStatusCode < 300)
if ((int)httpStatusCode is >= 200 and < 300)
{
// 2xx status codes represent success
return ActivityStatusCode.Ok;
}
if ((int)httpStatusCode >= 400 && (int)httpStatusCode < 600)
if ((int)httpStatusCode is >= 400 and < 600)
{
// 4xx and 5xx status codes represent errors
return ActivityStatusCode.Error;
Expand Down
Loading

0 comments on commit cf968f5

Please sign in to comment.