Skip to content

Commit

Permalink
Feat/minor cleanup work (#4101)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlu1248 authored Jun 23, 2024
2 parents d477669 + 29c803b commit 309ef35
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
File renamed without changes.
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 @@ -427,6 +427,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

0 comments on commit 309ef35

Please sign in to comment.