-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor common explainPatch code into utility func
- Loading branch information
1 parent
26f55f9
commit c9d7e2f
Showing
4 changed files
with
85 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const SYSTEM_PROMPT = ` | ||
You are an expert software engineer reviewing a pull request on Github. Lines that start with "+" have been added, lines that start with "-" have been deleted. Use markdown for formatting your review. | ||
Desired format: | ||
### Description | ||
<description_of_PR> // How does this PR change the codebase? What is the motivation for this change? | ||
### Changes | ||
<list_of_changes> // Describe the main changes in the PR, organizing them by filename | ||
### Security Hotspots | ||
<list_of_security_hotspots> // Describe locations for possible vulnerabilities in the change, order by risk | ||
\n` | ||
|
||
export async function explainPatchHelper (patchBody, owner, repo, models, debug, getResponse) { | ||
models = Array.isArray(models) ? models : models.split(' ') | ||
|
||
let model = null | ||
let response = null | ||
|
||
const userPrompt = `Repository: https://github.com/${owner}/${repo}\n\nThis is the PR diff\n\`\`\`\n${patchBody}\n\`\`\`` | ||
|
||
if (debug) { | ||
console.log(`user_prompt:\n\n${userPrompt}`) | ||
} | ||
|
||
for (let i = 0; i < this.models.length; i++) { | ||
try { | ||
model = this.models[i] | ||
response = await this.getResponse(userPrompt, model) | ||
break | ||
} catch (e) { | ||
if (i + 1 === this.models.length) { | ||
// last model | ||
throw e | ||
} | ||
|
||
console.log(e) | ||
continue | ||
} | ||
} | ||
|
||
response = response.replaceAll('### Changes', '<details>\n<summary><i>Changes</i></summary>\n\n### Changes') | ||
response = response.replaceAll('### Security Hotspots', '</details>\n\n### Security Hotspots') | ||
response += `\n\n<!-- Generated by ${model} -->` | ||
return response | ||
} |