From 9995ccd4c7d069ff190df664fdac1c6408a174bb Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 21 Dec 2023 08:31:54 +0200 Subject: [PATCH 1/2] feat: Update PR description prompts in toml file to include semantic file types and custom labels options --- pr_agent/settings/pr_description_prompts.toml | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 7538e4aa..fee9b8b9 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -1,6 +1,10 @@ [pr_description_prompt] system="""You are PR-Reviewer, a language model designed to review a Git Pull Request (PR). -Your task is to provide a full description for the PR content - title, type, description, and main files walkthrough. +{%- if enable_custom_labels %} +Your task is to provide a full description for the PR content - files walkthrough, title, type, description and labels. +{%- else %} +Your task is to provide a full description for the PR content - files walkthrough, title, type, and description. +{%- endif %} - Focus on the new PR code (lines starting with '+'). - Keep in mind that the 'Previous title', 'Previous description' and 'Commit messages' sections may be partial, simplistic, non-informative or out of date. Hence, compare them to the PR diff code, and use them only as a reference. - The generated title and description should prioritize the most significant changes. @@ -46,24 +50,31 @@ Class FileDescription(BaseModel): {%- endif %} Class PRDescription(BaseModel): +{%- if enable_semantic_files_types %} + pr_files[List[FileDescription]] = Field(max_items=15, description="a list of the files in the PR, and their changes summary.") +{%- endif %} title: str = Field(description="an informative title for the PR, describing its main theme") type: List[PRType] = Field(description="one or more types that describe the PR type. Return the label value, not the name.") description: str = Field(description="an informative and concise description of the PR. {%- if use_bullet_points %} Use bullet points.{% endif %}") {%- if enable_custom_labels %} labels: List[Label] = Field(min_items=0, description="choose the relevant custom labels that describe the PR content, and return their keys. Use the value field of the Label object to better understand the label meaning.") {%- endif %} -{%- if enable_file_walkthrough %} - main_files_walkthrough: List[FileWalkthrough] = Field(max_items=10) -{%- endif %} -{%- if enable_semantic_files_types %} - pr_files[List[FileDescription]] = Field(max_items=15") -{%- endif %} ===== Example output: ```yaml +{%- if enable_semantic_files_types %} +pr_files: +- filename: | + ... + changes_summary: | + ... + label: | + ... +... +{%- endif %} title: |- ... type: @@ -78,21 +89,6 @@ labels: {%- endif %} description: |- ... -{%- if enable_file_walkthrough %} -main_files_walkthrough: -- ... -- ... -{%- endif %} -{%- if enable_semantic_files_types %} -pr_files: -- filename: | - ... - changes_summary: | - ... - label: | - ... -... -{%- endif %} ``` Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|-') From eca807807185655537cab95de1f5547632fa7e30 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Thu, 21 Dec 2023 08:51:57 +0200 Subject: [PATCH 2/2] feat: Reorder keys in PR description data and update PRDescription model in toml file --- pr_agent/settings/pr_description_prompts.toml | 14 +++++++------- pr_agent/tools/pr_description.py | 13 ++++++++++++- pr_agent/tools/pr_generate_labels.py | 1 - 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index fee9b8b9..38c53e48 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -50,12 +50,12 @@ Class FileDescription(BaseModel): {%- endif %} Class PRDescription(BaseModel): + type: List[PRType] = Field(description="one or more types that describe the PR content. Return the label value, not the name.") {%- if enable_semantic_files_types %} pr_files[List[FileDescription]] = Field(max_items=15, description="a list of the files in the PR, and their changes summary.") {%- endif %} + description: str = Field(description="an informative and concise description of the PR. Use bullet points. Display first the most significant changes.") title: str = Field(description="an informative title for the PR, describing its main theme") - type: List[PRType] = Field(description="one or more types that describe the PR type. Return the label value, not the name.") - description: str = Field(description="an informative and concise description of the PR. {%- if use_bullet_points %} Use bullet points.{% endif %}") {%- if enable_custom_labels %} labels: List[Label] = Field(min_items=0, description="choose the relevant custom labels that describe the PR content, and return their keys. Use the value field of the Label object to better understand the label meaning.") {%- endif %} @@ -65,6 +65,9 @@ Class PRDescription(BaseModel): Example output: ```yaml +type: +- ... +- ... {%- if enable_semantic_files_types %} pr_files: - filename: | @@ -75,11 +78,10 @@ pr_files: ... ... {%- endif %} +description: |- + ... title: |- ... -type: -- ... -- ... {%- if enable_custom_labels %} labels: - | @@ -87,8 +89,6 @@ labels: - | ... {%- endif %} -description: |- - ... ``` Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|-') diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 9e3b22a1..d79c2d50 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -48,7 +48,6 @@ class PRDescription: "description": self.git_provider.get_pr_description(full=False), "language": self.main_pr_language, "diff": "", # empty diff for initial calculation - "use_bullet_points": get_settings().pr_description.use_bullet_points, "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), "enable_custom_labels": get_settings().config.enable_custom_labels, @@ -187,6 +186,18 @@ class PRDescription: # Load the AI prediction data into a dictionary self.data = load_yaml(self.prediction.strip()) + # re-order keys + if 'title' in self.data: + self.data['title'] = self.data.pop('title') + if 'type' in self.data: + self.data['type'] = self.data.pop('type') + if 'labels' in self.data: + self.data['labels'] = self.data.pop('labels') + if 'description' in self.data: + self.data['description'] = self.data.pop('description') + if 'pr_files' in self.data: + self.data['pr_files'] = self.data.pop('pr_files') + if get_settings().pr_description.add_original_user_description and self.user_description: self.data["User Description"] = self.user_description diff --git a/pr_agent/tools/pr_generate_labels.py b/pr_agent/tools/pr_generate_labels.py index 03dbe14c..a606ab4a 100644 --- a/pr_agent/tools/pr_generate_labels.py +++ b/pr_agent/tools/pr_generate_labels.py @@ -43,7 +43,6 @@ class PRGenerateLabels: "description": self.git_provider.get_pr_description(full=False), "language": self.main_pr_language, "diff": "", # empty diff for initial calculation - "use_bullet_points": get_settings().pr_description.use_bullet_points, "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), "enable_custom_labels": get_settings().config.enable_custom_labels,