Announcing Inline Code Support in Amazon Bedrock Flows: Simplifying Generative AI Workflows
Benefits of Inline Code in Amazon Bedrock Flows
Solution Overview
Prerequisites
Create Your Flow Using Inline Code Nodes
Considerations
Conclusion
About the Authors
Streamlining Generative AI Development: Inline Code Nodes in Amazon Bedrock Flows
Today marks an exciting milestone for developers utilizing Amazon Bedrock Flows: the public preview of inline code nodes. This powerful feature allows you to write Python scripts directly within your workflow, significantly simplifying the process of building generative AI applications. By reducing the need for separate AWS Lambda functions for simple logic, inline code not only streamlines tasks but also enhances the accessibility of generative AI development across organizations.
Why Inline Code?
Inline code nodes open the door to several critical improvements for generative AI workflows:
-
Simplified Preprocessing and Postprocessing: Manage data transformations before sending it to large language models (LLMs) and perform operations on model outputs directly in the flow.
-
Support for Complex Use Cases: Handle intricate, multi-step workflows seamlessly, using popular Python packages like
opencv,scipy, andpypdf. -
Builder-Friendly Interface: Create and manage code easily through the Amazon Bedrock API and the AWS Management Console, reducing the operational burden associated with managing multiple Lambda functions.
-
Observability: Gain insights into the inputs and outputs from each node in your workflow, enabling better debugging and monitoring.
Real-World Impact: Thomson Reuters
Consider Thomson Reuters, a global information services leader. They deal with complex, multi-step generative AI use cases that often require preprocessing and postprocessing. With the inline code feature, they can:
-
Simplify Flow Management: Avoid the overhead of maintaining numerous Lambda functions for various custom code blocks, thereby simplifying management across a large user base.
-
Enable Flexible Data Processing: Directly preprocess data and postprocess LLM responses with minimal friction between internal AWS services and external APIs.
-
Encourage DIY Flow Creation: Users can develop complex workflows using a self-service interface, shielded from backend complexities.
Solution Overview
Let’s showcase how to create a simple Amazon Bedrock flow that processes user requests for music playlists, incorporating both preprocessing and postprocessing inline code nodes.
Prerequisites
Before diving into implementation, ensure you have the following ready:
- Access to an AWS account.
- Permissions to manage Amazon Bedrock resources.
- A basic understanding of Python programming.
After confirming these prerequisites, you’re ready to implement inline code in your generative AI workflows.
Creating Your Flow
To create your flow using inline code nodes, follow these steps:
- Access the Amazon Bedrock Console: Go to Flows under Builder Tools.
- Create a New Flow: Name your flow, e.g.,
easy-inline-code-flow. - Add Inline Code Nodes: Create two nodes for preprocessing and postprocessing, respectively.
Sample Code for Preprocessing
In the Preprocessing_InlineCode node, use the following Python code to check the number of songs requested:
import json
def __func():
try:
if userprompt['number'] > 10:
userprompt['number'] = 10
return userprompt
except Exception as e:
return {
"error": "Invalid input format",
"details": str(e)
}
__func()
Sample Code for Postprocessing
In the Postprocessing_Inline Code node, process the response:
def __func():
cleaned_text = " ".join(playlist.split())
word_count = len(cleaned_text.split())
return {
"playlist": playlist,
"word_count": word_count
}
__func()
Testing the Flow
To test the flow, input the following JSON into the Flow Input node:
{
"genre": "pop",
"number": 8
}
Note: Ensure input to the inline code node is securely handled, as it’s treated as untrusted. Implement necessary validation and data processing.
Monitoring Your Flow
After executing your flow, you can access execution traces, providing insight into each processing step and real-time performance metrics. This feature can be enabled via the API by setting the enableTrace field to true in an InvokeFlow request.
Key Considerations
- Code runs in a secure, managed environment with no internet access.
- Support is limited to Python 3.12 and above.
- Code can handle binary sizes up to 4 MB (approximately 4 million characters).
- 25 concurrent code execution sessions are allowed per AWS account.
Conclusion
The introduction of inline code nodes in Amazon Bedrock Flows is a transformative step for generative AI development, simplifying the management of basic processing tasks and allowing developers to focus on building intelligent workflows. This new feature is currently available in the following AWS Regions: US East (N. Virginia, Ohio), US West (Oregon), and Europe (Frankfurt).
To get started, visit the Amazon Bedrock console or access the APIs. Dive into creating innovative applications powered by these new capabilities!
We’re eager to see what you build with this feature and welcome your feedback through AWS re:Post or your usual AWS contacts. Join the generative AI builder community at community.aws to share your experiences and insights.
About the Authors
Shubhankar Sumar is a Senior Solutions Architect at AWS, specializing in generative AI solutions for enterprise software.
Jesse Manders is a Senior Product Manager on Amazon Bedrock, focusing on enhancing generative AI products to meet industry needs.
Explore the provided resources and unleash the full potential of Amazon Bedrock Flows today!