Skip to content

Commit 22a3f2e

Browse files
authored
Patchflow that generates architecture diagram (#1022)
* added patchflow to generate architecture * added readme * added tests to CI * Update test.yml
1 parent df45086 commit 22a3f2e

File tree

7 files changed

+121
-1
lines changed

7 files changed

+121
-1
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ jobs:
201201
--github_api_key=${{ secrets.SCM_GITHUB_KEY }} \
202202
--base_path=tests/cicd/generate_docstring \
203203
--disable_telemetry
204+
205+
- name : Generate Diagram
206+
run: |
207+
poetry run patchwork GenerateDiagram --log debug \
208+
--patched_api_key=${{ secrets.PATCHED_API_KEY }} \
209+
--github_api_key=${{ secrets.SCM_GITHUB_KEY }} \
210+
--disable_telemetry
204211
205212
- name: Generate UnitTests
206213
run: |
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import json
2+
from pathlib import Path
3+
import yaml
4+
5+
from patchwork.common.utils.step_typing import validate_steps_with_inputs
6+
from patchwork.step import Step
7+
from patchwork.steps import (
8+
LLM,
9+
CallCode2Prompt,
10+
ModifyCode,
11+
PR
12+
)
13+
14+
_DEFAULT_INPUT_FILE = Path(__file__).parent / "defaults.yml"
15+
_DEFAULT_PROMPT_JSON = Path(__file__).parent / "default_prompt.json"
16+
17+
class GenerateDiagram(Step):
18+
def __init__(self, inputs):
19+
super().__init__(inputs)
20+
21+
final_inputs = yaml.safe_load(_DEFAULT_INPUT_FILE.read_text())
22+
if final_inputs is None:
23+
final_inputs = {}
24+
25+
final_inputs.update(inputs)
26+
27+
final_inputs["prompt_id"] = "GenerateDiagram"
28+
if "folder_path" not in final_inputs.keys():
29+
final_inputs["folder_path"] = Path.cwd()
30+
else:
31+
final_inputs["folder_path"] = Path(final_inputs["folder_path"])
32+
33+
print(final_inputs["folder_path"])
34+
35+
if "prompt_template_file" not in final_inputs:
36+
final_inputs["prompt_template_file"] = _DEFAULT_PROMPT_JSON
37+
38+
final_inputs["pr_title"] = f"PatchWork System Architecture Diagram generated"
39+
final_inputs["branch_prefix"] = f"{self.__class__.__name__.lower()}-"
40+
41+
validate_steps_with_inputs(
42+
set(final_inputs.keys()).union({"prompt_values","files_to_patch"}), LLM, CallCode2Prompt,ModifyCode,PR
43+
)
44+
self.inputs = final_inputs
45+
46+
def run(self):
47+
outputs = CallCode2Prompt(self.inputs).run()
48+
new_file_name = f"diagram.md"
49+
new_file_path = Path(outputs['uri']).with_name(new_file_name)
50+
Path(outputs['uri']).rename(new_file_path)
51+
outputs['uri'] = str(new_file_path)
52+
self.inputs["response_partitions"] = {"patch": ["```", "\n", "```"]}
53+
self.inputs["files_to_patch"] = self.inputs["prompt_values"] = [outputs]
54+
outputs = LLM(self.inputs).run()
55+
self.inputs.update(outputs)
56+
outputs = ModifyCode(self.inputs).run()
57+
self.inputs.update(outputs)
58+
self.inputs["pr_header"] = f"This pull request from patchwork generates system architecture diagram."
59+
outputs = PR(self.inputs).run()
60+
self.inputs.update(outputs)
61+
62+
return self.inputs
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## GenerateDiagram Code Overview
2+
3+
### Inputs
4+
- The code reads default inputs from a YAML file.
5+
- It updates the default inputs with any additional inputs provided.
6+
- It sets up various parameters like folder path, prompt template file, PR title, branch prefix, etc.
7+
- It validates the inputs with specific steps required for the process.
8+
9+
### Outputs
10+
- The code runs a series of steps to generate a system architecture diagram.
11+
- It utilizes classes like LLM, CallCode2Prompt, ModifyCode, and PR to process the inputs.
12+
- The final output is a set of inputs updated with the results of each step.
13+
- The code is designed to generate a pull request with the system architecture diagram.

patchwork/patchflows/GenerateDiagram/__init__.py

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"id": "GenerateDiagram",
4+
"prompts": [
5+
{
6+
"role": "system",
7+
"content": "You are an experienced software architect skilled at visualizing system designs. Users will provide repository details, and you will generate a comprehensive system architecture diagram using Mermaid markdown syntax. Output the diagram code directly with no additional text, formatting, or triple quotes. The response should be ready to be pasted into an editor supporting Mermaid syntax."
8+
},
9+
{
10+
"role": "user",
11+
"content": "Repo Details: {{fullContent}}"
12+
}
13+
]
14+
}
15+
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# CallLLM Inputs
2+
# openai_api_key: required-for-chatgpt
3+
# google_api_key: required-for-gemini
4+
# model: gpt-4o
5+
# client_base_url: https://api.openai.com/v1
6+
# Example HF model
7+
# client_base_url: https://api-inference.huggingface.co/models/codellama/CodeLlama-70b-Instruct-hf/v1
8+
# model: codellama/CodeLlama-70b-Instruct-hf
9+
# model_temperature: 0.2
10+
# model_top_p: 0.95
11+
# model_max_tokens: 2000
12+
13+
# folder_path : path/to/folder/with/class
14+
15+
# CommitChanges Inputs
16+
disable_branch: false
17+
18+
# CreatePR Inputs
19+
disable_pr: false
20+
force_pr_creation: true
21+
# github_api_key: required-for-github-scm
22+
# gitlab_api_key: required-for-gitlab-scm

patchwork/patchflows/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from .PRReview.PRReview import PRReview
66
from .ResolveIssue.ResolveIssue import ResolveIssue
77
from .GenerateUnitTests.GenerateUnitTests import GenerateUnitTests
8+
from .GenerateDiagram.GenerateDiagram import GenerateDiagram
89

9-
__all__ = ["AutoFix", "DependencyUpgrade", "GenerateREADME", "PRReview", "ResolveIssue", "GenerateDocstring", "GenerateUnitTests"]
10+
__all__ = ["AutoFix", "DependencyUpgrade", "GenerateREADME", "PRReview", "ResolveIssue", "GenerateDocstring", "GenerateUnitTests","GenerateDiagram"]

0 commit comments

Comments
 (0)