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

Feat/minor cleanup work #4101

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 13 deletions sweepai/chat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sweepai.config.client import SweepConfig
from sweepai.config.server import CACHE_DIRECTORY, DOCKER_ENABLED, GITHUB_APP_ID, GITHUB_APP_PEM
from sweepai.core.chat import ChatGPT, call_llm
from sweepai.core.entities import FileChangeRequest, Message, Snippet
from sweepai.core.entities import FileChangeRequest, Message, Snippet, fuse_snippets
from sweepai.core.pull_request_bot import get_pr_summary_for_chat
from sweepai.core.review_utils import split_diff_into_patches
from sweepai.dataclasses.check_status import CheckStatus, gha_to_check_status, gha_to_message
Expand Down Expand Up @@ -392,6 +392,8 @@ def search_codebase(
yield f"{message} (optimized query: {query})", snippets
else:
yield message, snippets
snippets = fuse_snippets(snippets)
yield "Fused snippets.", snippets
logger.debug(f"Preparing snippets took {timer.time_elapsed} seconds")
return snippets

Expand Down Expand Up @@ -562,18 +564,7 @@ def stream_state(
user_message = initial_user_message

fetched_snippets = snippets
new_messages = [
Message(
content=snippets_message,
role="function",
function_call={
"function_name": "search_codebase",
"function_parameters": {},
"is_complete": True,
"snippets": deepcopy(snippets)
}
)
] if len(messages) <= 2 else []
new_messages = []

yield new_messages

Expand Down
14 changes: 14 additions & 0 deletions sweepai/core/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,20 @@ def from_file(
**kwargs,
)

def fuse_snippets(snippets: list[Snippet]) -> list[Snippet]:
new_snippets = []
for snippet in snippets:
for new_snippet in new_snippets:
if new_snippet.file_path == snippet.file_path:
if new_snippet.end + 1 == snippet.start:
new_snippet.end = snippet.end
break
elif new_snippet.start - 1 == snippet.end:
new_snippet.start = snippet.start
break
else:
new_snippets.append(snippet)
return new_snippets

class NoFilesException(Exception):
def __init__(self, message="Sweep could not find any files to modify"):
Expand Down
Loading