From cde80595310f0bc4259e64f68597a25d7a4f2881 Mon Sep 17 00:00:00 2001 From: jj_ranalli Date: Sun, 16 Apr 2023 21:57:10 +0200 Subject: [PATCH] fix: prompts and logic --- lib/replyIssueComment.ts | 4 ++-- lib/summarizePullRequest.ts | 13 +++++++++---- utils/github/testPayloadComment.ts | 2 +- utils/github/testPayloadSyncPr.ts | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/replyIssueComment.ts b/lib/replyIssueComment.ts index 07386ad..f4ca8cd 100644 --- a/lib/replyIssueComment.ts +++ b/lib/replyIssueComment.ts @@ -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}` } ] diff --git a/lib/summarizePullRequest.ts b/lib/summarizePullRequest.ts index 679a612..43b7d9f 100644 --- a/lib/summarizePullRequest.ts +++ b/lib/summarizePullRequest.ts @@ -6,7 +6,7 @@ import { getCodeDiff } from "../utils/getCodeDiff" export const startDescription = "\n\n" export const endDescription = "" 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 @@ -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, @@ -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.' } ] @@ -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 diff --git a/utils/github/testPayloadComment.ts b/utils/github/testPayloadComment.ts index 8adf62c..0dfadb7 100644 --- a/utils/github/testPayloadComment.ts +++ b/utils/github/testPayloadComment.ts @@ -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" diff --git a/utils/github/testPayloadSyncPr.ts b/utils/github/testPayloadSyncPr.ts index 00ca963..f1512cc 100644 --- a/utils/github/testPayloadSyncPr.ts +++ b/utils/github/testPayloadSyncPr.ts @@ -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\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", - body: "\n\nthis is a test", + // body: "\n\nthis is a test", // body: // "\n\nthis is a test" + // startDescription +