Envío y procesamiento de un documento con Llama en Amazon Bedrock - Amazon Bedrock

Envío y procesamiento de un documento con Llama en Amazon Bedrock

El siguiente ejemplo de código muestra cómo enviar y procesar un documento con Llama en Amazon Bedrock.

Python
SDK para Python (Boto3)
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

Enviar y procesar un documento con Llama en Amazon Bedrock.

# Send and process a document with Llama on Amazon Bedrock. 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. Llama 3.1 8B Instruct. model_id = "us.meta.llama3-1-8b-instruct-v1:0" # Load the document with open("example-data/amazon-nova-service-cards.pdf", "rb") as file: document_bytes = file.read() # Start a conversation with a user message and the document conversation = [ { "role": "user", "content": [ {"text": "Briefly compare the models described in this document"}, { "document": { # Available formats: html, md, pdf, doc/docx, xls/xlsx, csv, and txt "format": "pdf", "name": "Amazon Nova Service Cards", "source": {"bytes": document_bytes}, } }, ], } ] try: # Send the message to the model, using a basic inference configuration. response = client.converse( modelId=model_id, messages=conversation, inferenceConfig={"maxTokens": 500, "temperature": 0.3}, ) # 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)
  • Para obtener más información sobre la API, consulte Converse en la Referencia de la API de AWS SDK para Python (Boto3).

Para obtener una lista completa de las guías para desarrolladores de AWS SDK y ejemplos de código, consulte Uso de Amazon Bedrock con un AWS SDK. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.