返回提交历史
Modified
etc/tool/copilot.py
+6
-6
XFEstudio/gpt4free
Fix offset_line in copilot
de993f53
代码差异
1 个文件
+6
-6
@@ -108,8 +108,8 @@ def analyze_code(pull: PullRequest, diff: str)-> list:
108
108
if match:
109
109
offset_line = int(match.group(1))
110
110
elif current_file_path:
111
if line.startswith('\\') or line.startswith('diff'):
112
prompt = create_prompt(changed_lines, pull, current_file_path, offset_line)
111
if line.startswith('\\') or line.startswith('diff') and changed_lines:
112
prompt = create_prompt(changed_lines, pull, current_file_path)
113
113
response = get_ai_response(prompt)
114
114
for review in response.get('reviews', []):
115
115
review['path'] = current_file_path
@@ -117,11 +117,12 @@ def analyze_code(pull: PullRequest, diff: str)-> list:
117
117
changed_lines = []
118
118
current_file_path = None
119
119
elif not line.startswith('-'):
120
changed_lines.append(line)
120
changed_lines.append(f"{offset_line}:{line}")
121
offset_line += 1
121
122
122
123
return comments
123
124
124
def create_prompt(changed_lines: list, pull: PullRequest, file_path: str, offset_line: int):
125
def create_prompt(changed_lines: list, pull: PullRequest, file_path: str):
125
126
"""
126
127
Creates a prompt for the g4f model.
127
128
@@ -132,8 +133,7 @@ def create_prompt(changed_lines: list, pull: PullRequest, file_path: str, offset
132
133
Returns:
133
134
str: The generated prompt.
134
135
"""
135
code = "\n".join([f"{offset_line+idx}:{line}" for idx, line in enumerate(changed_lines)])
136
print("Code:", code)
136
code = "\n".join(changed_lines)
137
137
example = '{"reviews": [{"line": <line_number>, "body": "<review comment>"}]}'
138
138
return f"""Your task is to review pull requests. Instructions:
139
139
- Provide the response in following JSON format: {example}