This repository has been archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
/
prompts.ts
282 lines (210 loc) · 7.36 KB
/
prompts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import {type Inputs} from './inputs'
export class Prompts {
summarize: string
summarizeReleaseNotes: string
summarizeFileDiff = `## GitHub PR Title
\`$title\`
## Description
\`\`\`
$description
\`\`\`
## Diff
\`\`\`diff
$file_diff
\`\`\`
## Instructions
I would like you to succinctly summarize the diff within 100 words.
If applicable, your summary should include a note about alterations
to the signatures of exported functions, global data structures and
variables, and any changes that might affect the external interface or
behavior of the code.
`
triageFileDiff = `Below the summary, I would also like you to triage the diff as \`NEEDS_REVIEW\` or
\`APPROVED\` based on the following criteria:
- If the diff involves any modifications to the logic or functionality, even if they
seem minor, triage it as \`NEEDS_REVIEW\`. This includes changes to control structures,
function calls, or variable assignments that might impact the behavior of the code.
- If the diff only contains very minor changes that don't affect the code logic, such as
fixing typos, formatting, or renaming variables for clarity, triage it as \`APPROVED\`.
Please evaluate the diff thoroughly and take into account factors such as the number of
lines changed, the potential impact on the overall system, and the likelihood of
introducing new bugs or security vulnerabilities.
When in doubt, always err on the side of caution and triage the diff as \`NEEDS_REVIEW\`.
You must strictly follow the format below for triaging the diff:
[TRIAGE]: <NEEDS_REVIEW or APPROVED>
Important:
- In your summary do not mention that the file needs a through review or caution about
potential issues.
- Do not provide any reasoning why you triaged the diff as \`NEEDS_REVIEW\` or \`APPROVED\`.
- Do not mention that these changes affect the logic or functionality of the code in
the summary. You must only use the triage status format above to indicate that.
`
summarizeChangesets = `Provided below are changesets in this pull request. Changesets
are in chronlogical order and new changesets are appended to the
end of the list. The format consists of filename(s) and the summary
of changes for those files. There is a separator between each changeset.
Your task is to deduplicate and group together files with
related/similar changes into a single changeset. Respond with the updated
changesets using the same format as the input.
$raw_summary
`
summarizePrefix = `Here is the summary of changes you have generated for files:
\`\`\`
$raw_summary
\`\`\`
`
summarizeShort = `Your task is to provide a concise summary of the changes. This
summary will be used as a prompt while reviewing each file and must be very clear for
the AI bot to understand.
Instructions:
- Focus on summarizing only the changes in the PR and stick to the facts.
- Do not provide any instructions to the bot on how to perform the review.
- Do not mention that files need a through review or caution about potential issues.
- Do not mention that these changes affect the logic or functionality of the code.
- The summary should not exceed 500 words.
`
reviewFileDiff = `## GitHub PR Title
\`$title\`
## Description
\`\`\`
$description
\`\`\`
## Summary of changes
\`\`\`
$short_summary
\`\`\`
## IMPORTANT Instructions
Input: New hunks annotated with line numbers and old hunks (replaced code). Hunks represent incomplete code fragments.
Additional Context: PR title, description, summaries and comment chains.
Task: Review new hunks for substantive issues using provided context and respond with comments if necessary.
Output: Review comments in markdown with exact line number ranges in new hunks. Start and end line numbers must be within the same hunk. For single-line comments, start=end line number. Must use example response format below.
Use fenced code blocks using the relevant language identifier where applicable.
Don't annotate code snippets with line numbers. Format and indent code correctly.
Do not use \`suggestion\` code blocks.
For fixes, use \`diff\` code blocks, marking changes with \`+\` or \`-\`. The line number range for comments with fix snippets must exactly match the range to replace in the new hunk.
- Do NOT provide general feedback, summaries, explanations of changes, or praises
for making good additions.
- Focus solely on offering specific, objective insights based on the
given context and refrain from making broad comments about potential impacts on
the system or question intentions behind the changes.
If there are no issues found on a line range, you MUST respond with the
text \`LGTM!\` for that line range in the review section.
## Example
### Example changes
---new_hunk---
\`\`\`
z = x / y
return z
20: def add(x, y):
21: z = x + y
22: retrn z
23:
24: def multiply(x, y):
25: return x * y
def subtract(x, y):
z = x - y
\`\`\`
---old_hunk---
\`\`\`
z = x / y
return z
def add(x, y):
return x + y
def subtract(x, y):
z = x - y
\`\`\`
---comment_chains---
\`\`\`
Please review this change.
\`\`\`
---end_change_section---
### Example response
22-22:
There's a syntax error in the add function.
\`\`\`diff
- retrn z
+ return z
\`\`\`
---
24-25:
LGTM!
---
## Changes made to \`$filename\` for your review
$patches
`
comment = `A comment was made on a GitHub PR review for a
diff hunk on a file - \`$filename\`. I would like you to follow
the instructions in that comment.
## GitHub PR Title
\`$title\`
## Description
\`\`\`
$description
\`\`\`
## Summary generated by the AI bot
\`\`\`
$short_summary
\`\`\`
## Entire diff
\`\`\`diff
$file_diff
\`\`\`
## Diff being commented on
\`\`\`diff
$diff
\`\`\`
## Instructions
Please reply directly to the new comment (instead of suggesting
a reply) and your reply will be posted as-is.
If the comment contains instructions/requests for you, please comply.
For example, if the comment is asking you to generate documentation
comments on the code, in your reply please generate the required code.
In your reply, please make sure to begin the reply by tagging the user
with "@user".
## Comment format
\`user: comment\`
## Comment chain (including the new comment)
\`\`\`
$comment_chain
\`\`\`
## The comment/request that you need to directly reply to
\`\`\`
$comment
\`\`\`
`
constructor(summarize = '', summarizeReleaseNotes = '') {
this.summarize = summarize
this.summarizeReleaseNotes = summarizeReleaseNotes
}
renderSummarizeFileDiff(
inputs: Inputs,
reviewSimpleChanges: boolean
): string {
let prompt = this.summarizeFileDiff
if (reviewSimpleChanges === false) {
prompt += this.triageFileDiff
}
return inputs.render(prompt)
}
renderSummarizeChangesets(inputs: Inputs): string {
return inputs.render(this.summarizeChangesets)
}
renderSummarize(inputs: Inputs): string {
const prompt = this.summarizePrefix + this.summarize
return inputs.render(prompt)
}
renderSummarizeShort(inputs: Inputs): string {
const prompt = this.summarizePrefix + this.summarizeShort
return inputs.render(prompt)
}
renderSummarizeReleaseNotes(inputs: Inputs): string {
const prompt = this.summarizePrefix + this.summarizeReleaseNotes
return inputs.render(prompt)
}
renderComment(inputs: Inputs): string {
return inputs.render(this.comment)
}
renderReviewFileDiff(inputs: Inputs): string {
return inputs.render(this.reviewFileDiff)
}
}