Verwendung GetFoundationModel mit einem AWS SDK oder 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.

Verwendung GetFoundationModel mit einem AWS SDK oder CLI

Die folgenden Codebeispiele zeigen, wie es verwendet wirdGetFoundationModel.

Java
SDK für Java 2.x
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Erfahren Sie mehr über ein Foundation-Modell mithilfe des synchronen Amazon Bedrock-Clients.

/** * Get details about an Amazon Bedrock foundation model. * * @param bedrockClient The service client for accessing Amazon Bedrock. * @param modelIdentifier The model identifier. * @return An object containing the foundation model's details. */ public static FoundationModelDetails getFoundationModel(BedrockClient bedrockClient, String modelIdentifier) { try { GetFoundationModelResponse response = bedrockClient.getFoundationModel( r -> r.modelIdentifier(modelIdentifier) ); FoundationModelDetails model = response.modelDetails(); System.out.println(" Model ID: " + model.modelId()); System.out.println(" Model ARN: " + model.modelArn()); System.out.println(" Model Name: " + model.modelName()); System.out.println(" Provider Name: " + model.providerName()); System.out.println(" Lifecycle status: " + model.modelLifecycle().statusAsString()); System.out.println(" Input modalities: " + model.inputModalities()); System.out.println(" Output modalities: " + model.outputModalities()); System.out.println(" Supported customizations: " + model.customizationsSupported()); System.out.println(" Supported inference types: " + model.inferenceTypesSupported()); System.out.println(" Response streaming supported: " + model.responseStreamingSupported()); return model; } catch (ValidationException e) { throw new IllegalArgumentException(e.getMessage()); } catch (SdkException e) { System.err.println(e.getMessage()); throw new RuntimeException(e); } }

Erfahren Sie mehr über ein Foundation-Modell mithilfe des asynchronen Amazon Bedrock-Clients.

/** * Get details about an Amazon Bedrock foundation model. * * @param bedrockClient The async service client for accessing Amazon Bedrock. * @param modelIdentifier The model identifier. * @return An object containing the foundation model's details. */ public static FoundationModelDetails getFoundationModel(BedrockAsyncClient bedrockClient, String modelIdentifier) { try { CompletableFuture<GetFoundationModelResponse> future = bedrockClient.getFoundationModel( r -> r.modelIdentifier(modelIdentifier) ); FoundationModelDetails model = future.get().modelDetails(); System.out.println(" Model ID: " + model.modelId()); System.out.println(" Model ARN: " + model.modelArn()); System.out.println(" Model Name: " + model.modelName()); System.out.println(" Provider Name: " + model.providerName()); System.out.println(" Lifecycle status: " + model.modelLifecycle().statusAsString()); System.out.println(" Input modalities: " + model.inputModalities()); System.out.println(" Output modalities: " + model.outputModalities()); System.out.println(" Supported customizations: " + model.customizationsSupported()); System.out.println(" Supported inference types: " + model.inferenceTypesSupported()); System.out.println(" Response streaming supported: " + model.responseStreamingSupported()); return model; } catch (ExecutionException e) { if (e.getMessage().contains("ValidationException")) { throw new IllegalArgumentException(e.getMessage()); } else { System.err.println(e.getMessage()); throw new RuntimeException(e); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); System.err.println(e.getMessage()); throw new RuntimeException(e); } }
JavaScript
SDK für JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Erfahren Sie mehr über ein Gründungsmodell.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { fileURLToPath } from "url"; import { BedrockClient, GetFoundationModelCommand, } from "@aws-sdk/client-bedrock"; /** * Get details about an Amazon Bedrock foundation model. * * @return {FoundationModelDetails} - The list of available bedrock foundation models. */ export const getFoundationModel = async () => { const client = new BedrockClient(); const command = new GetFoundationModelCommand({ modelIdentifier: "amazon.titan-embed-text-v1", }); const response = await client.send(command); return response.modelDetails; }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { const model = await getFoundationModel(); console.log(model); }
  • Einzelheiten zur API finden Sie GetFoundationModelunter AWS SDK for JavaScript API-Referenz.

Python
SDK für Python (Boto3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Erfahren Sie mehr über ein Gründungsmodell.

def get_foundation_model(self, model_identifier): """ Get details about an Amazon Bedrock foundation model. :return: The foundation model's details. """ try: return self.bedrock_client.get_foundation_model( modelIdentifier=model_identifier )["modelDetails"] except ClientError: logger.error( f"Couldn't get foundation models details for {model_identifier}" ) raise
  • Einzelheiten zur API finden Sie GetFoundationModelin AWS SDK for Python (Boto3) API Reference.

Eine vollständige Liste der AWS SDK-Entwicklerhandbücher und Codebeispiele finden Sie unter. Verwenden dieses Dienstes mit einem AWS SDK Dieses Thema enthält auch Informationen zu den ersten Schritten und Details zu früheren SDK-Versionen.