summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-20 18:54:32 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-20 18:54:32 +0100
commitde993f539c4e244687bd01572637e9a17af3350c (patch)
treeaf4d84358d82b05c1b86fe7c93997cff6caaf891 /etc
parentCheck access from chromedriver (diff)
downloadgpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar.gz
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar.bz2
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar.lz
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar.xz
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.tar.zst
gpt4free-de993f539c4e244687bd01572637e9a17af3350c.zip
Diffstat (limited to '')
-rw-r--r--etc/tool/copilot.py12
1 files changed, 6 insertions, 6 deletions
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": <line_number>, "body": "<review comment>"}]}'
return f"""Your task is to review pull requests. Instructions:
- Provide the response in following JSON format: {example}