pocketflow/cookbook/pocketflow-flow
Alan ALves 557a14f695 feat: add new examples from pocketflow-academy 2025-03-19 10:31:04 -03:00
..
README.md feat: add new examples from pocketflow-academy 2025-03-19 10:31:04 -03:00
flow.py feat: add new examples from pocketflow-academy 2025-03-19 10:31:04 -03:00
main.py feat: add new examples from pocketflow-academy 2025-03-19 10:31:04 -03:00
requirements.txt feat: add new examples from pocketflow-academy 2025-03-19 10:31:04 -03:00

README.md

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

  1. TextInput Node:

    • prep(): Gets text input from user
    • post(): Shows options menu and returns action based on choice
  2. TextTransform Node:

    • prep(): Gets text and choice from shared store
    • exec(): Applies the chosen transformation
    • post(): Shows result and asks if continue
  3. Flow Structure:

    • Input → Transform → (loop back to Input or exit)
    • Demonstrates branching based on actions ("transform", "input", "exit")

How to Run

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. 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

Additional Resources