如何在aws bedrock中进行批处理?

问题描述 投票:0回答:1

基于此处提供的 aws 文档,https://docs.aws.amazon.com/code-library/latest/ug/python_3_bedrock-runtime_code_examples.html。在以下示例中,调用基岩中的模型来生成嵌入。有没有办法传入批量文本(例如 csv 或数据帧)并在 aws bedrock 中批量生成嵌入,而不是对 bedrock 进行单独调用?

import boto3
import json

# 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 Embeddings V2.
model_id = "amazon.titan-embed-text-v2:0"

# The text to convert to an embedding.
input_text = "Please recommend books with a theme similar to the movie 'Inception'."

# Create the request for the model.
native_request = {"inputText": input_text}

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

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

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

# Extract and print the generated embedding and the input text token count.
embedding = model_response["embedding"]
input_token_count = model_response["inputTextTokenCount"]

print("\nYour input:")
print(input_text)
print(f"Number of input tokens: {input_token_count}")
print(f"Size of the generated embedding: {len(embedding)}")
print("Embedding:")
print(embedding)
amazon-web-services embedding amazon-bedrock
1个回答
0
投票

对批处理没有任何了解,但您可以创建 lambda,在其中可以读取 csv 中的每条记录并进行处理。如果您想并行运行将记录发布到 SQS,请将其作为触发器添加到 lambda,它将调用并行 lambdas

© www.soinside.com 2019 - 2024. All rights reserved.