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

Sonnet 35 support #4060

Merged
merged 1 commit into from
Jun 20, 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
8 changes: 6 additions & 2 deletions sweepai/chat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from sweepai.agents.modify_utils import get_error_message_dict, validate_and_parse_function_call
from sweepai.agents.search_agent import extract_xml_tag
from sweepai.chat.search_prompts import relevant_snippets_message, relevant_snippet_template, anthropic_system_message, function_response, pr_format, relevant_snippets_message_for_pr, openai_system_message, query_optimizer_system_prompt, query_optimizer_user_prompt
from sweepai.chat.search_prompts import relevant_snippets_message, relevant_snippet_template, anthropic_system_message, function_response, pr_format, relevant_snippets_message_for_pr, openai_system_message, query_optimizer_system_prompt, query_optimizer_user_prompt, anthropic_format_message
from sweepai.config.client import SweepConfig
from sweepai.config.server import CACHE_DIRECTORY, GITHUB_APP_ID, GITHUB_APP_PEM
from sweepai.core.chat import ChatGPT, call_llm
Expand Down Expand Up @@ -535,7 +535,11 @@ def chat_codebase_stream(
content=snippets_message,
role="user"
),
*messages[:-1]
*messages[:-1],
Message(
content=anthropic_format_message,
role="user",
)
]

def stream_state(
Expand Down
112 changes: 22 additions & 90 deletions sweepai/chat/search_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,83 +63,31 @@
[the function call goes here, using the valid XML format for function calls]
</function_call>""" + example_tool_calls

anthropic_format_message = """You MUST follow the following XML-based format:
anthropic_format_message = """You MUST follow the following XML-based format, including <analysis> and <user_response> XML blocks:

### Format

Use GitHub-styled markdown for your responses, using lists where applicable to improve clarity. You must respond with the following three distinct sections:
You must respond with the following two distinct sections:

# 1. Summary and analysis

<analysis>
First, list and summarize each file from the codebase provided that is relevant to the user's question. You may not need to summarize all provided files.
1. List and summarize each file from the codebase provided that is relevant to the user's question. You may not need to summarize all provided files.

2. List all the requests made by the user.

Then, determine if you have sufficient information to answer the user's question. If not, determine the information you need to answer the question completely by making `search_codebase` tool calls.
3. Organize your response to the user into sections. Plan out reasonable headers so that your response is more digestable.
</analysis>

# 2. User Response

<user_response>
Write a complete helpful response to the user's question in full detail, addressing all of the user's requests. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations.

When suggesting code changes, you MUST suggest changes in the following format:

<code_change>
<file_path>
path/to/file.py
</file_path>
<original_code>
Skip this section if and only if you are creating a new file.

Otherwise, copy the original section of code from path/to/file.py. This is the section of code that you will change. Paraphrasing, abbreviating the source code, or placeholder comments such as "# rest of code" are NEVER PERMITTED.
</original_code>
<new_code>
New code to replace <original_code> with.
</new_code>
</code_change>

For example for modifying an existing file, place the name of the existing file path in file_path and copy the original section of code from the file into <original_code>:

<code_change>
<file_path>
src/utils/rectangle.py
</file_path>
<original_code>
class Rectangle:
def __init__(self, width: int, height: int):
self.width = width
self.height = height

def area(self):
return self.width + self.height
</original_code>
<new_code>
class Rectangle:
def __init__(self, width: int, height: int):
self.width = width
self.height = height

def area(self):
return self.width * self.height
</new_code>
</code_change>
</user_response>

# 3. Self-Critique

<self_critique>
Then, self-critique your answer and validate that you have completely answered the user's question and addressed all their points. If the user's answer is extremely broad, you are done.

Otherwise, if the user's question is specific, and asks to implement a feature or fix a bug, determine what additional information you need to answer the user's question. Specifically, validate that all interfaces are being used correctly based on the contents of the retrieved files -- if you cannot verify this, then you must find the relevant information such as the correct interface or schema to validate the usage. If you need to search the codebase for more information, such as for how a particular feature in the codebase works, use the `search_codebase` tool in the next section.
</self_critique>

# 4. Function Call (Optional)
Write a complete helpful response to the user's question in full detail, addressing all of the user's requests. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When showing code examples, only show MINIMAL excerpts of code that address the user's question.

Then, make each a function call like so:
<function_call>
[the function call goes here, using the valid XML format for function calls]
</function_call>
When showing relevant examples of code, only show MINIMAL excerpts of code that address the user's question. Do NOT copy the whole file, but only the lines that are relevant to the user's question.

""" + example_tool_calls
When suggesting code changes, you add <code_change> blocks inside the <user_response></user_response> tags.
</user_response>"""

openai_format_message = """You MUST follow the following XML-based format, including <user_response> and </user_respose> tags:

Expand Down Expand Up @@ -172,25 +120,28 @@ def area(self):

# Guidelines

- When you are uncertain about details such as a type definition in the codebase, search the codebase to find the required information.
- When showing relevant examples of code, only show MINIMAL excerpts of code that address the user's question.
- Wherever possible, you should suggest code changes. To do so you must use the <code_change> format. First, indicate whether you want to modify an existing file or create a new fil, then write in the following format:
- Focus on providing high-quality explanations. Start with a high-level overview.
- Only show code as supplementary evidence or to enhance the explanations. When doing so, only show MINIMAL excerpts of code that address the user's question. Do NOT copy the whole file, but only the lines that are relevant to the user's question. Be concise, it's hard for a user to read entire files worth of content.
- Use markdown for your responses, using headers where applicable to improve clarity and lists to enumerate examples.
- Wherever possible, you should suggest code changes. To do so, you must add <code_change> blocks to the <user_response> block following the format provided below.
- Code changes must be atomic. Each code change must be in its own block, unless they are contiguous changes in the same file.

# <code_change> Format
First, indicate whether you want to modify an existing file or create a new file, then write in the following format:

<code_change>
<file_path>
path/to/file.py
</file_path>
<original_code>
Skip this section if and only if you are creating a new file.

Otherwise, copy the original section of code from path/to/file.py. This is the section of code that you will change. Paraphrasing, abbreviating the source code, or placeholder comments such as "# rest of code" are NEVER PERMITTED.
Copy the original section of code from path/to/file.py. This is the section of code that you will change. Paraphrasing, abbreviating the source code, or placeholder comments such as "# rest of code" are NEVER PERMITTED.
</original_code>
<new_code>
New code to replace <original_code> with.
</new_code>
</code_change>

For example for modifying an existing file, place the name of the existing file path in file_path and copy the original section of code from the file into <original_code>:
For example:

<code_change>
<file_path>
Expand All @@ -216,26 +167,7 @@ def area(self):
</new_code>
</code_change>

# Environment

In this environment, you have access to a code search tool to assist in fulfilling the user request:

You MUST invoke the tool like this:
<function_call>
<search_codebase>
<query>
The search query.
</query>
</search_codebase>
</function_call>

<search_codebase>
<query>
Single, detailed, specific natural language search question to search the codebase for relevant snippets. This should be in the form of a natural language question, like "What is the structure of the User model in the authentication module?"
</query>
</search_codebase>

""" + example_tool_calls + "\n\n" + anthropic_format_message
""" + anthropic_format_message

action_items_system_prompt = """You are a tech lead helping to break down a conversation about an issue into subtasks for an intern to solve. Identify every single one of the suggested changes. Be complete. The changes should be atomic.

Expand Down
2 changes: 2 additions & 0 deletions sweepai/core/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
AnthropicModel = (
Literal["claude-3-haiku-20240307"]
| Literal["claude-3-sonnet-20240229"]
| Literal["claude-3-5-sonnet-20240620"]
| Literal["claude-3-opus-20240229"]
)

Expand All @@ -77,6 +78,7 @@
"anthropic.claude-3-sonnet-20240229-v1:0": 200000,
"claude-3-opus-20240229": 200000,
"claude-3-sonnet-20240229": 200000,
"claude-3-5-sonnet-20240620": 200000,
"claude-3-haiku-20240307": 200000,
"gpt-3.5-turbo-16k-0613": 16000,
}
Expand Down
Loading