Skip to content

Commit dc4d445

Browse files
committed
update readme examples
1 parent b63a1c1 commit dc4d445

File tree

7 files changed

+1054
-56
lines changed

7 files changed

+1054
-56
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
This is a tutorial project of [Pocket Flow](https://github.com/The-Pocket/PocketFlow), a 100-line LLM framework. It crawls GitHub repositories and build a knowledge base from the code. It analyzes entire codebases to identify core abstractions and how they interact, and transforms complex code into beginner-friendly tutorials with clear visualizations.
1818

19-
## Example Tutorials for Popular GitHub Repositories!
19+
## Example Tutorials for Popular GitHub Repositories!
2020

2121
- [AutoGen Core](https://the-pocket.github.io/Tutorial-Codebase-Knowledge/AutoGen%20Core) - Build AI teams that talk, think, and solve problems together like coworkers!
2222

flow.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
from pocketflow import Flow
2-
from nodes import GetQuestionNode, AnswerNode
3-
4-
def create_qa_flow():
5-
"""Create and return a question-answering flow."""
6-
# Create nodes
7-
get_question_node = GetQuestionNode()
8-
answer_node = AnswerNode()
9-
10-
# Connect nodes in sequence
11-
get_question_node >> answer_node
12-
13-
# Create flow starting with input node
14-
return Flow(start=get_question_node)
2+
# Import all node classes from nodes.py
3+
from nodes import (
4+
FetchRepo,
5+
IdentifyAbstractions,
6+
AnalyzeRelationships,
7+
OrderChapters,
8+
WriteChapters,
9+
CombineTutorial
10+
)
11+
12+
def create_tutorial_flow():
13+
"""Creates and returns the codebase tutorial generation flow."""
14+
15+
# Instantiate nodes
16+
fetch_repo = FetchRepo()
17+
identify_abstractions = IdentifyAbstractions(max_retries=3, wait=10)
18+
analyze_relationships = AnalyzeRelationships(max_retries=3, wait=10)
19+
order_chapters = OrderChapters(max_retries=3, wait=10)
20+
write_chapters = WriteChapters(max_retries=3, wait=10) # This is a BatchNode
21+
combine_tutorial = CombineTutorial()
22+
23+
# Connect nodes in sequence based on the design
24+
fetch_repo >> identify_abstractions
25+
identify_abstractions >> analyze_relationships
26+
analyze_relationships >> order_chapters
27+
order_chapters >> write_chapters
28+
write_chapters >> combine_tutorial
29+
30+
# Create the flow starting with FetchRepo
31+
tutorial_flow = Flow(start=fetch_repo)
32+
33+
return tutorial_flow

main.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,67 @@
1-
from flow import qa_flow
1+
import os
2+
import argparse
3+
# Import the function that creates the flow
4+
from flow import create_tutorial_flow
25

3-
# Example main function
4-
# Please replace this with your own main function
6+
# Default file patterns
7+
DEFAULT_INCLUDE_PATTERNS = {
8+
"*.py", "*.js", "*.ts", "*.go", "*.java", "*.pyi", "*.pyx",
9+
"*.c", "*.cc", "*.cpp", "*.h", "*.md", "*.rst", "Dockerfile",
10+
"Makefile", "*.yaml", "*.yml"
11+
}
12+
13+
DEFAULT_EXCLUDE_PATTERNS = {
14+
"*test*", "tests/*", "docs/*", "examples/*", "v1/*",
15+
"dist/*", "build/*", "experimental/*", "deprecated/*",
16+
"legacy/*", ".git/*", ".github/*"
17+
}
18+
19+
# --- Main Function ---
520
def main():
21+
parser = argparse.ArgumentParser(description="Generate a tutorial for a GitHub codebase.")
22+
parser.add_argument("repo_url", help="URL of the public GitHub repository.")
23+
parser.add_argument("-n", "--name", help="Project name (optional, derived from URL if omitted).")
24+
parser.add_argument("-t", "--token", help="GitHub personal access token (optional, reads from GITHUB_TOKEN env var if not provided).")
25+
parser.add_argument("-o", "--output", default="output", help="Base directory for output (default: ./output).")
26+
parser.add_argument("-i", "--include", nargs="+", help="Include file patterns (e.g. '*.py' '*.js'). Defaults to common code files if not specified.")
27+
parser.add_argument("-e", "--exclude", nargs="+", help="Exclude file patterns (e.g. 'tests/*' 'docs/*'). Defaults to test/build directories if not specified.")
28+
parser.add_argument("-s", "--max-size", type=int, default=100000, help="Maximum file size in bytes (default: 100000, about 100KB).")
29+
30+
args = parser.parse_args()
31+
32+
# Get GitHub token from argument or environment variable
33+
github_token = args.token or os.environ.get('GITHUB_TOKEN')
34+
if not github_token:
35+
print("Warning: No GitHub token provided. You might hit rate limits for public repositories.")
36+
37+
# Initialize the shared dictionary with inputs
638
shared = {
7-
"question": "In one sentence, what's the end of universe?",
8-
"answer": None
39+
"repo_url": args.repo_url,
40+
"project_name": args.name, # Can be None, FetchRepo will derive it
41+
"github_token": github_token,
42+
"output_dir": args.output, # Base directory for CombineTutorial output
43+
44+
# Add include/exclude patterns and max file size
45+
"include_patterns": set(args.include) if args.include else DEFAULT_INCLUDE_PATTERNS,
46+
"exclude_patterns": set(args.exclude) if args.exclude else DEFAULT_EXCLUDE_PATTERNS,
47+
"max_file_size": args.max_size,
48+
49+
# Outputs will be populated by the nodes
50+
"files": [],
51+
"abstractions": [],
52+
"relationships": {},
53+
"chapter_order": [],
54+
"chapters": [],
55+
"final_output_dir": None
956
}
1057

11-
qa_flow.run(shared)
12-
print("Question:", shared["question"])
13-
print("Answer:", shared["answer"])
58+
print(f"Starting tutorial generation for: {args.repo_url}")
59+
60+
# Create the flow instance
61+
tutorial_flow = create_tutorial_flow()
1462

63+
# Run the flow
64+
tutorial_flow.run(shared)
65+
1566
if __name__ == "__main__":
1667
main()

0 commit comments

Comments
 (0)