From 157e0ccb73de4b9ba2ee5b54ac13a8d6556e0de2 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 11 Apr 2023 16:51:03 -0700 Subject: [PATCH] update instructions (#162) ### Summary by OpenAI **Release Notes** - New Feature: Added instructions for reviewing code changes in a specific format, including suggestions and replacements. Clarified the expected response format and provided an example. > "Code reviews made easy, > With format clear and breezy. > Suggestions and replacements galore, > Reviewing code has never been more." --- dist/index.js | 66 ++++++++++++++++++++++++++++++++++++++------------- src/review.ts | 50 +++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 34 deletions(-) diff --git a/dist/index.js b/dist/index.js index 1942895d..839f1a42 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6492,9 +6492,14 @@ const codeReview = async (lightBot, heavyBot, options, prompts) => { } const hunks_str = ` ---new_hunk_for_review--- +\`\`\` ${hunks.new_hunk} +\`\`\` + ---old_hunk_for_context--- +\`\`\` ${hunks.old_hunk} +\`\`\` `; patches.push([ patch_lines.new_hunk.start_line, @@ -6672,32 +6677,55 @@ ${summaries_failed.length > 0 ins.filename = filename; // Pack instructions ins.patches += ` -Format for changes - +Format for changes: ---new_hunk_for_review--- - + \`\`\` + + \`\`\` + ---old_hunk_for_context--- - + \`\`\` + + \`\`\` + ---comment_chains_for_context--- + \`\`\` + \`\`\` + ---end_change_section--- ... -Instructions - +Instructions: - Only respond in the below response format and nothing else. Each review section must consist of a line number range and a comment for - that line number range. There's a separator between review sections. + that line number range. Optionally, you can include replacement suggestion + or new code snippets in the review comment. There's a separator between + review sections. - It's important that line number ranges for each review section must be within the line number range of a specific new hunk. i.e. must belong to the same hunk as the - . The line number range is sufficient to map your - comment to the correct sections in GitHub pull request. + . +- Do not repeat back the code being reviewed as the the line number range is + sufficient to map your comment to the correct location in GitHub. - Markdown format is preferred for review comment text. - Fenced code blocks must be used for new content and replacement - code/text snippets. Replacement snippets must be complete, - correctly formatted and most importantly, map exactly to the line - number ranges that need to be replaced inside the hunks. The line - number ranges must not belong to different hunks. Do not annotate - suggested content with line numbers inside the code blocks. + code/text snippets. +- Replacement code/text snippets must be complete and correctly + formatted. The line number range must map exactly to the line + number range that need to be replaced within a new_hunk_for_review. + E.g. if you are suggesting to replace 2 specific lines in a + new_hunk_for_review with 10 lines of code, then the line number + range must be exactly the 2 lines that need to be replaced. + The replacement code/text snippet must use \`suggestion\` as the + language identifier in the fenced code block. Replacement code + suggestions can be directly committed by the user from the GitHub + UI, replacing the code within new_hunk_for_review, that is why + alignment of line number ranges is important. +- New code/text snippets must use the correct language identifier + in the fenced code block. You can use such snippets to suggest + code that can be added in some other file, e.g. test cases. +- Do not annotate snippets with line numbers inside the code blocks. - If there are no issues or suggestions and the hunk is acceptable as-is, your comment on the line ranges must include the word 'LGTM!'. @@ -6707,32 +6735,34 @@ Response format expected - --- -: - \`\`\`suggestion \`\`\` --- -: - \`\`\` \`\`\` --- ... -Example response - +Example response: 1-5: LGTM! --- 6-6: + replace the code on line 6 with the following \`\`\`suggestion - print("Hello!") + for i in range(10): + print("Hello!") + print("World!") + exit(0) \`\`\` --- -Hunks for review are below - +Hunks for review are below: `; // calculate tokens based on inputs so far let tokens = tokenizer/* get_token_count */.u(prompts.render_review_file_diff(ins)); @@ -6795,7 +6825,9 @@ ${patch} if (comment_chain !== '') { ins.patches += ` ---comment_chains_for_review--- +\`\`\` ${comment_chain} +\`\`\` `; } ins.patches += ` diff --git a/src/review.ts b/src/review.ts index 03dc66fb..6c0d4ee1 100644 --- a/src/review.ts +++ b/src/review.ts @@ -371,15 +371,15 @@ ${ // Pack instructions ins.patches += ` -Format for changes - +Format for changes: ---new_hunk_for_review--- \`\`\` - + \`\`\` ---old_hunk_for_context--- \`\`\` - + \`\`\` ---comment_chains_for_context--- @@ -390,22 +390,36 @@ Format for changes - ---end_change_section--- ... -Instructions - +Instructions: - Only respond in the below response format and nothing else. Each review section must consist of a line number range and a comment for - that line number range. There's a separator between review sections. + that line number range. Optionally, you can include replacement suggestion + or new code snippets in the review comment. There's a separator between + review sections. - It's important that line number ranges for each review section must be within the line number range of a specific new hunk. i.e. must belong to the same hunk as the - . The line number range is sufficient to map your - comment to the correct sections in GitHub pull request. + . +- Do not repeat back the code being reviewed as the the line number range is + sufficient to map your comment to the correct location in GitHub. - Markdown format is preferred for review comment text. - Fenced code blocks must be used for new content and replacement - code/text snippets. Replacement snippets must be complete, - correctly formatted and most importantly, map exactly to the line - number ranges that need to be replaced inside the hunks. The line - number ranges must not belong to different hunks. Do not annotate - suggested content with line numbers inside the code blocks. + code/text snippets. +- Replacement code/text snippets must be complete and correctly + formatted. The line number range must map exactly to the line + number range that need to be replaced within a new_hunk_for_review. + E.g. if you are suggesting to replace 2 specific lines in a + new_hunk_for_review with 10 lines of code, then the line number + range must be exactly the 2 lines that need to be replaced. + The replacement code/text snippet must use \`suggestion\` as the + language identifier in the fenced code block. Replacement code + suggestions can be directly committed by the user from the GitHub + UI, replacing the code within new_hunk_for_review, that is why + alignment of line number ranges is important. +- New code/text snippets must use the correct language identifier + in the fenced code block. You can use such snippets to suggest + code that can be added in some other file, e.g. test cases. +- Do not annotate snippets with line numbers inside the code blocks. - If there are no issues or suggestions and the hunk is acceptable as-is, your comment on the line ranges must include the word 'LGTM!'. @@ -415,32 +429,34 @@ Response format expected - --- -: - \`\`\`suggestion \`\`\` --- -: - \`\`\` \`\`\` --- ... -Example response - +Example response: 1-5: LGTM! --- 6-6: + replace the code on line 6 with the following \`\`\`suggestion - print("Hello!") + for i in range(10): + print("Hello!") + print("World!") + exit(0) \`\`\` --- -Hunks for review are below - +Hunks for review are below: ` // calculate tokens based on inputs so far