From de993f539c4e244687bd01572637e9a17af3350c Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sat, 20 Jan 2024 18:54:32 +0100 Subject: Fix offset_line in copilot --- etc/tool/copilot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'etc') diff --git a/etc/tool/copilot.py b/etc/tool/copilot.py index 4de53ffc..9be1291c 100644 --- a/etc/tool/copilot.py +++ b/etc/tool/copilot.py @@ -108,8 +108,8 @@ def analyze_code(pull: PullRequest, diff: str)-> list: if match: offset_line = int(match.group(1)) elif current_file_path: - if line.startswith('\\') or line.startswith('diff'): - prompt = create_prompt(changed_lines, pull, current_file_path, offset_line) + if line.startswith('\\') or line.startswith('diff') and changed_lines: + prompt = create_prompt(changed_lines, pull, current_file_path) response = get_ai_response(prompt) for review in response.get('reviews', []): review['path'] = current_file_path @@ -117,11 +117,12 @@ def analyze_code(pull: PullRequest, diff: str)-> list: changed_lines = [] current_file_path = None elif not line.startswith('-'): - changed_lines.append(line) + changed_lines.append(f"{offset_line}:{line}") + offset_line += 1 return comments -def create_prompt(changed_lines: list, pull: PullRequest, file_path: str, offset_line: int): +def create_prompt(changed_lines: list, pull: PullRequest, file_path: str): """ Creates a prompt for the g4f model. @@ -132,8 +133,7 @@ def create_prompt(changed_lines: list, pull: PullRequest, file_path: str, offset Returns: str: The generated prompt. """ - code = "\n".join([f"{offset_line+idx}:{line}" for idx, line in enumerate(changed_lines)]) - print("Code:", code) + code = "\n".join(changed_lines) example = '{"reviews": [{"line": , "body": ""}]}' return f"""Your task is to review pull requests. Instructions: - Provide the response in following JSON format: {example} -- cgit v1.2.3