From 05e9186ca0dce04516f6701902ad7336276f1ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bouteruche?= Date: Thu, 26 Oct 2023 13:32:08 +0200 Subject: [PATCH 1/5] Initial version of ListFoundationModelsExample project --- .../ListFoundationModels.cs | 235 ++++++++++++++++++ .../ListFoundationModelsExample.csproj | 14 ++ .../ListFoundationModelsExample.sln | 25 ++ 3 files changed, 274 insertions(+) create mode 100644 dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs create mode 100644 dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj create mode 100644 dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs new file mode 100644 index 00000000000..ca0f3b24fdd --- /dev/null +++ b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs @@ -0,0 +1,235 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System.Text; +using Amazon; +using Amazon.Bedrock; +using Amazon.Bedrock.Model; +using Amazon.Internal; +using Amazon.Runtime; + +namespace ListFoundationModelsExample +{ + internal class ListFoundationModels + { + static async Task Main(string[] args) + { + // Specify a region endpoint where Amazon Bedrock is available. For a list of supported region see https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html#bedrock-regions + AmazonBedrockClient client = new(RegionEndpoint.USWest2); + + await ListFoundationModelsWithNoFilter(client); + + await ListFoundationModelsSupportingFineTuning(client); + + await ListFoundationModelsSupportingProvisionedInference(client); + + await ListFoundationModelsSupportingOnDemandInference(client); + + await ListFoundationModelsSupportingTextOuput(client); + + await ListFoundationModelsSupportingImageOuput(client); + + await ListFoundationModelsSupportingEmbeddingOuput(client); + + await ListFoundationModelsSupportingProvisionedInferenceAndEmbeddingOutput(client); + + } + + private static async Task ListFoundationModelsWithNoFilter(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models with no filter"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingFineTuning(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting fine tuning"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByCustomizationType = ModelCustomization.FINE_TUNING + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingProvisionedInference(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting provisioned inference"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByInferenceType = InferenceType.PROVISIONED + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingOnDemandInference(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting on demand inference"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByInferenceType = InferenceType.ON_DEMAND + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingTextOuput(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting text Output"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByOutputModality = ModelModality.TEXT + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingImageOuput(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting image Output"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByOutputModality = ModelModality.IMAGE + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingEmbeddingOuput(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting embedding Output"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByOutputModality = ModelModality.EMBEDDING + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static async Task ListFoundationModelsSupportingProvisionedInferenceAndEmbeddingOutput(AmazonBedrockClient client) + { + Console.WriteLine("List foundation models supporting provisioned inference and embedding output"); + + ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + ByInferenceType = InferenceType.PROVISIONED, + ByOutputModality = ModelModality.EMBEDDING + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + + Console.WriteLine(); + } + + private static void WriteToConsole(FoundationModelSummary fm) + { + Console.WriteLine($"{fm.ModelId}, Customization: {String.Join(", ", fm.CustomizationsSupported)}, Stream: {fm.ResponseStreamingSupported}, Input: {String.Join(", ", fm.InputModalities)}, Output: {String.Join(", ", fm.OutputModalities)}"); + } + } +} \ No newline at end of file diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj new file mode 100644 index 00000000000..5d85c613b88 --- /dev/null +++ b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj @@ -0,0 +1,14 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln new file mode 100644 index 00000000000..020e0192888 --- /dev/null +++ b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34202.233 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListFoundationModelsExample", "ListFoundationModelsExample.csproj", "{51A011A9-2AEA-433D-A6B0-611216F955DF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {51A011A9-2AEA-433D-A6B0-611216F955DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {51A011A9-2AEA-433D-A6B0-611216F955DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {51A011A9-2AEA-433D-A6B0-611216F955DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {51A011A9-2AEA-433D-A6B0-611216F955DF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {86D7A4D8-43F7-42C9-AFE9-F8AB12A91A0B} + EndGlobalSection +EndGlobal From a1862f401f03850adff98e4f486ed0baea5b2e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bouteruche?= Date: Wed, 6 Dec 2023 10:28:00 +0100 Subject: [PATCH 2/5] Update code example to match other .NET code example structure --- .../ListFoundationModels.cs | 235 ------------------ .../ListFoundationModelsExample.sln | 25 -- ...lsExample.csproj => BedrockActions.csproj} | 6 +- dotnetv3/Bedrock/Actions/HelloBedrock.cs | 71 ++++++ dotnetv3/Bedrock/BedrockExamples.sln | 30 +++ 5 files changed, 104 insertions(+), 263 deletions(-) delete mode 100644 dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs delete mode 100644 dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln rename dotnetv3/Bedrock/Actions/{Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj => BedrockActions.csproj} (55%) create mode 100644 dotnetv3/Bedrock/Actions/HelloBedrock.cs create mode 100644 dotnetv3/Bedrock/BedrockExamples.sln diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs deleted file mode 100644 index ca0f3b24fdd..00000000000 --- a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModels.cs +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -using System.Text; -using Amazon; -using Amazon.Bedrock; -using Amazon.Bedrock.Model; -using Amazon.Internal; -using Amazon.Runtime; - -namespace ListFoundationModelsExample -{ - internal class ListFoundationModels - { - static async Task Main(string[] args) - { - // Specify a region endpoint where Amazon Bedrock is available. For a list of supported region see https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html#bedrock-regions - AmazonBedrockClient client = new(RegionEndpoint.USWest2); - - await ListFoundationModelsWithNoFilter(client); - - await ListFoundationModelsSupportingFineTuning(client); - - await ListFoundationModelsSupportingProvisionedInference(client); - - await ListFoundationModelsSupportingOnDemandInference(client); - - await ListFoundationModelsSupportingTextOuput(client); - - await ListFoundationModelsSupportingImageOuput(client); - - await ListFoundationModelsSupportingEmbeddingOuput(client); - - await ListFoundationModelsSupportingProvisionedInferenceAndEmbeddingOutput(client); - - } - - private static async Task ListFoundationModelsWithNoFilter(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models with no filter"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingFineTuning(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting fine tuning"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByCustomizationType = ModelCustomization.FINE_TUNING - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingProvisionedInference(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting provisioned inference"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByInferenceType = InferenceType.PROVISIONED - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingOnDemandInference(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting on demand inference"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByInferenceType = InferenceType.ON_DEMAND - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingTextOuput(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting text Output"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByOutputModality = ModelModality.TEXT - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingImageOuput(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting image Output"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByOutputModality = ModelModality.IMAGE - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingEmbeddingOuput(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting embedding Output"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByOutputModality = ModelModality.EMBEDDING - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static async Task ListFoundationModelsSupportingProvisionedInferenceAndEmbeddingOutput(AmazonBedrockClient client) - { - Console.WriteLine("List foundation models supporting provisioned inference and embedding output"); - - ListFoundationModelsResponse response = await client.ListFoundationModelsAsync(new ListFoundationModelsRequest() - { - ByInferenceType = InferenceType.PROVISIONED, - ByOutputModality = ModelModality.EMBEDDING - }); - - if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) - { - foreach (var fm in response.ModelSummaries) - { - WriteToConsole(fm); - } - } - else - { - Console.WriteLine("Something wrong happened"); - } - - Console.WriteLine(); - } - - private static void WriteToConsole(FoundationModelSummary fm) - { - Console.WriteLine($"{fm.ModelId}, Customization: {String.Join(", ", fm.CustomizationsSupported)}, Stream: {fm.ResponseStreamingSupported}, Input: {String.Join(", ", fm.InputModalities)}, Output: {String.Join(", ", fm.OutputModalities)}"); - } - } -} \ No newline at end of file diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln b/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln deleted file mode 100644 index 020e0192888..00000000000 --- a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.7.34202.233 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ListFoundationModelsExample", "ListFoundationModelsExample.csproj", "{51A011A9-2AEA-433D-A6B0-611216F955DF}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {51A011A9-2AEA-433D-A6B0-611216F955DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {51A011A9-2AEA-433D-A6B0-611216F955DF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {51A011A9-2AEA-433D-A6B0-611216F955DF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {51A011A9-2AEA-433D-A6B0-611216F955DF}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {86D7A4D8-43F7-42C9-AFE9-F8AB12A91A0B} - EndGlobalSection -EndGlobal diff --git a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj b/dotnetv3/Bedrock/Actions/BedrockActions.csproj similarity index 55% rename from dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj rename to dotnetv3/Bedrock/Actions/BedrockActions.csproj index 5d85c613b88..48756aef89f 100644 --- a/dotnetv3/Bedrock/Actions/Bedrock/ListFoundationModelsExample/ListFoundationModelsExample/ListFoundationModelsExample.csproj +++ b/dotnetv3/Bedrock/Actions/BedrockActions.csproj @@ -1,14 +1,14 @@ - + Exe - net7.0 + net8.0 enable enable - + diff --git a/dotnetv3/Bedrock/Actions/HelloBedrock.cs b/dotnetv3/Bedrock/Actions/HelloBedrock.cs new file mode 100644 index 00000000000..62f9a632947 --- /dev/null +++ b/dotnetv3/Bedrock/Actions/HelloBedrock.cs @@ -0,0 +1,71 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +// snippet-start:[Bedrock.dotnetv3.HelloBedrock] +using Amazon; +using Amazon.Bedrock; +using Amazon.Bedrock.Model; + +namespace ListFoundationModelsExample +{ + /// + /// This example shows how to list foundation models. + /// + internal class HelloBedrock + { + /// + /// Main method to call the ListFoundationModelsAsync method. + /// + /// The command line arguments. + static async Task Main(string[] args) + { + // Specify a region endpoint where Amazon Bedrock is available. For a list of supported region see https://docs.aws.amazon.com/bedrock/latest/userguide/what-is-bedrock.html#bedrock-regions + AmazonBedrockClient bedrockClient = new(RegionEndpoint.USWest2); + + await ListFoundationModelsAsync(bedrockClient); + + } + + /// + /// List foundation models. + /// + /// The Amazon Bedrock client. + private static async Task ListFoundationModelsAsync(AmazonBedrockClient bedrockClient) + { + Console.WriteLine("List foundation models with no filter"); + + try + { + ListFoundationModelsResponse response = await bedrockClient.ListFoundationModelsAsync(new ListFoundationModelsRequest() + { + }); + + if (response?.HttpStatusCode == System.Net.HttpStatusCode.OK) + { + foreach (var fm in response.ModelSummaries) + { + WriteToConsole(fm); + } + } + else + { + Console.WriteLine("Something wrong happened"); + } + } + catch(AmazonBedrockException e) + { + Console.WriteLine(e.Message); + } + } + + /// + /// Write the foundation model summary to console. + /// + /// The foundation model summary to write to console. + private static void WriteToConsole(FoundationModelSummary foundationModel) + { + Console.WriteLine($"{foundationModel.ModelId}, Customization: {String.Join(", ", foundationModel.CustomizationsSupported)}, Stream: {foundationModel.ResponseStreamingSupported}, Input: {String.Join(", ", foundationModel.InputModalities)}, Output: {String.Join(", ", foundationModel.OutputModalities)}"); + } + } +} +// snippet-end:[Bedrock.dotnetv3.HelloBedrock] \ No newline at end of file diff --git a/dotnetv3/Bedrock/BedrockExamples.sln b/dotnetv3/Bedrock/BedrockExamples.sln new file mode 100644 index 00000000000..30ace2580e1 --- /dev/null +++ b/dotnetv3/Bedrock/BedrockExamples.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34309.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedrockActions", "Actions\BedrockActions.csproj", "{C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{0DD1E95E-9EF2-4E43-86B3-F636736BE054}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83} = {0DD1E95E-9EF2-4E43-86B3-F636736BE054} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3D82D9F6-BE3C-40F1-9224-B8E4D746FC2E} + EndGlobalSection +EndGlobal From abe5bc971d2ab568547d61eb8afb2cb29eb8e7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bouteruche?= Date: Wed, 6 Dec 2023 11:22:53 +0100 Subject: [PATCH 3/5] Update bedrock_metadata.yaml file and add snippet tags in HelloBedrock.cs --- .doc_gen/metadata/bedrock_metadata.yaml | 17 +++++++++++++++++ dotnetv3/Bedrock/Actions/HelloBedrock.cs | 8 ++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.doc_gen/metadata/bedrock_metadata.yaml b/.doc_gen/metadata/bedrock_metadata.yaml index 972bd52f425..475510a88b5 100644 --- a/.doc_gen/metadata/bedrock_metadata.yaml +++ b/.doc_gen/metadata/bedrock_metadata.yaml @@ -13,6 +13,15 @@ bedrock_Hello: - description: snippet_tags: - gov2.bedrock.Hello + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock + sdkguide: + excerpts: + - description: + snippet_tags: + - Bedrock.dotnetv3.BedrockActions.HelloBedrock services: bedrock: {ListFoundationModels} @@ -63,5 +72,13 @@ bedrock_ListFoundationModels: - description: List the available &BRlong; foundation models. snippet_tags: - python.example_code.bedrock.ListFoundationModels + .NET: + versions: + - sdk_version: 3 + github: dotnetv3/Bedrock + excerpts: + - description: List the available Bedrock foundation models. + snippet_tags: + - Bedrock.dotnetv3.BedrockActions.ListFoundationModels services: bedrock: {ListFoundationModels} diff --git a/dotnetv3/Bedrock/Actions/HelloBedrock.cs b/dotnetv3/Bedrock/Actions/HelloBedrock.cs index 62f9a632947..0a9b6d4339f 100644 --- a/dotnetv3/Bedrock/Actions/HelloBedrock.cs +++ b/dotnetv3/Bedrock/Actions/HelloBedrock.cs @@ -1,7 +1,7 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// snippet-start:[Bedrock.dotnetv3.HelloBedrock] +// snippet-start:[Bedrock.dotnetv3.BedrockActions.HelloBedrock] using Amazon; using Amazon.Bedrock; using Amazon.Bedrock.Model; @@ -26,6 +26,8 @@ static async Task Main(string[] args) } + // snippet-start:[Bedrock.dotnetv3.BedrockActions.ListFoundationModels] + /// /// List foundation models. /// @@ -58,6 +60,8 @@ private static async Task ListFoundationModelsAsync(AmazonBedrockClient bedrockC } } + // snippet-end:[Bedrock.dotnetv3.BedrockActions.ListFoundationModels] + /// /// Write the foundation model summary to console. /// @@ -68,4 +72,4 @@ private static void WriteToConsole(FoundationModelSummary foundationModel) } } } -// snippet-end:[Bedrock.dotnetv3.HelloBedrock] \ No newline at end of file +// snippet-end:[Bedrock.dotnetv3.BedrockActions.HelloBedrock] \ No newline at end of file From 3ad62baddcda4c99498ea6a2ea14bb2b127cebc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bouteruche?= Date: Wed, 6 Dec 2023 16:01:34 +0100 Subject: [PATCH 4/5] Add a test project. Add the BedrockActions and BedrockTests projects to DotNetV3Examples.sln file. --- dotnetv3/Bedrock/BedrockExamples.sln | 9 ++++++ dotnetv3/Bedrock/Tests/BedrockTest.cs | 36 ++++++++++++++++++++++ dotnetv3/Bedrock/Tests/BedrockTests.csproj | 27 ++++++++++++++++ dotnetv3/Bedrock/Tests/GlobalUsings.cs | 12 ++++++++ dotnetv3/DotNetV3Examples.sln | 9 ++++++ 5 files changed, 93 insertions(+) create mode 100644 dotnetv3/Bedrock/Tests/BedrockTest.cs create mode 100644 dotnetv3/Bedrock/Tests/BedrockTests.csproj create mode 100644 dotnetv3/Bedrock/Tests/GlobalUsings.cs diff --git a/dotnetv3/Bedrock/BedrockExamples.sln b/dotnetv3/Bedrock/BedrockExamples.sln index 30ace2580e1..0c01c36e80a 100644 --- a/dotnetv3/Bedrock/BedrockExamples.sln +++ b/dotnetv3/Bedrock/BedrockExamples.sln @@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedrockActions", "Actions\B EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{0DD1E95E-9EF2-4E43-86B3-F636736BE054}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{898AFE57-24C6-4D79-81C2-614873B38F62}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedrockTests", "Tests\BedrockTests.csproj", "{5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,12 +21,17 @@ Global {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Debug|Any CPU.Build.0 = Debug|Any CPU {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Release|Any CPU.ActiveCfg = Release|Any CPU {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83}.Release|Any CPU.Build.0 = Release|Any CPU + {5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {C47E3B3E-0040-4CB6-AB92-EF4395C1EB83} = {0DD1E95E-9EF2-4E43-86B3-F636736BE054} + {5486426B-A8E8-4C6A-BEE2-83DD7CDB68A6} = {898AFE57-24C6-4D79-81C2-614873B38F62} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3D82D9F6-BE3C-40F1-9224-B8E4D746FC2E} diff --git a/dotnetv3/Bedrock/Tests/BedrockTest.cs b/dotnetv3/Bedrock/Tests/BedrockTest.cs new file mode 100644 index 00000000000..d21612b9ec2 --- /dev/null +++ b/dotnetv3/Bedrock/Tests/BedrockTest.cs @@ -0,0 +1,36 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +using Amazon.Bedrock; +using Amazon.Bedrock.Model; + +namespace BedrockTests; + +/// +/// Bedrock tests. +/// +public class BedrockTest +{ + private readonly AmazonBedrockClient bedrockClient; + + /// + /// Constructor for the test class. + /// + public BedrockTest() + { + bedrockClient = new AmazonBedrockClient(Amazon.RegionEndpoint.USEast1); + } + + /// + /// List foundation models. Should not be null. + /// + /// Async task. + [Fact] + [Order(1)] + [Trait("Category", "Integration")] + public async Task ListFoundationModelsAsync_ShouldNotBeNull() + { + var result = await bedrockClient.ListFoundationModelsAsync(new ListFoundationModelsRequest()); + Assert.NotEmpty(result.ModelSummaries); + } +} \ No newline at end of file diff --git a/dotnetv3/Bedrock/Tests/BedrockTests.csproj b/dotnetv3/Bedrock/Tests/BedrockTests.csproj new file mode 100644 index 00000000000..03f960debd4 --- /dev/null +++ b/dotnetv3/Bedrock/Tests/BedrockTests.csproj @@ -0,0 +1,27 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/dotnetv3/Bedrock/Tests/GlobalUsings.cs b/dotnetv3/Bedrock/Tests/GlobalUsings.cs new file mode 100644 index 00000000000..158ebd88747 --- /dev/null +++ b/dotnetv3/Bedrock/Tests/GlobalUsings.cs @@ -0,0 +1,12 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +global using Xunit; +global using Xunit.Extensions.Ordering; + +// Optional. +[assembly: CollectionBehavior(DisableTestParallelization = true)] +// Optional. +[assembly: TestCaseOrderer("Xunit.Extensions.Ordering.TestCaseOrderer", "Xunit.Extensions.Ordering")] +// Optional. +[assembly: TestCollectionOrderer("Xunit.Extensions.Ordering.CollectionOrderer", "Xunit.Extensions.Ordering")] \ No newline at end of file diff --git a/dotnetv3/DotNetV3Examples.sln b/dotnetv3/DotNetV3Examples.sln index 4c237f18ea4..f7bb48232a7 100644 --- a/dotnetv3/DotNetV3Examples.sln +++ b/dotnetv3/DotNetV3Examples.sln @@ -739,6 +739,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StepFunctionsBasics", "Step EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StepFunctionsActions", "StepFunctions\Actions\StepFunctionsActions.csproj", "{0340F970-AE33-4ABD-9B2B-E7CF266E33CC}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BedrockActions", "Bedrock\Actions\BedrockActions.csproj", "{F2975A40-3BCD-4AE0-BB14-03704E6B3F79}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bedrock", "Bedrock", "{5810E90E-DBA6-438A-8FB3-A1769B2E4ECA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1677,6 +1681,10 @@ Global {0340F970-AE33-4ABD-9B2B-E7CF266E33CC}.Debug|Any CPU.Build.0 = Debug|Any CPU {0340F970-AE33-4ABD-9B2B-E7CF266E33CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {0340F970-AE33-4ABD-9B2B-E7CF266E33CC}.Release|Any CPU.Build.0 = Release|Any CPU + {F2975A40-3BCD-4AE0-BB14-03704E6B3F79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2975A40-3BCD-4AE0-BB14-03704E6B3F79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2975A40-3BCD-4AE0-BB14-03704E6B3F79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2975A40-3BCD-4AE0-BB14-03704E6B3F79}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2014,6 +2022,7 @@ Global {6A9E4CE0-E5B2-4136-B796-BFE673954ACA} = {66F40B36-B02C-4B6E-9978-592BB0040FD8} {8638D5FD-CFEB-4FBA-A8C0-B65F31B8AE93} = {66F40B36-B02C-4B6E-9978-592BB0040FD8} {0340F970-AE33-4ABD-9B2B-E7CF266E33CC} = {66F40B36-B02C-4B6E-9978-592BB0040FD8} + {F2975A40-3BCD-4AE0-BB14-03704E6B3F79} = {5810E90E-DBA6-438A-8FB3-A1769B2E4ECA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {08502818-E8E1-4A91-A51C-4C8C8D4FF9CA} From 9037e0e92f67b76def1b823b8f6ddd51420e4041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Bouteruche?= Date: Thu, 7 Dec 2023 11:14:35 +0100 Subject: [PATCH 5/5] Fix lint issues --- dotnetv3/Bedrock/Actions/HelloBedrock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnetv3/Bedrock/Actions/HelloBedrock.cs b/dotnetv3/Bedrock/Actions/HelloBedrock.cs index 0a9b6d4339f..3c68c6d3cb5 100644 --- a/dotnetv3/Bedrock/Actions/HelloBedrock.cs +++ b/dotnetv3/Bedrock/Actions/HelloBedrock.cs @@ -54,7 +54,7 @@ private static async Task ListFoundationModelsAsync(AmazonBedrockClient bedrockC Console.WriteLine("Something wrong happened"); } } - catch(AmazonBedrockException e) + catch (AmazonBedrockException e) { Console.WriteLine(e.Message); }