update doc example and desc
This commit is contained in:
parent
f4e9e6f1e6
commit
1246f1a492
|
|
@ -13,19 +13,19 @@ Many real-world tasks are too complex for one LLM call. The solution is to decom
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class GenerateOutline(Node):
|
class GenerateOutline(Node):
|
||||||
def exec(self, topic):
|
def prep(self, shared): return shared["topic"]
|
||||||
prompt = f"Create a detailed outline for an article about {topic}"
|
def exec(self, topic): return call_llm(f"Create a detailed outline for an article about {topic}")
|
||||||
return call_llm(prompt)
|
def post(self, shared, prep_res, exec_res): shared["outline"] = exec_res
|
||||||
|
|
||||||
class WriteSection(Node):
|
class WriteSection(Node):
|
||||||
def exec(self, section):
|
def prep(self, shared): return shared["outline"]
|
||||||
prompt = f"Write content for this section: {section}"
|
def exec(self, outline): return call_llm(f"Write content based on this outline: {outline}")
|
||||||
return call_llm(prompt)
|
def post(self, shared, prep_res, exec_res): shared["draft"] = exec_res
|
||||||
|
|
||||||
class ReviewAndRefine(Node):
|
class ReviewAndRefine(Node):
|
||||||
def exec(self, draft):
|
def prep(self, shared): return shared["draft"]
|
||||||
prompt = f"Review and improve this draft: {draft}"
|
def exec(self, draft): return call_llm(f"Review and improve this draft: {draft}")
|
||||||
return call_llm(prompt)
|
def post(self, shared, prep_res, exec_res): shared["final_article"] = exec_res
|
||||||
|
|
||||||
# Connect nodes
|
# Connect nodes
|
||||||
outline = GenerateOutline()
|
outline = GenerateOutline()
|
||||||
|
|
@ -34,7 +34,8 @@ review = ReviewAndRefine()
|
||||||
|
|
||||||
outline >> write >> review
|
outline >> write >> review
|
||||||
|
|
||||||
# Create flow
|
# Create and run flow
|
||||||
writing_flow = Flow(start=outline)
|
writing_flow = Flow(start=outline)
|
||||||
writing_flow.run({"topic": "AI Safety"})
|
shared = {"topic": "AI Safety"}
|
||||||
|
writing_flow.run(shared)
|
||||||
```
|
```
|
||||||
|
|
|
||||||
25
docs/node.md
25
docs/node.md
|
|
@ -9,24 +9,23 @@ nav_order: 1
|
||||||
|
|
||||||
A **Node** is the smallest building block of Mini LLM Flow. Each Node has 3 steps:
|
A **Node** is the smallest building block of Mini LLM Flow. Each Node has 3 steps:
|
||||||
|
|
||||||
1. **`prep(shared)`**
|
1. `prep(shared)`
|
||||||
- Reads and preprocesses data from the `shared` store for LLMs.
|
- A reliable step for preprocessing data from the `shared` store.
|
||||||
- Examples: *query DB, read files, or serialize data into a string*.
|
- Examples: *query DB, read files, or serialize data into a string*.
|
||||||
- Returns `prep_res`, which will be passed to both `exec()` and `post()`.
|
- Returns `prep_res`, which is used by `exec()` and `post()`.
|
||||||
|
|
||||||
2. **`exec(prep_res)`**
|
2. `exec(prep_res)`
|
||||||
- The main execution step where the LLM is called.
|
- The **main execution** step, with optional retries and error handling (below).
|
||||||
- Optionally has built-in retry and error handling (below).
|
- Examples: *primarily for LLMs, but can also for remote APIs*。
|
||||||
- ⚠️ If retry enabled, ensure implementation is idempotent.
|
- ⚠️ If retries enabled, ensure idempotent implementation.
|
||||||
- Returns `exec_res`, which is passed to `post()`.
|
- Returns `exec_res`, which is passed to `post()`.
|
||||||
|
|
||||||
3. **`post(shared, prep_res, exec_res)`**
|
3.`post(shared, prep_res, exec_res)`
|
||||||
- Writes results back to the `shared` store or decides the next action.
|
- A reliable postprocessing step to write results back to the `shared` store and decide the next Action.
|
||||||
- Examples: *finalize outputs, trigger next steps, or log results*.
|
- Examples: *update DB, change states, log results, decide next Action*.
|
||||||
- Returns a **string** to specify the next action (`"default"` if nothing or `None` is returned).
|
- Returns a **string** specifying the next Action (`"default"` if none).
|
||||||
|
|
||||||
|
> All 3 steps are optional. You could run only `prep` if you just need to prepare data without calling the LLM.
|
||||||
> All 3 steps are optional. For example, you might only need to run the Prep without calling the LLM.
|
|
||||||
{: .note }
|
{: .note }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue