-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_humans.py
More file actions
55 lines (44 loc) · 2.45 KB
/
Copy pathadd_humans.py
File metadata and controls
55 lines (44 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import json
with open("C:\\PersonalRepo\\portfolio\\autogen\\autogen_dashboard\\blueprints.py", "r", encoding="utf-8") as f:
content = f.read()
# We need to add the human-operator node to each phase, and link it to the first meta node.
# e.g., Phase 1: 1.1 Intent Translation
# Phase 2: 2.1 Feature Impl
# Phase 3: 3.1 Auto Test Gen
# Phase 4: 4.1 Auto Patching
# Phase 5: 5.1 PR Review
# Phase 6: 6.1 Continuous Tech Debt
import re
for i in range(1, 7):
node_str = f' {{"id": "human-operator", "label": "Human Operator (You)", "type": "customNode", "status": "System Prompt", "instructions": "You govern the entire OS.", "parentId": f"p{i}-group"}},'
edge_str = f' {{"type": "edge_created", "data": {{"id": f"p{i}-e0", "source": "human-operator", "target": f"{i}.1", "label": "Triggers Phase"}}}},'
# Add node
search_node = f'phase{i}_nodes = [\n {{"id": "p{i}-group"'
replace_node = f'phase{i}_nodes = [\n {{"id": "p{i}-group"...\n{node_str}'
content = re.sub(
rf'phase{i}_nodes = \[\n {{"id": "p{i}-group"(.*?)\]',
lambda m: f'phase{i}_nodes = [\n {{"id": "p{i}-group"{m.group(1).split(",")[0] + "," + m.group(1).split(",", 1)[1]}\n{node_str}',
content,
flags=re.DOTALL
)
# The regex approach is messy, let's just do simple splits.
def add_human(phase_num):
global content
# Add node
target_node = f'{{"id": "p{phase_num}-group"'
idx = content.find(target_node)
end_of_line = content.find('\n', idx)
node_str = f'\n {{"id": "human-operator", "label": "Human Operator (You)", "type": "customNode", "status": "System Prompt", "instructions": "You govern the entire OS.", "parentId": "p{phase_num}-group"}},'
content = content[:end_of_line] + node_str + content[end_of_line:]
# Add edge
target_edge = f'phase{phase_num}_edges = ['
idx = content.find(target_edge)
end_of_line = content.find('\n', idx)
edge_str = f'\n {{"type": "edge_created", "data": {{"id": "p{phase_num}-e0", "source": "human-operator", "target": "{phase_num}.1", "label": "Triggers Phase"}}}},'
content = content[:end_of_line] + edge_str + content[end_of_line:]
with open("C:\\PersonalRepo\\portfolio\\autogen\\autogen_dashboard\\blueprints.py", "r", encoding="utf-8") as f:
content = f.read()
for i in range(1, 7):
add_human(i)
with open("C:\\PersonalRepo\\portfolio\\autogen\\autogen_dashboard\\blueprints.py", "w", encoding="utf-8") as f:
f.write(content)