Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updated OpenAI prompts
  • Loading branch information
kevinlu1248 committed May 14, 2024
commit 5158b094dcfdf9b55cd64c008654b9ada4b7c4eb
111 changes: 59 additions & 52 deletions sweepai/chat/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,32 +117,34 @@ def search_codebase_endpoint(

### Format

Use GitHub-styled markdown for your responses. You must respond with the following three distinct sections:
Use GitHub-styled markdown for your responses. You must respond with the following four distinct sections:

# 1. User Response

<user_response>
# 1. Summary and analysis
<analysis>
## Summary
First, list and summarize each NEW file from the codebase provided from the last function output that is relevant to the user's question. You may not need to summarize all provided files.

## New information
Secondly, list all new information that was retrieved from the codebase that is relevant to the user's question, especially if it invalidates any previous beliefs or assumptions.
</analysis>

# 2. Updated answer as a user response

## Updated answer
<user_response>
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.

If so, rewrite your previous response with the new information and any invalidated beliefs or assumptions. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When explaining how to add new code, always write out the new code. When suggesting code changes, write out all the code changes required in the unified diff format.
</user_response>

# 2. Self-Critique
# 3. Self-Critique

<self_critique>
Then, self-critique your answer and validate that you have completely answered the user's question. If the user's answer is relatively 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>

# 3. Function Calls (Optional)
# 4. Function Calls (as needed)

Then, make each function call like so:
<function_calls>
Expand All @@ -153,29 +155,34 @@ def search_codebase_endpoint(

### Format

Use GitHub-styled markdown for your responses. You must respond with the following three distinct sections:
Use GitHub-styled markdown for your responses. You must respond with the following four distinct sections:

# 1. User Response
# 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, but only the relevant ones.
</analysis>

<user_response>
## Summary
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.
# 2. User Response

## Answer
<user_response>
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.

If so, write a complete helpful response to the user's question in full detail. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When explaining how to add new code, always write out the new code. When suggesting code changes, write out all the code changes required in the unified diff format.
If so, write a detailed, helpful response to the user's question. Provide small code examples, explanations and excerpts as required to provide concrete explanations. Break large changes into multiple steps. When suggesting code changes, write out each code change required in the unified diff format, providing a few surrounding lines for context.
</user_response>

# 2. Self-Critique
# 3. Self-Critique

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

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.
Then, determine what additional information you need to answer the user's question. Specifically, validate that:
1. All interfaces are being used correctly based on the contents of the retrieved files.
2. When a function is changed, be sure to update all of its usages.

If you cannot verify any of these, 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>

# 3. Function Calls (Optional)
# 3. Function Calls (as needed)

Then, make each function call like so:
<function_calls>
Expand Down Expand Up @@ -320,56 +327,56 @@ def stream_state(initial_user_message: str, snippets: list[Snippet], messages: l
result_string = ""
user_response = ""
self_critique = ""
current_messages = []
for token in stream:
result_string += token
analysis = extract_xml_tag(result_string, "analysis", include_closing_tag=False) or ""
user_response = extract_xml_tag(result_string, "user_response", include_closing_tag=False) or ""
self_critique = extract_xml_tag(result_string, "self_critique", include_closing_tag=False)

current_messages = []

if self_critique:
yield [
*new_messages,
if analysis:
current_messages.append(
Message(
content=analysis,
role="function",
function_call={
"function_name": "analysis",
"function_parameters": {},
"is_complete": bool(user_response),
}
)
)

if user_response:
current_messages.append(
Message(
content=user_response,
role="assistant"
),
role="assistant",
)
)

if self_critique:
current_messages.append(
Message(
content=self_critique,
role="function",
function_call={
"function_name": "self_critique",
"function_parameters": {},
"is_complete": False,
}
),
]
else:
yield [
*new_messages,
Message(
content=user_response,
role="assistant"
)
]

new_messages.append(
Message(
content=user_response,
role="assistant",
)
)

if self_critique:
new_messages.append(
Message(
content=self_critique,
role="function",
function_call={
"function_name": "self_critique",
"function_parameters": {},
"is_complete": True,
}
)
)

yield [
*new_messages,
*current_messages
]

current_messages[-1].function_call["is_complete"] = True

new_messages.extend(current_messages)

yield new_messages

Expand Down