mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-24 11:00:40 -08:00
Fix offset_line in copilot
This commit is contained in:
parent
8787db385e
commit
de993f539c
1 changed files with 6 additions and 6 deletions
|
|
@ -108,8 +108,8 @@ def analyze_code(pull: PullRequest, diff: str)-> list:
|
||||||
if match:
|
if match:
|
||||||
offset_line = int(match.group(1))
|
offset_line = int(match.group(1))
|
||||||
elif current_file_path:
|
elif current_file_path:
|
||||||
if line.startswith('\\') or line.startswith('diff'):
|
if line.startswith('\\') or line.startswith('diff') and changed_lines:
|
||||||
prompt = create_prompt(changed_lines, pull, current_file_path, offset_line)
|
prompt = create_prompt(changed_lines, pull, current_file_path)
|
||||||
response = get_ai_response(prompt)
|
response = get_ai_response(prompt)
|
||||||
for review in response.get('reviews', []):
|
for review in response.get('reviews', []):
|
||||||
review['path'] = current_file_path
|
review['path'] = current_file_path
|
||||||
|
|
@ -117,11 +117,12 @@ def analyze_code(pull: PullRequest, diff: str)-> list:
|
||||||
changed_lines = []
|
changed_lines = []
|
||||||
current_file_path = None
|
current_file_path = None
|
||||||
elif not line.startswith('-'):
|
elif not line.startswith('-'):
|
||||||
changed_lines.append(line)
|
changed_lines.append(f"{offset_line}:{line}")
|
||||||
|
offset_line += 1
|
||||||
|
|
||||||
return comments
|
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.
|
Creates a prompt for the g4f model.
|
||||||
|
|
||||||
|
|
@ -132,8 +133,7 @@ def create_prompt(changed_lines: list, pull: PullRequest, file_path: str, offset
|
||||||
Returns:
|
Returns:
|
||||||
str: The generated prompt.
|
str: The generated prompt.
|
||||||
"""
|
"""
|
||||||
code = "\n".join([f"{offset_line+idx}:{line}" for idx, line in enumerate(changed_lines)])
|
code = "\n".join(changed_lines)
|
||||||
print("Code:", code)
|
|
||||||
example = '{"reviews": [{"line": <line_number>, "body": "<review comment>"}]}'
|
example = '{"reviews": [{"line": <line_number>, "body": "<review comment>"}]}'
|
||||||
return f"""Your task is to review pull requests. Instructions:
|
return f"""Your task is to review pull requests. Instructions:
|
||||||
- Provide the response in following JSON format: {example}
|
- Provide the response in following JSON format: {example}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue