Skip to content

Commit

Permalink
Merge pull request #1410 from Codium-ai/tr/update_changelog_fix
Browse files Browse the repository at this point in the history
Tr/update changelog fix
  • Loading branch information
mrT23 authored Dec 23, 2024
2 parents 20c506d + 6c131b8 commit 93e6436
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/docs/tools/update_changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions pr_agent/algo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'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,
Expand Down
1 change: 1 addition & 0 deletions pr_agent/settings/configuration.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions pr_agent/settings/pr_update_changelog_prompts.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[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 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 %}
Expand Down Expand Up @@ -47,16 +52,19 @@ The PR Git Diff:
{{ diff|trim }}
======
Current date:
```
{{today}}
```
The current CHANGELOG.md:
The current 'CHANGELOG.md' file
======
{{ changelog_file_str }}
======
Response:
```markdown
"""
12 changes: 12 additions & 0 deletions pr_agent/tools/pr_update_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(self, pr_url: str, cli_mode=False, args=None, ai_handler: partial[B
"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,
Expand Down Expand Up @@ -102,12 +103,23 @@ async def _prepare_prediction(self, model: str):
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)
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 not response:
return ""
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]:
Expand Down

0 comments on commit 93e6436

Please sign in to comment.