update flow
This commit is contained in:
parent
43f4ad319b
commit
14b1cf0a69
|
|
@ -1,6 +1,6 @@
|
||||||
# PocketFlow Text Converter
|
# Text Converter Flow
|
||||||
|
|
||||||
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.
|
This project demonstrates an interactive text transformation tool built with PocketFlow.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|
@ -11,60 +11,62 @@ A practical example demonstrating how to use PocketFlow to create an interactive
|
||||||
- Interactive command-line interface
|
- Interactive command-line interface
|
||||||
- Continuous flow with option to process multiple texts
|
- Continuous flow with option to process multiple texts
|
||||||
|
|
||||||
## Project Structure
|
## Getting Started
|
||||||
|
|
||||||
```
|
1. Install the required dependencies:
|
||||||
.
|
|
||||||
├── 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:
|
|
||||||
```bash
|
|
||||||
python -m venv venv
|
|
||||||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Install dependencies:
|
|
||||||
```bash
|
```bash
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Run the example:
|
2. Run the application:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python main.py
|
python main.py
|
||||||
```
|
```
|
||||||
|
|
||||||
## What You'll Learn
|
## How It Works
|
||||||
|
|
||||||
This example demonstrates several important PocketFlow concepts:
|
The workflow features an interactive loop with branching paths:
|
||||||
|
|
||||||
- **Node Architecture**: How to structure logic using prep/exec/post pattern
|
```mermaid
|
||||||
- **Flow Control**: How to use actions to control flow between nodes
|
graph TD
|
||||||
- **Shared Store**: How to share data between nodes
|
Input[TextInput Node] -->|transform| Transform[TextTransform Node]
|
||||||
- **Interactivity**: How to create interactive flows with user input
|
Transform -->|input| Input
|
||||||
- **Branching**: How to implement different paths based on choices
|
Transform -->|exit| End[End]
|
||||||
|
Input -->|exit| End
|
||||||
|
```
|
||||||
|
|
||||||
## Additional Resources
|
Here's what each part does:
|
||||||
|
1. **TextInput Node**: Collects text input and handles menu choices
|
||||||
|
2. **TextTransform Node**: Applies the selected transformation to the text
|
||||||
|
|
||||||
- [PocketFlow Documentation](https://the-pocket.github.io/PocketFlow/)
|
## Example Output
|
||||||
- [Flow Guide](https://the-pocket.github.io/PocketFlow/flow.html)
|
|
||||||
- [Node Guide](https://the-pocket.github.io/PocketFlow/node.html)
|
```
|
||||||
|
Welcome to Text Converter!
|
||||||
|
=========================
|
||||||
|
|
||||||
|
Enter text to convert: Pocket Flow is a 100-line LLM framework
|
||||||
|
|
||||||
|
Choose transformation:
|
||||||
|
1. Convert to UPPERCASE
|
||||||
|
2. Convert to lowercase
|
||||||
|
3. Reverse text
|
||||||
|
4. Remove extra spaces
|
||||||
|
5. Exit
|
||||||
|
|
||||||
|
Your choice (1-5): 1
|
||||||
|
|
||||||
|
Result: POCKET FLOW IS A 100-LINE LLM FRAMEWORK
|
||||||
|
|
||||||
|
Convert another text? (y/n): n
|
||||||
|
|
||||||
|
Thank you for using Text Converter!
|
||||||
|
```
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
- [`main.py`](./main.py): Main entry point for running the text converter
|
||||||
|
- [`flow.py`](./flow.py): Defines the nodes and flow for text transformation
|
||||||
|
- [`requirements.txt`](./requirements.txt): Lists the required dependencies
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue