Skip to content

Commit

Permalink
fix: prompts and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jjranalli committed Apr 16, 2023
1 parent 746e584 commit cde8059
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/replyIssueComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export async function replyIssueComment(payload: any, octokit: Octokit) {
const messages: ChatCompletionRequestMessage[] = [
{
role: "system",
content: systemPrompt
content: `${systemPrompt}\n\nHere is the code diff:\n\n${codeDiff}`
},
{
role: "user",
content: `${question}\n\nHere is the code diff:\n\n${codeDiff}`
content: `${question}`
}
]

Expand Down
13 changes: 9 additions & 4 deletions lib/summarizePullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getCodeDiff } from "../utils/getCodeDiff"
export const startDescription = "\n\n<!-- start pr-codex -->"
export const endDescription = "<!-- end pr-codex -->"
const systemPrompt =
'You are a Git diff assistant. Always begin with "This PR". Given a code diff, you provide a simple description in prose, in less than 300 chars, which sums up the changes. Continue with "\n\n### Detailed summary\n" and make a comprehensive list of all changes, excluding any eventual skipped files. Be concise. Always wrap file names, functions, objects and similar in backticks (`).'
"You are a Git diff assistant. Given a code diff, you provide a clear and concise description of its content. Always wrap file names, functions, objects and similar in backticks (`)."

export async function summarizePullRequest(payload: any, octokit: Octokit) {
// Get relevant PR information
Expand All @@ -18,7 +18,7 @@ export async function summarizePullRequest(payload: any, octokit: Octokit) {
}

// Get the diff content using Octokit and GitHub API
const { codeDiff, skippedFiles } = await getCodeDiff(
const { codeDiff, skippedFiles, maxLengthExceeded } = await getCodeDiff(
owner,
repo,
pull_number,
Expand All @@ -30,11 +30,12 @@ export async function summarizePullRequest(payload: any, octokit: Octokit) {
const messages: ChatCompletionRequestMessage[] = [
{
role: "system",
content: systemPrompt
content: `${systemPrompt}\n\nHere is the code diff:\n\n${codeDiff}`
},
{
role: "user",
content: `Here is the code diff:\n\n${codeDiff}`
content:
'Starting with "This PR", clearly explain the focus of this PR in prose, in less than 300 characters. Then follow up with "\n\n### Detailed summary\n" and make a comprehensive list of all changes.'
}
]

Expand All @@ -55,6 +56,10 @@ export async function summarizePullRequest(payload: any, octokit: Octokit) {
", "
)}`
: ""
}${
maxLengthExceeded
? "\n\n> The code diff exceeds the max number of characters, so this overview may be incomplete."
: ""
}\n\n${endDescription}`

const description = hasCodexCommented
Expand Down
2 changes: 1 addition & 1 deletion utils/github/testPayloadComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const testPayloadComment = {
},

comment: {
body: "/ask-codex Describe the changes in the homepage UI"
body: "/ask-codex what changes have been done in the homepage?"
},
sender: {
login: "jjranalli"
Expand Down
4 changes: 2 additions & 2 deletions utils/github/testPayloadSyncPr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const testPayloadSyncPr = {
pull_request: {
diff_url: "https://github.com/decentralizedlabs/pr-codex/pull/4.diff",
number: 4,
// body: null,
body: null,
// body: "\n\n<!-- start pr-codex -->\n\n## PR-Codex overview\nThis PR adds a new feature to the project: a GitHub app that explains and summarizes PR code diffs. It includes a new `github/route.ts` file and updates several existing files, including `README.md`, `Homepage.tsx`, `DefaultHead.tsx`, `AppLayout.tsx`, `Footer.tsx`, and `Navbar.tsx`.\n\n> The following files were skipped due to too many changes: `package-lock.json`.\n\n<!-- end pr-codex -->",
body: "<!-- start -->\n\nthis is a test",
// body: "<!-- start -->\n\nthis is a test",
// body:
// "<!-- start -->\n\nthis is a test" +
// startDescription +
Expand Down

0 comments on commit cde8059

Please sign in to comment.