https://github.com/lenml/pflow
LLM framework pocketflow-like.
https://github.com/lenml/pflow
Last synced: 11 months ago
JSON representation
LLM framework pocketflow-like.
- Host: GitHub
- URL: https://github.com/lenml/pflow
- Owner: lenML
- License: agpl-3.0
- Created: 2025-05-20T02:30:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-07T15:48:32.000Z (about 1 year ago)
- Last Synced: 2025-06-07T16:42:28.656Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pflow
enhancement pocket-flow
## features
- typing safety
- Practical Experience
# usage
```ts
import { Node, Flow, Shared, Action } from "@lenml/pflow";
// ... some utils
interface Message {
role: string;
content: string;
}
type Messages = Message[];
class ChatNode extends Node> {
async prep(): Promise {
const { messages } = this._shared.data;
const user_input = await prompt("User: ");
if (user_input === "exit") {
return null;
}
messages.push({ role: "user", content: user_input });
return messages;
}
async exec(prepRes: Messages | null): Promise {
if (prepRes === null) return null;
const resp = await get_llm_completions(prepRes);
return resp.choices[0].message.content;
}
async post(
prepRes: Messages | null,
execRes: string
): Promise {
if (prepRes === null || execRes === null) {
console.log("\nGoodbye!");
return undefined;
}
console.log(`\nAssistant: ${execRes}`);
this._shared.data.messages.push({ role: "assistant", content: execRes });
return "continue";
}
}
const shared = new Shared<{
messages: Messages;
}>({ messages: [] });
const chat_node = new ChatNode();
chat_node.on("continue", chat_node);
const chat_flow = new Flow(chat_node);
chat_flow.setShared(shared);
chat_flow.run();
```