Skip to content

Commit

Permalink
New module: openaiExplainPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed Nov 29, 2023
1 parent 7e8869a commit 1d243b4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# ![pull-merge](/logo/svg/logo-no-background.svg)

puLL-Merge is a `github-action` to add LLM capabilities to pull-requests in `github` automatically

## Example (local)

```
./run.js ./src/explainPatch.js --openaiKey=<OPENAPI_KEY> --repo=brave/security-action --prnum=406
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"bugs": {
"url": "https://github.com/brave/pull-merge/issues",
"email": "security@brave.com"
Expand Down
9 changes: 9 additions & 0 deletions run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node

import { parseArgs } from 'node:util';
const [ node, file, _module, ...args ] = process.argv;

const run = (await import(_module)).default;
const innerArgs = parseArgs({args, strict: false});

console.log(await run(innerArgs.values));
41 changes: 41 additions & 0 deletions src/openaiExplainPatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import OpenAI from "openai";

export default async function explainPatch({openaiKey, repo, prnum,
model="gpt-3.5-turbo-16k",
system_prompt="Explain the patch:\n\n",
max_tokens=256,
temperature=1,
top_p=1,
frequency_penalty=0,
presence_penalty=0}) {
const openai = new OpenAI({apiKey: openaiKey});

const patchResponse = await fetch(`https://github.com/${repo}/pull/${prnum}.patch`);
const patchBody = await patchResponse.text();

// console.log(patchBody)

const aiResponse = await openai.chat.completions.create({
model: model,
messages: [
{
"role": "system",
"content": "Explain the patch:\n\n"
},
{
"role": "user",
"content": patchBody
}
],
temperature: temperature,
max_tokens: max_tokens,
top_p: top_p,
frequency_penalty: frequency_penalty,
presence_penalty: presence_penalty,
});

// console.log(aiResponse);
// console.log(aiResponse.choices[0].message);

return aiResponse.choices[0].message.content;
}

0 comments on commit 1d243b4

Please sign in to comment.