Esempi per Amazon Bedrock con SDK per .NET (v4) - Esempi di codice per SDK AWS

Sono disponibili altri esempi per SDK AWS nel repository GitHub della documentazione degli esempi per SDK AWS.

Esempi per Amazon Bedrock con SDK per .NET (v4)

Gli esempi di codice seguenti mostrano come eseguire operazioni e implementare scenari comuni utilizzando AWS SDK per .NET (v4) con Amazon Bedrock.

Le azioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un link al codice sorgente completo, in cui vengono fornite le istruzioni su come configurare ed eseguire il codice nel contesto.

Nozioni di base

Gli esempi di codice seguenti mostrano come iniziare a utilizzare Amazon Bedrock.

SDK per .NET (v4)
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice AWS.

using Amazon; using Amazon.Bedrock; using Amazon.Bedrock.Model; namespace BedrockActions; /// <summary> /// This example shows how to list foundation models. /// </summary> internal class HelloBedrock { /// <summary> /// Main method to call the ListFoundationModelsAsync method. /// </summary> /// <param name="args"> The command line arguments. </param> 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); } /// <summary> /// List foundation models. /// </summary> /// <param name="bedrockClient"> The Amazon Bedrock client. </param> private static async Task ListFoundationModelsAsync(AmazonBedrockClient bedrockClient) { Console.WriteLine("List foundation models with no filter."); try { var 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); } } /// <summary> /// Write the foundation model summary to console. /// </summary> /// <param name="foundationModel"> The foundation model summary to write to console. </param> 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)}"); } }
  • Per informazioni dettagliate sull’API, consulta ListFoundationModels nella documentazione di riferimento dell’API AWS SDK per .NET.

Argomenti

Azioni

L’esempio di codice seguente mostra come utilizzare ListFoundationModels.

SDK per .NET (v4)
Nota

Ulteriori informazioni su GitHub. Trova l’esempio completo e scopri di più sulla configurazione e l’esecuzione nel Repository di esempi di codice AWS.

Elenca i modelli di fondazione di Bedrock.

/// <summary> /// List foundation models. /// </summary> /// <param name="bedrockClient"> The Amazon Bedrock client. </param> private static async Task ListFoundationModelsAsync(AmazonBedrockClient bedrockClient) { Console.WriteLine("List foundation models with no filter."); try { var 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); } }
  • Per informazioni dettagliate sull’API, consulta ListFoundationModels nella documentazione di riferimento dell’API AWS SDK per .NET.