Utilizzo di PrepareFlow con un SDK AWS
L’esempio di codice seguente mostra come utilizzare PrepareFlow.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- Python
-
- SDK per Python (Boto3)
-
Preparare un flusso Amazon Bedrock.
def prepare_flow(client, flow_id):
"""
Prepares an Amazon Bedrock Flow.
Args:
client: Amazon Bedrock agent boto3 client.
flow_id (str): The identifier of the flow that you want to prepare.
Returns:
str: The status of the flow preparation
"""
try:
# Prepare the flow.
logger.info("Preparing flow ID: %s",
flow_id)
response = client.prepare_flow(
flowIdentifier=flow_id
)
status = response.get('status')
while status == "Preparing":
logger.info("Preparing flow ID: %s. Status %s",
flow_id, status)
sleep(5)
response = client.get_flow(
flowIdentifier=flow_id
)
status = response.get('status')
print(f"Flow Status: {status}")
if status == "Prepared":
logger.info("Finished preparing flow ID: %s. Status %s",
flow_id, status)
else:
logger.warning("flow ID: %s not prepared. Status %s",
flow_id, status)
return status
except ClientError as e:
logger.exception("Client error preparing flow: %s", {str(e)})
raise
except Exception as e:
logger.exception("Unexepcted error preparing flow: %s", {str(e)})
raise
Per un elenco completo delle guide per gli sviluppatori di SDK AWS ed esempi di codice, consulta la sezione Utilizzo di Amazon Bedrock con un AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell'SDK.