feat: add new examples from pocketflow-academy
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
# PocketFlow Hello World
|
||||
|
||||
Your first PocketFlow application! This simple example demonstrates how to create a basic PocketFlow app from scratch.
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
.
|
||||
├── docs/ # Documentation files
|
||||
├── utils/ # Utility functions
|
||||
├── flow.py # PocketFlow implementation
|
||||
├── main.py # Main application entry point
|
||||
└── README.md # Project documentation
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
1. Create a virtual environment:
|
||||
```bash
|
||||
python -m venv venv
|
||||
source venv/bin/activate # On Windows: venv\Scripts\activate
|
||||
```
|
||||
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Run the example:
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
|
||||
## What This Example Demonstrates
|
||||
|
||||
- How to create your first PocketFlow application
|
||||
- Basic PocketFlow concepts and usage
|
||||
- Simple example of PocketFlow's capabilities
|
||||
|
||||
## Additional Resources
|
||||
|
||||
- [PocketFlow Documentation](https://the-pocket.github.io/PocketFlow/)
|
||||
@@ -0,0 +1,46 @@
|
||||
# Your Project Title
|
||||
|
||||
## Project Requirements
|
||||
A description of the project requirements.
|
||||
|
||||
## Utility Functions
|
||||
|
||||
1. **Call LLM** (`utils/call_llm.py`)
|
||||
|
||||
## Flow Design
|
||||
|
||||
1. **First Node**
|
||||
2. **Second Node**
|
||||
3. **Third Node**
|
||||
|
||||
### Flow Diagram
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
firstNode[First Node] --> secondNode[Second Node]
|
||||
secondNode --> thirdNode[Third Node]
|
||||
```
|
||||
|
||||
## Data Structure
|
||||
|
||||
The shared memory structure will be organized as follows:
|
||||
|
||||
```python
|
||||
shared = {
|
||||
"key": "value"
|
||||
}
|
||||
```
|
||||
|
||||
## Node Designs
|
||||
|
||||
### 1. First Node
|
||||
- **Purpose**: What the node does
|
||||
- **Design**: Regular Node (no Batch/Async)
|
||||
- **Data Access**:
|
||||
- Read: "key" from shared store
|
||||
- Write: "key" to shared store
|
||||
|
||||
### 2. Second Node
|
||||
...
|
||||
|
||||
### 3. Third Node
|
||||
@@ -0,0 +1,19 @@
|
||||
from pocketflow import Node, Flow
|
||||
from utils.call_llm import call_llm
|
||||
|
||||
# An example node and flow
|
||||
# Please replace this with your own node and flow
|
||||
class AnswerNode(Node):
|
||||
def prep(self, shared):
|
||||
# Read question from shared
|
||||
return shared["question"]
|
||||
|
||||
def exec(self, question):
|
||||
return call_llm(question)
|
||||
|
||||
def post(self, shared, prep_res, exec_res):
|
||||
# Store the answer in shared
|
||||
shared["answer"] = exec_res
|
||||
|
||||
answer_node = AnswerNode()
|
||||
qa_flow = Flow(start=answer_node)
|
||||
@@ -0,0 +1,16 @@
|
||||
from flow import qa_flow
|
||||
|
||||
# Example main function
|
||||
# Please replace this with your own main function
|
||||
def main():
|
||||
shared = {
|
||||
"question": "In one sentence, what's the end of universe?",
|
||||
"answer": None
|
||||
}
|
||||
|
||||
qa_flow.run(shared)
|
||||
print("Question:", shared["question"])
|
||||
print("Answer:", shared["answer"])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,13 @@
|
||||
from openai import OpenAI
|
||||
|
||||
def call_llm(prompt):
|
||||
client = OpenAI(api_key="YOUR_API_KEY_HERE")
|
||||
r = client.chat.completions.create(
|
||||
model="gpt-4o",
|
||||
messages=[{"role": "user", "content": prompt}]
|
||||
)
|
||||
return r.choices[0].message.content
|
||||
|
||||
if __name__ == "__main__":
|
||||
prompt = "What is the meaning of life?"
|
||||
print(call_llm(prompt))
|
||||
Reference in New Issue
Block a user