change the syntax of exec

This commit is contained in:
zachary62
2024-12-29 02:40:27 +00:00
parent 96cecb9086
commit 2550decdc5
11 changed files with 103 additions and 101 deletions
+5 -3
View File
@@ -19,9 +19,11 @@ Below is a minimal **AsyncNode** that calls an LLM in `exec()` to summarize text
```python
class SummarizeThenVerify(AsyncNode):
def exec(self, shared, prep_res):
doc = shared.get("doc", "")
return call_llm(f"Summarize: {doc}")
def prep(self, shared):
return shared.get("doc", "")
def exec(self, prep_res):
return call_llm(f"Summarize: {prep_res}")
async def post_async(self, shared, prep_res, exec_res):
user_decision = await gather_user_feedback(exec_res)
+3 -3
View File
@@ -9,7 +9,7 @@ nav_order: 3
Nodes and Flows **communicate** in two ways:
1. **Shared Store** A global data structure (often an in-mem dict) that all nodes can read from and write to. Every Nodes `prep()`, `exec()`, and `post()` methods receive the **same** `shared` store.
1. **Shared Store** A global data structure (often an in-mem dict) that all nodes can read from and write to. Every Nodes `prep()` and `post()` methods receive the **same** `shared` store.
2. **Params** Each node and Flow has a `params` dict assigned by the **parent Flow**. Params mostly serve as identifiers, letting each node/flow know what task its assigned.
If you know memory management, **Shared Store** is like a **heap** shared across function calls, while **Params** is like a **stack** assigned by parent function calls.
@@ -47,7 +47,7 @@ class Summarize(Node):
content = shared["data"].get("my_file.txt", "")
return content
def exec(self, shared, prep_res):
def exec(self, prep_res):
prompt = f"Summarize: {prep_res}"
summary = call_llm(prompt)
return summary
@@ -91,7 +91,7 @@ class SummarizeFile(Node):
filename = self.params["filename"]
return shared["data"].get(filename, "")
def exec(self, shared, prep_res):
def exec(self, prep_res):
prompt = f"Summarize: {prep_res}"
return call_llm(prompt)
+4 -3
View File
@@ -14,9 +14,10 @@ A **Node** is the smallest building block of Mini LLM Flow. Each Node has three
- Often used for tasks like reading files, chunking text, or validation.
- Returns `prep_res`, which will be passed to both `exec()` and `post()`.
2. **`exec(shared, prep_res)`**
2. **`exec(prep_res)`**
- The main execution step where the LLM is called.
- Has a built-in retry feature to handle errors and ensure reliable results.
- Optionally has built-in retry and error handling (below).
- ⚠️ If retry enabled, ensure implementation is idempotent.
- Returns `exec_res`, which is passed to `post()`.
3. **`post(shared, prep_res, exec_res)`**
@@ -55,7 +56,7 @@ class SummarizeFile(Node):
filename = self.params["filename"]
return shared["data"][filename]
def exec(self, shared, prep_res):
def exec(self, prep_res):
if not prep_res:
raise ValueError("Empty file content!")
prompt = f"Summarize this text in 10 words: {prep_res}"