Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip cr task if there is no error #633

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions server/agent/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
json_output = json.dumps(d, ensure_ascii=False)
yield f"data: {json_output}\n\n"
except Exception as e:
error_output = json.dumps({"status": "error", "message": str(e)}, ensure_ascii=False)
error_output = json.dumps(
{"status": "error", "message": str(e)}, ensure_ascii=False

Check warning on line 36 in server/agent/base.py

View check run for this annotation

Codecov / codecov/patch

server/agent/base.py#L35-L36

Added lines #L35 - L36 were not covered by tests
)
yield f"data: {error_output}\n\n"


class AgentBuilder:
agent_executor: AgentExecutor

Expand Down Expand Up @@ -216,13 +219,17 @@
async def run_chat(self, input_data: ChatData) -> str:
try:
messages = input_data.messages
return self.agent_executor.invoke(
last_message_content = messages[-1].content

result = self.agent_executor.invoke(
{
"input": messages[len(messages) - 1].content,
"input": last_message_content,

Check warning on line 226 in server/agent/base.py

View check run for this annotation

Codecov / codecov/patch

server/agent/base.py#L226

Added line #L226 was not covered by tests
"chat_history": self.chat_history_transform(messages),
},
return_only_outputs=True,
)

return result
except Exception as e:
logger.error(e)
return f"error: {str(e)}\n"
logger.error("Error occurred in run_chat: %s", str(e))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error logging message has been improved to provide more context. Ensure that sensitive information is not logged inadvertently.

return f"error: {str(e)}"
22 changes: 13 additions & 9 deletions server/agent/prompts/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@
For further assistance, please describe your question in the comments and @petercat-assistant to start a conversation with me.
</details>


## Task 2: Code Review

If the title or description includes the flag [skip], you can skip the task.
Review the diff for significant errors in the updated files. Focus exclusively on logical, functional issues, or security vulnerabilities. Avoid comments on stylistic changes, minor refactors, or insignificant issues.
Review the code diff exclusively for critical logical, functional, or security errors. Avoid any commentary unrelated to these areas, including documentation, stylistic changes, or minor issues.

### Specific Instructions:

### Specific instructions:
- Only the code diff is available for you to review, not the entire codebase.
- Make comments only on code introducing clear and critical functional or security errors.
- Do not comment on documentation, style, accuracy of text, or minor refactoring changes.
- Provide absolutely no feedback if no critical errors are found.
- If necessary, provide code examples only for addressing critical errors.
- Adhere to language-specific coding conventions used in the PR.
- If there are critical errors to comment on, use the `create_review_comment` tool to create review comments.
- Skip the task if no errors are found.
- Upon completing the task, output strictly "All task finished", with no additional commentary.

- Take into account that you don’t have access to the full code but only the code diff.
- Only comment on code that introduces potential functional or security errors.
- If no critical issues are found in the changes, do not provide any comments.
- Provide code examples if necessary for critical fixes.
- Follow the coding conventions of the language in the PR.
- After completing the tasks, only output "All task finished".

### Input format

Expand Down
37 changes: 24 additions & 13 deletions server/agent/tools/pull_request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import traceback
from typing import Optional
from github import Github, Auth, ContentFile
Expand All @@ -7,6 +6,7 @@
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: Optional[str] = None):
Expand All @@ -22,19 +22,28 @@
g = Github(auth=token)
try:
repo = g.get_repo(repo_name)
contents: list[ContentFile.ContentFile] | ContentFile.ContentFile = repo.get_contents(path=path, ref=ref) if ref else repo.get_contents(path=path)
contents: list[ContentFile.ContentFile] | ContentFile.ContentFile = (

Check warning on line 25 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L25

Added line #L25 was not covered by tests
repo.get_contents(path=path, ref=ref)
if ref
else repo.get_contents(path=path)

Check warning on line 28 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L27-L28

Added lines #L27 - L28 were not covered by tests
)

if isinstance(contents, list):
return json.dumps(
[{
"filename": content.path,
"content": content.content,
} for content in contents]
[
{

Check warning on line 34 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L34

Added line #L34 was not covered by tests
"filename": content.path,
"content": content.content,
}
for content in contents
]

Check warning on line 39 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L38-L39

Added lines #L38 - L39 were not covered by tests
)
return json.dumps({
"filename": contents.path,
"content": contents.content,
})
return json.dumps(
{
"filename": contents.path,

Check warning on line 43 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L42-L43

Added lines #L42 - L43 were not covered by tests
"content": contents.content,
}
)
except Exception as e:
print(traceback.format_exception(e))
return json.dumps([])
Expand All @@ -53,11 +62,13 @@
g = Github(auth=token)
repo = g.get_repo(repo_name)
pull_request = repo.get_pull(pull_number)
# print(f"create_pr_summary, pull_request={pull_request}, summary={summary}")
pull_request.create_issue_comment(summary)
return json.dumps([])

@tool
def create_review_comment(repo_name: str, pull_number: int, sha: str, path: str, line: int, comment: str):
def create_review_comment(
repo_name: str, pull_number: int, sha: str, path: str, line: int, comment: str
):

Check warning on line 71 in server/agent/tools/pull_request.py

View check run for this annotation

Codecov / codecov/patch

server/agent/tools/pull_request.py#L70-L71

Added lines #L70 - L71 were not covered by tests
"""
Create a code review of specified pull requst file
:param repo_name: The name of the repository, e.g., "ant-design/ant-design"
Expand Down Expand Up @@ -91,4 +102,4 @@
"get_file_content": get_file_content,
"create_pr_summary": create_pr_summary,
"create_review_comment": create_review_comment,
}
}
Loading