Verwenden Sie ListFoundationModels mit einem AWS SDKoder CLI - Amazon Bedrock

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Verwenden Sie ListFoundationModels mit einem AWS SDKoder CLI

Die folgenden Codebeispiele zeigen, wie man es benutztListFoundationModels.

.NET
AWS SDK for .NET
Anmerkung

Es gibt noch mehr dazu GitHub. Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Bedrock Foundation-Modelle auf.

/// <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 { 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); } }
Go
SDKfür Go V2
Anmerkung

Es gibt noch mehr dazu GitHub. Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Bedrock Foundation-Modelle auf.

// FoundationModelWrapper encapsulates Amazon Bedrock actions used in the examples. // It contains a Bedrock service client that is used to perform foundation model actions. type FoundationModelWrapper struct { BedrockClient *bedrock.Client } // ListPolicies lists Bedrock foundation models that you can use. func (wrapper FoundationModelWrapper) ListFoundationModels() ([]types.FoundationModelSummary, error) { var models []types.FoundationModelSummary result, err := wrapper.BedrockClient.ListFoundationModels(context.TODO(), &bedrock.ListFoundationModelsInput{}) if err != nil { log.Printf("Couldn't list foundation models. Here's why: %v\n", err) } else { models = result.ModelSummaries } return models, err }
Java
SDKfür Java 2.x
Anmerkung

Es gibt noch mehr dazu. GitHub Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Amazon Bedrock Foundation-Modelle mit dem synchronen Amazon Bedrock-Client auf.

/** * Lists Amazon Bedrock foundation models that you can use. * You can filter the results with the request parameters. * * @param bedrockClient The service client for accessing Amazon Bedrock. * @return A list of objects containing the foundation models' details */ public static List<FoundationModelSummary> listFoundationModels(BedrockClient bedrockClient) { try { ListFoundationModelsResponse response = bedrockClient.listFoundationModels(r -> {}); List<FoundationModelSummary> models = response.modelSummaries(); if (models.isEmpty()) { System.out.println("No available foundation models in " + region.toString()); } else { for (FoundationModelSummary model : models) { System.out.println("Model ID: " + model.modelId()); System.out.println("Provider: " + model.providerName()); System.out.println("Name: " + model.modelName()); System.out.println(); } } return models; } catch (SdkClientException e) { System.err.println(e.getMessage()); throw new RuntimeException(e); } }

Listet die verfügbaren Amazon Bedrock Foundation-Modelle auf, die den asynchronen Amazon Bedrock-Client verwenden.

/** * Lists Amazon Bedrock foundation models that you can use. * You can filter the results with the request parameters. * * @param bedrockClient The async service client for accessing Amazon Bedrock. * @return A list of objects containing the foundation models' details */ public static List<FoundationModelSummary> listFoundationModels(BedrockAsyncClient bedrockClient) { try { CompletableFuture<ListFoundationModelsResponse> future = bedrockClient.listFoundationModels(r -> {}); List<FoundationModelSummary> models = future.get().modelSummaries(); if (models.isEmpty()) { System.out.println("No available foundation models in " + region.toString()); } else { for (FoundationModelSummary model : models) { System.out.println("Model ID: " + model.modelId()); System.out.println("Provider: " + model.providerName()); System.out.println("Name: " + model.modelName()); System.out.println(); } } return models; } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println(e.getMessage()); throw new RuntimeException(e); } catch (ExecutionException e) { System.err.println(e.getMessage()); throw new RuntimeException(e); } }
JavaScript
SDKfür JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Foundation-Modelle auf.

import { fileURLToPath } from "url"; import { BedrockClient, ListFoundationModelsCommand, } from "@aws-sdk/client-bedrock"; /** * List the available Amazon Bedrock foundation models. * * @return {FoundationModelSummary[]} - The list of available bedrock foundation models. */ export const listFoundationModels = async () => { const client = new BedrockClient(); const input = { // byProvider: 'STRING_VALUE', // byCustomizationType: 'FINE_TUNING' || 'CONTINUED_PRE_TRAINING', // byOutputModality: 'TEXT' || 'IMAGE' || 'EMBEDDING', // byInferenceType: 'ON_DEMAND' || 'PROVISIONED', }; const command = new ListFoundationModelsCommand(input); const response = await client.send(command); return response.modelSummaries; }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { const models = await listFoundationModels(); console.log(models); }
Kotlin
SDKfür Kotlin
Anmerkung

Es gibt noch mehr dazu. GitHub Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Amazon Bedrock Foundation-Modelle auf.

suspend fun listFoundationModels(): List<FoundationModelSummary>? { BedrockClient { region = "us-east-1" }.use { bedrockClient -> val response = bedrockClient.listFoundationModels(ListFoundationModelsRequest {}) response.modelSummaries?.forEach { model -> println("==========================================") println(" Model ID: ${model.modelId}") println("------------------------------------------") println(" Name: ${model.modelName}") println(" Provider: ${model.providerName}") println(" Input modalities: ${model.inputModalities}") println(" Output modalities: ${model.outputModalities}") println(" Supported customizations: ${model.customizationsSupported}") println(" Supported inference types: ${model.inferenceTypesSupported}") println("------------------------------------------\n") } return response.modelSummaries } }
PHP
SDK für PHP
Anmerkung

Es gibt noch mehr dazu. GitHub Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Amazon Bedrock Foundation-Modelle auf.

public function listFoundationModels() { $result = $this->bedrockClient->listFoundationModels(); return $result; }
Python
SDKfür Python (Boto3)
Anmerkung

Es gibt noch mehr dazu. GitHub Finden Sie das vollständige Beispiel und erfahren Sie, wie Sie es einrichten und ausführen in der AWS Repository mit Codebeispielen.

Listet die verfügbaren Amazon Bedrock Foundation-Modelle auf.

def list_foundation_models(self): """ List the available Amazon Bedrock foundation models. :return: The list of available bedrock foundation models. """ try: response = self.bedrock_client.list_foundation_models() models = response["modelSummaries"] logger.info("Got %s foundation models.", len(models)) return models except ClientError: logger.error("Couldn't list foundation models.") raise

Für eine vollständige Liste von AWS SDKEntwicklerhandbücher und Codebeispiele finden Sie unterNutzung dieses Dienstes mit einem AWS SDK. Dieses Thema enthält auch Informationen zu den ersten Schritten und Details zu früheren SDK Versionen.