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

Sweep: create a new agent to be used in ticket_utils.py #3158

Open
4 tasks done
wwzeng1 opened this issue Feb 24, 2024 · 1 comment · May be fixed by #3160
Open
4 tasks done

Sweep: create a new agent to be used in ticket_utils.py #3158

wwzeng1 opened this issue Feb 24, 2024 · 1 comment · May be fixed by #3160
Labels
sweep Assigns Sweep to an issue or pull request.

Comments

@wwzeng1
Copy link
Contributor

wwzeng1 commented Feb 24, 2024

Details

The agent should filter unnecessary terms out of the search query to be sent into lexical search. Write a prompt to do this, using pr_description as a reference

Checklist
  • Create sweepai/agents/query_filter_agent.py9159660 Edit
  • Running GitHub Actions for sweepai/agents/query_filter_agent.pyEdit
  • Modify sweepai/utils/ticket_utils.py8d22520 Edit
  • Running GitHub Actions for sweepai/utils/ticket_utils.pyEdit
@wwzeng1 wwzeng1 added the sweep Assigns Sweep to an issue or pull request. label Feb 24, 2024
@wwzeng1 wwzeng1 changed the title Sweep: create a new agent to be used in ticket_utils.py Sweep: create a new agent to be used in ticket_utils.py Feb 24, 2024
Copy link
Contributor

sweep-nightly bot commented Feb 24, 2024

🚀 Here's the PR! #3160

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: None)

Tip

I can email you next time I complete a pull request if you set up your email here!


Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

def fetch_relevant_files(
cloned_repo,
title,
summary,
replies_text,
username,
metadata,
on_ticket_start_time,
tracking_id,
is_paying_user,
is_consumer_tier,
issue_url,
chat_logger,
ticket_progress: TicketProgress,
):
logger.info("Fetching relevant files...")
try:
search_query = (title + summary + replies_text).strip("\n")
replies_text = f"\n{replies_text}" if replies_text else ""
formatted_query = (f"{title.strip()}\n{summary.strip()}" + replies_text).strip(
"\n"
)
repo_context_manager = prep_snippets(cloned_repo, search_query, ticket_progress)
ticket_progress.search_progress.repo_tree = str(repo_context_manager.dir_obj)
ticket_progress.save()
repo_context_manager = get_relevant_context(
formatted_query,
repo_context_manager,
ticket_progress,
chat_logger=chat_logger,
)
snippets = repo_context_manager.current_top_snippets
ticket_progress.search_progress.repo_tree = str(repo_context_manager.dir_obj)
ticket_progress.search_progress.final_snippets = snippets
ticket_progress.save()

keyword_search_schema = {
"name": "keyword_search",
"parameters": {
"type": "object",
"properties": {
"justification": {
"type": "string",
"description": "Justification for searching the keyword.",
},
"keyword": {
"type": "string",
"description": "The keyword to search for.",
},
},
"required": ["justification", "keyword"],
},
"description": "Searches for all lines in the file containing the keyword.",

class PRDescriptionBot(ChatGPT):
def describe_diffs(
self,
diffs,
pr_title,
):
self.messages = []
self.model = DEFAULT_GPT35_MODEL
# attempt to generate description 3 times
pr_desc_pattern = r"<pr_description>\n(.*?)\n</pr_description>"
for attempt in [0, 1, 2]:
pr_desc_response = self.chat(
content=prompt.format(
diffs=diffs,
pr_title=pr_title,
),
)
pr_desc_matches = re.search(pr_desc_pattern, pr_desc_response, re.DOTALL)
if pr_desc_matches is None:
if attempt == 2:
return ""
else:
break
pr_desc = pr_desc_matches.group(1)
pr_desc = pr_desc.strip()


Step 2: ⌨️ Coding

  • Create sweepai/agents/query_filter_agent.py9159660 Edit
Create sweepai/agents/query_filter_agent.py with contents:
• Create a new Python file named query_filter_agent.py in the sweepai/agents directory.
• Define a new class named QueryFilterAgent within this file.
• Import necessary modules and classes, such as the ChatGPT class from sweepai/agents/pr_description_bot.py, as this new agent will likely use similar functionality.
• Implement a method within QueryFilterAgent named filter_search_query that takes a search query as input and returns a filtered version of the query. This method will use a prompt to filter out unnecessary terms, similar to how PRDescriptionBot generates PR descriptions.
• The method should handle cases where the filtering does not yield a result by returning the original query as a fallback.
  • Running GitHub Actions for sweepai/agents/query_filter_agent.pyEdit
Check sweepai/agents/query_filter_agent.py with contents:

Ran GitHub Actions for 9159660fe39e8db1ec039e836362627e567045b8:

  • Modify sweepai/utils/ticket_utils.py8d22520 Edit
Modify sweepai/utils/ticket_utils.py with contents:
• Import the QueryFilterAgent class from the newly created file sweepai/agents/query_filter_agent.py at the top of the ticket_utils.py file.
• Inside the fetch_relevant_files function, replace the current search_query concatenation logic (lines 111-115) with a call to the filter_search_query method of a QueryFilterAgent instance.
• Create an instance of QueryFilterAgent before the try block where the search_query is currently being concatenated.
• Pass the concatenated title, summary, and replies_text to the filter_search_query method and assign the result back to the search_query variable.
• Ensure that the rest of the function uses this new filtered search_query for further processing.
--- 
+++ 
@@ -5,6 +5,7 @@
 
 from sweepai.config.client import SweepConfig
 from sweepai.core.context_pruning import RepoContextManager, get_relevant_context
+from sweepai.agents.query_filter_agent import QueryFilterAgent
 from sweepai.core.lexical_search import (
     compute_vector_search_scores,
     prepare_lexical_search_index,
@@ -108,7 +109,8 @@
 ):
     logger.info("Fetching relevant files...")
     try:
-        search_query = (title + summary + replies_text).strip("\n")
+        filter_agent = QueryFilterAgent()
+        search_query = filter_agent.filter_search_query((title + summary + replies_text).strip('\n'))
         replies_text = f"\n{replies_text}" if replies_text else ""
         formatted_query = (f"{title.strip()}\n{summary.strip()}" + replies_text).strip(
             "\n"
  • Running GitHub Actions for sweepai/utils/ticket_utils.pyEdit
Check sweepai/utils/ticket_utils.py with contents:

Ran GitHub Actions for 8d2252011a45e78dce97cddb27a991e025f7568c:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/create_a_new_agent_to_be_used_in_ticket_2f9c3.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description.
Something wrong? Let us know.

This is an automated message generated by Sweep AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Assigns Sweep to an issue or pull request.
Projects
None yet
1 participant