Wählen Sie Ihre Cookie-Einstellungen aus

Wir verwenden essentielle Cookies und ähnliche Tools, die für die Bereitstellung unserer Website und Services erforderlich sind. Wir verwenden Performance-Cookies, um anonyme Statistiken zu sammeln, damit wir verstehen können, wie Kunden unsere Website nutzen, und Verbesserungen vornehmen können. Essentielle Cookies können nicht deaktiviert werden, aber Sie können auf „Anpassen“ oder „Ablehnen“ klicken, um Performance-Cookies abzulehnen.

Wenn Sie damit einverstanden sind, verwenden AWS und zugelassene Drittanbieter auch Cookies, um nützliche Features der Website bereitzustellen, Ihre Präferenzen zu speichern und relevante Inhalte, einschließlich relevanter Werbung, anzuzeigen. Um alle nicht notwendigen Cookies zu akzeptieren oder abzulehnen, klicken Sie auf „Akzeptieren“ oder „Ablehnen“. Um detailliertere Entscheidungen zu treffen, klicken Sie auf „Anpassen“.

Rufen Sie Amazon Nova auf Amazon Bedrock mithilfe der Converse-API von Bedrock auf

Fokusmodus
Rufen Sie Amazon Nova auf Amazon Bedrock mithilfe der Converse-API von Bedrock auf - 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.

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.

Die folgenden Codebeispiele zeigen, wie Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova senden.

.NET
SDK for .NET
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.

Senden Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova.

// Use the Converse API to send a text message to Amazon Nova. using System; using System.Collections.Generic; using Amazon; using Amazon.BedrockRuntime; using Amazon.BedrockRuntime.Model; // Create a Bedrock Runtime client in the AWS Region you want to use. var client = new AmazonBedrockRuntimeClient(RegionEndpoint.USEast1); // Set the model ID, e.g., Amazon Nova Lite. var modelId = "amazon.nova-lite-v1:0"; // Define the user message. var userMessage = "Describe the purpose of a 'hello world' program in one line."; // Create a request with the model ID, the user message, and an inference configuration. var request = new ConverseRequest { ModelId = modelId, Messages = new List<Message> { new Message { Role = ConversationRole.User, Content = new List<ContentBlock> { new ContentBlock { Text = userMessage } } } }, InferenceConfig = new InferenceConfiguration() { MaxTokens = 512, Temperature = 0.5F, TopP = 0.9F } }; try { // Send the request to the Bedrock Runtime and wait for the result. var response = await client.ConverseAsync(request); // Extract and print the response text. string responseText = response?.Output?.Message?.Content?[0]?.Text ?? ""; Console.WriteLine(responseText); } catch (AmazonBedrockRuntimeException e) { Console.WriteLine($"ERROR: Can't invoke '{modelId}'. Reason: {e.Message}"); throw; }

Senden Sie mithilfe der Converse-API von Bedrock mit einer Toolkonfiguration eine Konversation mit Nachrichten an Amazon Nova.

/// <summary> /// Wrapper class for interacting with the Amazon Bedrock Converse API. /// </summary> public class BedrockActionsWrapper { private readonly IAmazonBedrockRuntime _bedrockClient; private readonly ILogger<BedrockActionsWrapper> _logger; /// <summary> /// Initializes a new instance of the <see cref="BedrockActionsWrapper"/> class. /// </summary> /// <param name="bedrockClient">The Bedrock Converse API client.</param> /// <param name="logger">The logger instance.</param> public BedrockActionsWrapper(IAmazonBedrockRuntime bedrockClient, ILogger<BedrockActionsWrapper> logger) { _bedrockClient = bedrockClient; _logger = logger; } /// <summary> /// Sends a Converse request to the Amazon Bedrock Converse API. /// </summary> /// <param name="modelId">The Bedrock Model Id.</param> /// <param name="systemPrompt">A system prompt instruction.</param> /// <param name="conversation">The array of messages in the conversation.</param> /// <param name="toolSpec">The specification for a tool.</param> /// <returns>The response of the model.</returns> public async Task<ConverseResponse> SendConverseRequestAsync(string modelId, string systemPrompt, List<Message> conversation, ToolSpecification toolSpec) { try { var request = new ConverseRequest() { ModelId = modelId, System = new List<SystemContentBlock>() { new SystemContentBlock() { Text = systemPrompt } }, Messages = conversation, ToolConfig = new ToolConfiguration() { Tools = new List<Tool>() { new Tool() { ToolSpec = toolSpec } } } }; var response = await _bedrockClient.ConverseAsync(request); return response; } catch (ModelNotReadyException ex) { _logger.LogError(ex, "Model not ready, please wait and try again."); throw; } catch (AmazonBedrockRuntimeException ex) { _logger.LogError(ex, "Error occurred while sending Converse request."); throw; } } }
  • Einzelheiten zur API finden Sie unter Converse in AWS SDK for .NET der API-Referenz.

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.

Senden Sie mithilfe der Converse-API von Bedrock mit dem asynchronen Java-Client eine Textnachricht an Amazon Nova.

import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeAsyncClient; import software.amazon.awssdk.services.bedrockruntime.model.*; import java.util.concurrent.CompletableFuture; /** * This example demonstrates how to use the Amazon Nova foundation models * with an asynchronous Amazon Bedrock runtime client to generate text. * It shows how to: * - Set up the Amazon Bedrock runtime client * - Create a message * - Configure and send a request * - Process the response */ public class ConverseAsync { public static String converseAsync() { // Step 1: Create the Amazon Bedrock runtime client // The runtime client handles the communication with AI models on Amazon Bedrock BedrockRuntimeAsyncClient client = BedrockRuntimeAsyncClient.builder() .credentialsProvider(DefaultCredentialsProvider.create()) .region(Region.US_EAST_1) .build(); // Step 2: Specify which model to use // Available Amazon Nova models and their characteristics: // - Amazon Nova Micro: Text-only model optimized for lowest latency and cost // - Amazon Nova Lite: Fast, low-cost multimodal model for image, video, and text // - Amazon Nova Pro: Advanced multimodal model balancing accuracy, speed, and cost // // For the latest available models, see: // https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html String modelId = "amazon.nova-lite-v1:0"; // Step 3: Create the message // The message includes the text prompt and specifies that it comes from the user var inputText = "Describe the purpose of a 'hello world' program in one line."; var message = Message.builder() .content(ContentBlock.fromText(inputText)) .role(ConversationRole.USER) .build(); // Step 4: Configure the request // Optional parameters to control the model's response: // - maxTokens: maximum number of tokens to generate // - temperature: randomness (max: 1.0, default: 0.7) // OR // - topP: diversity of word choice (max: 1.0, default: 0.9) // Note: Use either temperature OR topP, but not both ConverseRequest request = ConverseRequest.builder() .modelId(modelId) .messages(message) .inferenceConfig(config -> config .maxTokens(500) // The maximum response length .temperature(0.5F) // Using temperature for randomness control //.topP(0.9F) // Alternative: use topP instead of temperature ).build(); // Step 5: Send and process the request asynchronously // - Send the request to the model // - Extract and return the generated text from the response try { CompletableFuture<ConverseResponse> asyncResponse = client.converse(request); return asyncResponse.thenApply( response -> response.output().message().content().get(0).text() ).get(); } catch (Exception e) { System.err.printf("Can't invoke '%s': %s", modelId, e.getMessage()); throw new RuntimeException(e); } } public static void main(String[] args) { String response = converseAsync(); System.out.println(response); } }

Senden Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova.

import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.core.exception.SdkClientException; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient; import software.amazon.awssdk.services.bedrockruntime.model.*; /** * This example demonstrates how to use the Amazon Nova foundation models * with a synchronous Amazon Bedrock runtime client to generate text. * It shows how to: * - Set up the Amazon Bedrock runtime client * - Create a message * - Configure and send a request * - Process the response */ public class Converse { public static String converse() { // Step 1: Create the Amazon Bedrock runtime client // The runtime client handles the communication with AI models on Amazon Bedrock BedrockRuntimeClient client = BedrockRuntimeClient.builder() .credentialsProvider(DefaultCredentialsProvider.create()) .region(Region.US_EAST_1) .build(); // Step 2: Specify which model to use // Available Amazon Nova models and their characteristics: // - Amazon Nova Micro: Text-only model optimized for lowest latency and cost // - Amazon Nova Lite: Fast, low-cost multimodal model for image, video, and text // - Amazon Nova Pro: Advanced multimodal model balancing accuracy, speed, and cost // // For the latest available models, see: // https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html String modelId = "amazon.nova-lite-v1:0"; // Step 3: Create the message // The message includes the text prompt and specifies that it comes from the user var inputText = "Describe the purpose of a 'hello world' program in one line."; var message = Message.builder() .content(ContentBlock.fromText(inputText)) .role(ConversationRole.USER) .build(); // Step 4: Configure the request // Optional parameters to control the model's response: // - maxTokens: maximum number of tokens to generate // - temperature: randomness (max: 1.0, default: 0.7) // OR // - topP: diversity of word choice (max: 1.0, default: 0.9) // Note: Use either temperature OR topP, but not both ConverseRequest request = ConverseRequest.builder() .modelId(modelId) .messages(message) .inferenceConfig(config -> config .maxTokens(500) // The maximum response length .temperature(0.5F) // Using temperature for randomness control //.topP(0.9F) // Alternative: use topP instead of temperature ).build(); // Step 5: Send and process the request // - Send the request to the model // - Extract and return the generated text from the response try { ConverseResponse response = client.converse(request); return response.output().message().content().get(0).text(); } catch (SdkClientException e) { System.err.printf("ERROR: Can't invoke '%s'. Reason: %s", modelId, e.getMessage()); throw new RuntimeException(e); } } public static void main(String[] args) { String response = converse(); System.out.println(response); } }
  • Einzelheiten zur API finden Sie unter Converse in AWS SDK for Java 2.x der API-Referenz.

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.

Senden Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova.

// Use the Conversation API to send a text message to Amazon Titan Text. import { BedrockRuntimeClient, ConverseCommand, } from "@aws-sdk/client-bedrock-runtime"; // Create a Bedrock Runtime client in the AWS Region you want to use. const client = new BedrockRuntimeClient({ region: "us-east-1" }); // Set the model ID, e.g., Titan Text Premier. const modelId = "amazon.titan-text-premier-v1:0"; // Start a conversation with the user message. const userMessage = "Describe the purpose of a 'hello world' program in one line."; const conversation = [ { role: "user", content: [{ text: userMessage }], }, ]; // Create a command with the model ID, the message, and a basic configuration. const command = new ConverseCommand({ modelId, messages: conversation, inferenceConfig: { maxTokens: 512, temperature: 0.5, topP: 0.9 }, }); try { // Send the command to the model and wait for the response const response = await client.send(command); // Extract and print the response text. const responseText = response.output.message.content[0].text; console.log(responseText); } catch (err) { console.log(`ERROR: Can't invoke '${modelId}'. Reason: ${err}`); process.exit(1); }
  • Einzelheiten zur API finden Sie unter Converse in AWS SDK für JavaScript der 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.

Senden Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova.

# Use the Conversation API to send a text message to Amazon Nova. import boto3 from botocore.exceptions import ClientError # Create a Bedrock Runtime client in the AWS Region you want to use. client = boto3.client("bedrock-runtime", region_name="us-east-1") # Set the model ID, e.g., Amazon Nova Lite. model_id = "amazon.nova-lite-v1:0" # Start a conversation with the user message. user_message = "Describe the purpose of a 'hello world' program in one line." conversation = [ { "role": "user", "content": [{"text": user_message}], } ] try: # Send the message to the model, using a basic inference configuration. response = client.converse( modelId=model_id, messages=conversation, inferenceConfig={"maxTokens": 512, "temperature": 0.5, "topP": 0.9}, ) # Extract and print the response text. response_text = response["output"]["message"]["content"][0]["text"] print(response_text) except (ClientError, Exception) as e: print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}") exit(1)
  • Einzelheiten zur API finden Sie unter Converse in AWS SDK for Python (Boto3) API Reference.

SDK for .NET
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.

Senden Sie mithilfe der Converse-API von Bedrock eine Textnachricht an Amazon Nova.

// Use the Converse API to send a text message to Amazon Nova. using System; using System.Collections.Generic; using Amazon; using Amazon.BedrockRuntime; using Amazon.BedrockRuntime.Model; // Create a Bedrock Runtime client in the AWS Region you want to use. var client = new AmazonBedrockRuntimeClient(RegionEndpoint.USEast1); // Set the model ID, e.g., Amazon Nova Lite. var modelId = "amazon.nova-lite-v1:0"; // Define the user message. var userMessage = "Describe the purpose of a 'hello world' program in one line."; // Create a request with the model ID, the user message, and an inference configuration. var request = new ConverseRequest { ModelId = modelId, Messages = new List<Message> { new Message { Role = ConversationRole.User, Content = new List<ContentBlock> { new ContentBlock { Text = userMessage } } } }, InferenceConfig = new InferenceConfiguration() { MaxTokens = 512, Temperature = 0.5F, TopP = 0.9F } }; try { // Send the request to the Bedrock Runtime and wait for the result. var response = await client.ConverseAsync(request); // Extract and print the response text. string responseText = response?.Output?.Message?.Content?[0]?.Text ?? ""; Console.WriteLine(responseText); } catch (AmazonBedrockRuntimeException e) { Console.WriteLine($"ERROR: Can't invoke '{modelId}'. Reason: {e.Message}"); throw; }

Senden Sie mithilfe der Converse-API von Bedrock mit einer Toolkonfiguration eine Konversation mit Nachrichten an Amazon Nova.

/// <summary> /// Wrapper class for interacting with the Amazon Bedrock Converse API. /// </summary> public class BedrockActionsWrapper { private readonly IAmazonBedrockRuntime _bedrockClient; private readonly ILogger<BedrockActionsWrapper> _logger; /// <summary> /// Initializes a new instance of the <see cref="BedrockActionsWrapper"/> class. /// </summary> /// <param name="bedrockClient">The Bedrock Converse API client.</param> /// <param name="logger">The logger instance.</param> public BedrockActionsWrapper(IAmazonBedrockRuntime bedrockClient, ILogger<BedrockActionsWrapper> logger) { _bedrockClient = bedrockClient; _logger = logger; } /// <summary> /// Sends a Converse request to the Amazon Bedrock Converse API. /// </summary> /// <param name="modelId">The Bedrock Model Id.</param> /// <param name="systemPrompt">A system prompt instruction.</param> /// <param name="conversation">The array of messages in the conversation.</param> /// <param name="toolSpec">The specification for a tool.</param> /// <returns>The response of the model.</returns> public async Task<ConverseResponse> SendConverseRequestAsync(string modelId, string systemPrompt, List<Message> conversation, ToolSpecification toolSpec) { try { var request = new ConverseRequest() { ModelId = modelId, System = new List<SystemContentBlock>() { new SystemContentBlock() { Text = systemPrompt } }, Messages = conversation, ToolConfig = new ToolConfiguration() { Tools = new List<Tool>() { new Tool() { ToolSpec = toolSpec } } } }; var response = await _bedrockClient.ConverseAsync(request); return response; } catch (ModelNotReadyException ex) { _logger.LogError(ex, "Model not ready, please wait and try again."); throw; } catch (AmazonBedrockRuntimeException ex) { _logger.LogError(ex, "Error occurred while sending Converse request."); throw; } } }
  • Einzelheiten zur API finden Sie unter Converse in AWS SDK for .NET der API-Referenz.

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

DatenschutzNutzungsbedingungen für die WebsiteCookie-Einstellungen
© 2025, Amazon Web Services, Inc. oder Tochtergesellschaften. Alle Rechte vorbehalten.