From 3360a28b3e7c7e2885a12f0cee8a4ac7c58a422e Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 23 Dec 2024 17:06:21 +0200 Subject: [PATCH 1/4] fix: improve changelog update prompt and response handling --- pr_agent/algo/__init__.py | 1 + .../settings/pr_update_changelog_prompts.toml | 15 ++++++++++----- pr_agent/tools/pr_update_changelog.py | 7 +++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pr_agent/algo/__init__.py b/pr_agent/algo/__init__.py index cf09f4ad..cfa1bbe3 100644 --- a/pr_agent/algo/__init__.py +++ b/pr_agent/algo/__init__.py @@ -62,6 +62,7 @@ MAX_TOKENS = { 'bedrock/anthropic.claude-3-5-haiku-20241022-v1:0': 100000, 'bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0': 100000, 'bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0': 100000, + "bedrock/us.anthropic.claude-3-5-sonnet-20241022-v2:0": 100000, 'claude-3-5-sonnet': 100000, 'groq/llama3-8b-8192': 8192, 'groq/llama3-70b-8192': 8192, diff --git a/pr_agent/settings/pr_update_changelog_prompts.toml b/pr_agent/settings/pr_update_changelog_prompts.toml index 121f43a0..a5769355 100644 --- a/pr_agent/settings/pr_update_changelog_prompts.toml +++ b/pr_agent/settings/pr_update_changelog_prompts.toml @@ -1,9 +1,11 @@ [pr_update_changelog_prompt] system="""You are a language model called PR-Changelog-Updater. -Your task is to update the CHANGELOG.md file of the project, to shortly summarize important changes introduced in this PR (the '+' lines). -- The output should match the existing CHANGELOG.md format, style and conventions, so it will look like a natural part of the file. For example, if previous changes were summarized in a single line, you should do the same. -- Don't repeat previous changes. Generate only new content, that is not already in the CHANGELOG.md file. -- Be general, and avoid specific details, files, etc. The output should be minimal, no more than 3-4 short lines. Ignore non-relevant subsections. +Your task is to add a brief summary of this PR's changes to CHANGELOG.md file of the project: +- Follow the file's existing format and style conventions like dates, section titles, etc. +- Only add new changes (don't repeat existing entries) +- Be general, and avoid specific details, files, etc. The output should be minimal, no more than 3-4 short lines. +- Write only the new content to be added to CHANGELOG.md, without any introduction or summary. The content should appear as if it's a natural part of the existing file. + {%- if extra_instructions %} @@ -47,16 +49,19 @@ The PR Git Diff: {{ diff|trim }} ====== + Current date: ``` {{today}} ``` -The current CHANGELOG.md: + +The current 'CHANGELOG.md' file ====== {{ changelog_file_str }} ====== Response: +```markdown """ diff --git a/pr_agent/tools/pr_update_changelog.py b/pr_agent/tools/pr_update_changelog.py index b18a966c..79acf4f5 100644 --- a/pr_agent/tools/pr_update_changelog.py +++ b/pr_agent/tools/pr_update_changelog.py @@ -108,6 +108,13 @@ class PRUpdateChangelog: response, finish_reason = await self.ai_handler.chat_completion( model=model, system=system_prompt, user=user_prompt, temperature=get_settings().config.temperature) + # post-process the response + response = response.strip() + if response.startswith("```"): + response_lines = response.splitlines() + response_lines = response_lines[1:] + response = "\n".join(response_lines) + response = response.strip("`") return response def _prepare_changelog_update(self) -> Tuple[str, str]: From e8e4fb0afa38b0c5c6878cdd38500b5ab47ea957 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 23 Dec 2024 17:20:29 +0200 Subject: [PATCH 2/4] feat: add PR link support in changelog updates --- pr_agent/settings/configuration.toml | 1 + pr_agent/settings/pr_update_changelog_prompts.toml | 3 +++ pr_agent/tools/pr_update_changelog.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 38a19412..16461b7e 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -162,6 +162,7 @@ class_name = "" # in case there are several methods with the same name in [pr_update_changelog] # /update_changelog # push_changelog_changes=false extra_instructions = "" +add_pr_link=true [pr_analyze] # /analyze # enable_help_text=true diff --git a/pr_agent/settings/pr_update_changelog_prompts.toml b/pr_agent/settings/pr_update_changelog_prompts.toml index a5769355..6825da66 100644 --- a/pr_agent/settings/pr_update_changelog_prompts.toml +++ b/pr_agent/settings/pr_update_changelog_prompts.toml @@ -5,6 +5,9 @@ Your task is to add a brief summary of this PR's changes to CHANGELOG.md file of - Only add new changes (don't repeat existing entries) - Be general, and avoid specific details, files, etc. The output should be minimal, no more than 3-4 short lines. - Write only the new content to be added to CHANGELOG.md, without any introduction or summary. The content should appear as if it's a natural part of the existing file. +{%- if pr_link %} +- If relevant, convert the changelog main header into a clickable link using the PR URL '{{ pr_link }}'. Format: header [*][pr_link] +{%- endif %} {%- if extra_instructions %} diff --git a/pr_agent/tools/pr_update_changelog.py b/pr_agent/tools/pr_update_changelog.py index 79acf4f5..10547534 100644 --- a/pr_agent/tools/pr_update_changelog.py +++ b/pr_agent/tools/pr_update_changelog.py @@ -41,6 +41,7 @@ class PRUpdateChangelog: "description": self.git_provider.get_pr_description(), "language": self.main_language, "diff": "", # empty diff for initial calculation + "pr_link": "", "changelog_file_str": self.changelog_file_str, "today": date.today(), "extra_instructions": get_settings().pr_update_changelog.extra_instructions, @@ -102,6 +103,8 @@ class PRUpdateChangelog: async def _get_prediction(self, model: str): variables = copy.deepcopy(self.vars) variables["diff"] = self.patches_diff # update diff + if get_settings().pr_update_changelog.add_pr_link: + variables["pr_link"] = self.git_provider.get_pr_url() environment = Environment(undefined=StrictUndefined) system_prompt = environment.from_string(get_settings().pr_update_changelog_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_update_changelog_prompt.user).render(variables) From dd89e1f2dc44910b8c923b14d87a711dc179ea96 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 23 Dec 2024 19:34:21 +0200 Subject: [PATCH 3/4] feat: add PR link support in changelog updates --- docs/docs/tools/update_changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/tools/update_changelog.md b/docs/docs/tools/update_changelog.md index 9f880ccd..ff789622 100644 --- a/docs/docs/tools/update_changelog.md +++ b/docs/docs/tools/update_changelog.md @@ -17,3 +17,4 @@ Under the section `pr_update_changelog`, the [configuration file](https://github - `push_changelog_changes`: whether to push the changes to CHANGELOG.md, or just print them. Default is false (print only). - `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ... +- `add_pr_link`: whether the model should try to add a link to the PR in the changelog. Default is true. \ No newline at end of file From 6c131b8406f02a1c1af1fecc0e8e6cf89f166448 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 23 Dec 2024 19:35:52 +0200 Subject: [PATCH 4/4] feat: add PR link support in changelog updates --- pr_agent/tools/pr_update_changelog.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pr_agent/tools/pr_update_changelog.py b/pr_agent/tools/pr_update_changelog.py index 10547534..fadf28f1 100644 --- a/pr_agent/tools/pr_update_changelog.py +++ b/pr_agent/tools/pr_update_changelog.py @@ -113,6 +113,8 @@ class PRUpdateChangelog: # post-process the response response = response.strip() + if not response: + return "" if response.startswith("```"): response_lines = response.splitlines() response_lines = response_lines[1:]