Skip to content

Commit

Permalink
final commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrT23 committed Jul 16, 2023
1 parent 8ce9e90 commit ff211df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion pr_agent/algo/pr_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler,
continue

if patch:
patch_final = f"## {file.filename}\n\n{patch}\n"
if not convert_hunks_to_line_numbers:
patch_final = f"## {file.filename}\n\n{patch}\n"
else:
patch_final = patch
patches.append(patch_final)
total_tokens += token_handler.count_tokens(patch_final)
if settings.config.verbosity_level >= 2:
Expand Down
12 changes: 6 additions & 6 deletions pr_agent/settings/pr_code_suggestions_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
system="""You are a language model called CodiumAI-PR-Code-Reviewer.
Your task is to provide provide meaningfull non-trivial code suggestions to improve the new code in a PR (the '+' lines).
- Try to give important suggestions like fixing code problems, issues and bugs. As a second priority, provide suggestions for meaningfull code improvements, like performance, vulnerability, modularity, and best practices.
- Suggestions should refer only to the 'new hunk' code, and focus on improving the code on lines with '+'.
- Suggestions should refer only to the 'new hunk' code, and focus on improving the new added code lines, with '+'.
- Provide the exact line number range (inclusive) for each issue.
- Assume there is additional code in the relevant file that is not included in the diff.
- Provide up to {{ num_code_suggestions }} code suggestions.
Expand All @@ -14,8 +14,8 @@ You must use the following JSON schema to format your answer:
{
"Code suggestions": {
"type": "array",
"minItems": "1",
"maxItems": "{{ num_code_suggestions }}",
"minItems": 1,
"maxItems": {{ num_code_suggestions }},
"uniqueItems": "true",
"items": {
"relevant file": {
Expand All @@ -24,7 +24,7 @@ You must use the following JSON schema to format your answer:
},
"suggestion content": {
"type": "string",
"description": "a concrete suggestion for meaningfully improving the new PR code.
"description": "a concrete suggestion for meaningfully improving the new PR code."
},
"existing code": {
"type": "string",
Expand All @@ -48,11 +48,11 @@ Example input:
## src/file1.py
---new_hunk---
```
<new hunk code, annotated with line numbers>
[new hunk code, annotated with line numbers]
```
---old_hunk---
```
<old hunk code, that was replaced by the new hunk above>
[old hunk code]
```
...
'
Expand Down
5 changes: 4 additions & 1 deletion pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ def _prepare_pr_code_suggestions(self) -> str:
try:
data = json.loads(review)
except json.decoder.JSONDecodeError:
if settings.config.verbosity_level >= 2:
logging.info(f"Could not parse json response: {review}")
data = try_fix_json(review)
return data

def push_inline_code_suggestions(self, data):
for d in data['Code suggestions']:
print(d)
if settings.config.verbosity_level >= 2:
logging.info(f"suggestion: {d}")
relevant_file = d['relevant file'].strip()
relevant_lines_str = d['relevant lines'].strip()
relevant_lines_start = int(relevant_lines_str.split('-')[0]) # absolute position
Expand Down

0 comments on commit ff211df

Please sign in to comment.