-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathgenerateDiffReviewPrompt.ts
More file actions
53 lines (36 loc) · 1.95 KB
/
generateDiffReviewPrompt.ts
File metadata and controls
53 lines (36 loc) · 1.95 KB
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
import { sourcebot_diff, sourcebot_context, sourcebot_file_diff_review_schema } from "@/features/agents/review-agent/types";
import { zodToJsonSchema } from "zod-to-json-schema";
import { createLogger } from "@sourcebot/shared";
const logger = createLogger('generate-diff-review-prompt');
export const generateDiffReviewPrompt = async (diffs: sourcebot_diff[], context: sourcebot_context[], rules: string[]) => {
logger.debug("Executing generate_diff_review_prompt");
const hunksText = diffs.map((diff, i) => `
## Hunk ${i + 1}
### Old Code
\`\`\`
${diff.oldSnippet}
\`\`\`
### New Code
\`\`\`
${diff.newSnippet}
\`\`\`
`).join('\n');
const prompt = `
You are an expert software engineer that excels at reviewing code changes. Given the input, additional context, and rules defined below, review the code changes and provide a detailed review. The review you provide
must conform to all of the rules defined below. The output format of your review must conform to the output format defined below.
# Input
The input is the old and new code snippets for one or more hunks from a git diff for a single file. The old code snippet is the code before the changes were made, and the new code snippet is the code after the changes were made. Each code snippet
is a sequence of lines each with a line number.
${hunksText}
# Additional Context
${context.map(c => `${c.type}: ${c.description}\n\n${c.context}`).join("\n\n----------------------\n\n")}
# Rules
- ${rules.join("\n- ")}
# Output Format (JSON Schema)
The output must be a valid JSON object that conforms to the following JSON schema. Do NOT respond with anything other than the JSON object. Do NOT respond with
the JSON object in a markdown code block.
${JSON.stringify(zodToJsonSchema(sourcebot_file_diff_review_schema), null, 2)}
`;
logger.debug("Completed generate_diff_review_prompt");
return prompt;
}