Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub
Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare con un SDK PrepareFlowAWS
Il seguente esempio di codice mostra come utilizzarePrepareFlow.
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)
-
Prepara 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