

Weitere AWS SDK-Beispiele sind im GitHub Repo [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) verfügbar.

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.

# Amazon Titan Text für Amazon Bedrock Runtime
<a name="bedrock-runtime_code_examples_amazon_titan_text"></a>

Die folgenden Codebeispiele zeigen, wie Sie Amazon Bedrock Runtime mit AWS SDKs verwenden.

**Topics**
+ [InvokeModel](bedrock-runtime_example_bedrock-runtime_InvokeModel_TitanText_section.md)

# Aufrufen von Modellen von Amazon Titan Text in Amazon Bedrock mithilfe der Invoke-Model-API
<a name="bedrock-runtime_example_bedrock-runtime_InvokeModel_TitanText_section"></a>

Das folgende Codebeispiel zeigt, wie mit der Invoke-Model-API eine Textnachricht an Amazon Titan Text gesendet wird.

------
#### [ Python ]

**SDK für Python (Boto3)**  
 Es gibt noch mehr dazu GitHub. Hier finden Sie das vollständige Beispiel und erfahren, wie Sie das [AWS -Code-Beispiel-](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/bedrock-runtime#code-examples) einrichten und ausführen. 
Verwenden der API zum Aufrufen eines Modells zum Senden einer Textnachricht.  

```
# Use the native inference API to send a text message to Amazon Titan Text.

import boto3
import json

from botocore.exceptions import ClientError

# Create a Bedrock Runtime client in the AWS Region of your choice.
client = boto3.client("bedrock-runtime", region_name="us-east-1")

# Set the model ID, e.g., Titan Text Premier.
model_id = "amazon.titan-text-premier-v1:0"

# Define the prompt for the model.
prompt = "Describe the purpose of a 'hello world' program in one line."

# Format the request payload using the model's native structure.
native_request = {
    "inputText": prompt,
    "textGenerationConfig": {
        "maxTokenCount": 512,
        "temperature": 0.5,
    },
}

# Convert the native request to JSON.
request = json.dumps(native_request)

try:
    # Invoke the model with the request.
    response = client.invoke_model(modelId=model_id, body=request)

except (ClientError, Exception) as e:
    print(f"ERROR: Can't invoke '{model_id}'. Reason: {e}")
    exit(1)

# Decode the response body.
model_response = json.loads(response["body"].read())

# Extract and print the response text.
response_text = model_response["results"][0]["outputText"]
print(response_text)
```
+  Einzelheiten zur API finden Sie [InvokeModel](https://docs.aws.amazon.com/goto/boto3/bedrock-runtime-2023-09-30/InvokeModel)in *AWS SDK for Python (Boto3) API* Reference. 

------