2.0 KiB
2.0 KiB
PocketFlow Text Converter
A practical example demonstrating how to use PocketFlow to create an interactive text converter. This example showcases important concepts like data flow between nodes, user choice-based branching, and state management using the shared store.
Features
- Convert text to UPPERCASE
- Convert text to lowercase
- Reverse text
- Remove extra spaces
- Interactive command-line interface
- Continuous flow with option to process multiple texts
Project Structure
.
├── flow.py # Nodes and flow implementation
├── main.py # Application entry point
└── README.md # Documentation
Implementation Details
-
TextInput Node:
prep(): Gets text input from userpost(): Shows options menu and returns action based on choice
-
TextTransform Node:
prep(): Gets text and choice from shared storeexec(): Applies the chosen transformationpost(): Shows result and asks if continue
-
Flow Structure:
- Input → Transform → (loop back to Input or exit)
- Demonstrates branching based on actions ("transform", "input", "exit")
How to Run
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the example:
python main.py
What You'll Learn
This example demonstrates several important PocketFlow concepts:
- Node Architecture: How to structure logic using prep/exec/post pattern
- Flow Control: How to use actions to control flow between nodes
- Shared Store: How to share data between nodes
- Interactivity: How to create interactive flows with user input
- Branching: How to implement different paths based on choices