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 #2767

Open
wwzeng1 opened this issue Dec 14, 2023 · 1 comment · May be fixed by #2785
Open

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

wwzeng1 opened this issue Dec 14, 2023 · 1 comment · May be fixed by #2785
Labels
sweep Assigns Sweep to an issue or pull request.

Comments

@wwzeng1
Copy link
Contributor

wwzeng1 commented Dec 14, 2023

Details

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

@wwzeng1 wwzeng1 added the sweep Assigns Sweep to an issue or pull request. label Dec 14, 2023
Copy link
Contributor

sweep-nightly bot commented Dec 26, 2023

Sweeping

✨ Track Sweep's progress on our progress dashboard!


50%

💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 7bc8e3e248)

Tip

I'll email you at william@sweep.dev when I complete this pull request!


Actions (click)

  • ↻ Restart Sweep

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 0db6b3e
Checking sweepai/utils/ticket_utils.py for syntax errors... ✅ sweepai/utils/ticket_utils.py has no syntax errors! 1/1 ✓
Checking sweepai/utils/ticket_utils.py for syntax errors...
✅ sweepai/utils/ticket_utils.py has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


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.

doc_query_rewriter_system_prompt = """\
You must rewrite the user's github issue to leverage the docs. In this case we want to look at {package}. It's used for: {description}. Using the github issue, write a search query that searches for the potential answer using the documentation. This query will be sent to a documentation search engine with vector and lexical based indexing. Make this query contain keywords relevant to the {package} documentation.
"""
doc_query_rewriter_prompt = """\
This is the issue:
{issue}

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"

prompt = """\
<old_code>
{old_code}
</old_code>
{snippets}
For each of the {count} code snippets above, we want to create function names. We must not have duplicates of the existing function names as follows:
{existing_names}
Generate a function name for each of these in the below format. Use the context from the old_code and snippets to generate function names that clearly state what the function does. Optimize for readability, clarity, and similarity to the existing function names.
<function_name>
name_of_function
</function_name>
..."""
def serialize_method_name(method_name):
# handles '1. "method_name"' -> 'method_name'
if "." in method_name:
return method_name.split(". ")[-1].strip('"')
return method_name.strip().strip('"')
class NameBot(ChatGPT):
def name_functions(
self,
old_code,
snippets,
existing_names,
count=1,
):
self.model = (
DEFAULT_GPT4_32K_MODEL
if (self.chat_logger and self.chat_logger.is_paying_user())
else DEFAULT_GPT35_MODEL
)
name_response = self.chat(
content=prompt.format(
old_code=old_code,
snippets=snippets,
existing_names=existing_names,
count=count,
),
)
name_pattern = r"<function_name>\n(.*?)\n</function_name>"
name_matches = list(re.finditer(name_pattern, name_response, re.DOTALL))
name_matches = [match.group(1) for match in name_matches]
function_names = [
serialize_method_name(name_match.strip().strip('"').strip("'").strip("`"))
for name_match in name_matches
]


Step 2: ⌨️ Coding

  • Create sweepai/agents/query_filter_agent.py1b24e73 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.
• Import the `ChatGPT` class from `sweepai/core/chat.py`.
• Define a new class `QueryFilterAgent` that inherits from `ChatGPT`.
• Inside the `QueryFilterAgent` class, define a method `filter_search_query` that takes parameters such as `search_query`, `title`, `summary`, and `replies_text`.
• Construct a prompt within `filter_search_query` that instructs the AI to filter out unnecessary terms from the search query. Use the `doc_query_rewriter_prompt` from `sweepai/core/prompts.py` as a reference for structuring the prompt.
• Call the `chat` method of the `ChatGPT` class with the constructed prompt to get the AI's response.
• Process the AI's response to extract the filtered search query.
• Return the filtered search query from the `filter_search_query` method.
  • Running GitHub Actions for sweepai/agents/query_filter_agent.pyEdit
Check sweepai/agents/query_filter_agent.py with contents:

Ran GitHub Actions for 1b24e73308bdcba66960dde23ceff6ae2811eccf:
• Vercel Preview Comments:

  • Modify sweepai/utils/ticket_utils.pyEdit
Modify sweepai/utils/ticket_utils.py with contents:
• Import the `QueryFilterAgent` class from the newly created `sweepai/agents/query_filter_agent.py`.
• Inside the `fetch_relevant_files` function, after constructing the `search_query` in line 110, instantiate a `QueryFilterAgent` object.
• Call the `filter_search_query` method of the `QueryFilterAgent` object, passing the `title`, `summary`, and `replies_text` as arguments.
• Replace the original `search_query` with the filtered search query returned by the `filter_search_query` method.
• Ensure that the filtered `search_query` is used in subsequent operations within the `fetch_relevant_files` function.
  • Running GitHub Actions for sweepai/utils/ticket_utils.pyEdit
Check sweepai/utils/ticket_utils.py with contents:

Step 3: 🔁 Code Review

Working on it...


🎉 Latest improvements to Sweep:

  • We just released a dashboard to track Sweep's progress on your issue in real-time, showing every stage of the process – from search to planning and coding.
  • Sweep uses OpenAI's latest Assistant API to plan code changes and modify code! This is 3x faster and significantly more reliable as it allows Sweep to edit code and validate the changes in tight iterations, the same way as a human would.
  • Try using the GitHub issues extension to create Sweep issues directly from your editor! GitHub Issues and Pull Requests.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.
Join Our Discord

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
Development

Successfully merging a pull request may close this issue.

1 participant