-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 支持生成摘要 - 支持 CR
- Loading branch information
Showing
17 changed files
with
1,152 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
from core.dao.botDAO import BotDAO | ||
from core.models.bot import Bot | ||
from petercat_utils.data_class import ChatData | ||
|
||
def get_bot(input_data: ChatData) -> Bot: | ||
bot_dao = BotDAO() | ||
bot = bot_dao.get_bot(input_data.bot_id) | ||
return bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
PULL_REQUEST_ROLE = """ | ||
# Character Description | ||
You are an experienced Code Reviewer, specializing in identifying critical issues and potentially incorrect code in Pull Requests (PRs). | ||
# Skills Description | ||
## Skill 1: Pull Request Summarize | ||
You excel at analyzing users' code changes and get summaries. | ||
Offering specific and targeted in pinpointing code that may lead to errors, security vulnerabilities, or significant performance issues. | ||
You focus only on identifying and addressing severe or fundamentally flawed code practices. | ||
You are equipped with two powerful tool2, used to leave a summary and code review comments: | ||
- create_pr_summary; This tools is used to create summary of PR. | ||
- create_review_comment: This tool is used to leave review comment of file. | ||
Constraints | ||
- Focus exclusively on identifying and reviewing highly inappropriate code usage or potential errors. | ||
- Avoid reviewing minor style inconsistencies or non-critical issues. | ||
- Respect the language of the PR's title and description when providing feedback, ensuring that all comments and summarize are given in the same language. | ||
- Provide concise, clear, and actionable feedback, directly related to improving the correctness and reliability of the code. | ||
""" | ||
|
||
PULL_REQUEST_SUMMARY = """ | ||
# Task | ||
You have two Pull Requst review task with basic infomation: | ||
``` | ||
repo_name: {repo_name} | ||
pull_number: {pull_number} | ||
title: {title} | ||
description: {description} | ||
``` | ||
## Task 1: Summarize the Pull Request | ||
Using `create_pr_summary` tool to create PR summary. | ||
Provider your response in markdown with the following content. follow the user's language. | ||
- **Walkthrough**: A high-level summary of the overall change instead of specific files within 80 words. | ||
- **Changes**: A markdown table of files and their summaries. Group files with similar changes together into a single row to save space. | ||
## Task 2: using `create_review_comment` tool to Create code review comments for every new_hunk file that may lead to errors, vulnerabilities. | ||
## File Diff: | ||
{file_diff} | ||
# Constraints | ||
- After completing the tasks, only output "All task finished". | ||
""" | ||
|
||
def get_role_prompt(repo_name: str, ref: str): | ||
return PULL_REQUEST_ROLE.format(repo_name=repo_name, ref=ref) | ||
|
||
def get_pr_summary(repo_name: str, pull_number: int, title: str, description: str, file_diff: str): | ||
return PULL_REQUEST_SUMMARY.format( | ||
repo_name=repo_name, | ||
pull_number={pull_number}, | ||
title={title}, | ||
description={description}, | ||
file_diff=file_diff | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
|
||
from typing import Optional | ||
from github import Github, Auth | ||
import json | ||
|
||
from langchain.tools import tool | ||
from agent.tools.helper import need_github_login | ||
|
||
def factory(token: Optional[Auth.Token]): | ||
|
||
@tool | ||
def get_file_content(repo_name: str, path: str, ref: str): | ||
""" | ||
Get content of specified pull requst file | ||
:param repo_name: The name of the repository, e.g., "ant-design/ant-design" | ||
:param path: The path of file, e.g., /contents/file1.txt | ||
:param ref: The name of the commit/branch/tag. Default: the repository’s default branch. | ||
""" | ||
if token is None: | ||
return need_github_login() | ||
|
||
g = Github(auth=token) | ||
try: | ||
repo = g.get_repo(repo_name) | ||
content = repo.get_contents(path=path, ref=ref) | ||
print(f"get_content: f{content}") | ||
return json.dumps([]) | ||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
return json.dumps([]) | ||
|
||
@tool | ||
def create_pr_summary(repo_name: str, pull_number: int, summary: str): | ||
""" | ||
Create a code review of specified pull requst file | ||
:param repo_name: The name of the repository, e.g., "ant-design/ant-design" | ||
:param pull_number: The number of pull requst: e.g., 123 | ||
:param summary: markdown content of PR summary | ||
""" | ||
if token is None: | ||
return need_github_login() | ||
|
||
g = Github(auth=token) | ||
repo = g.get_repo(repo_name) | ||
pull_request = repo.get_pull(pull_number) | ||
pull_request.create_issue_comment(summary) | ||
|
||
@tool | ||
def create_review_comment(repo_name: str, pull_number: int, sha: str, path: str, line: int, comment: str): | ||
""" | ||
Create a code review of specified pull requst file | ||
:param repo_name: The name of the repository, e.g., "ant-design/ant-design" | ||
:param pull_number: The number of pull requst: e.g., 123 | ||
:param sha: The sha of file. e.g., 6dcb09b5b57875f334f61aebed695e2e4193db5e | ||
:param path: The path of file, e.g., /contents/file1.txt | ||
:param line: The line number to create comment at. e.g., 19 | ||
:param comment: Content of review comments | ||
""" | ||
if token is None: | ||
return need_github_login() | ||
|
||
g = Github(auth=token) | ||
try: | ||
repo = g.get_repo(repo_name) | ||
pull_request = repo.get_pull(pull_number) | ||
commit = repo.get_commit(sha=sha) | ||
# print(f"create_review_comment, pull_request={pull_request}, commit={commit}, comment={comment}") | ||
pull_request.create_review_comment( | ||
body=comment, | ||
path=path, | ||
commit=commit, | ||
line=line, | ||
) | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
return json.dumps([]) | ||
|
||
return { | ||
"get_file_content": get_file_content, | ||
"create_pr_summary": create_pr_summary, | ||
"create_review_comment": create_review_comment, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.