Created
June 4, 2022 19:01
-
-
Save tobischw/937def6638edd8f1be218dcb272e17e1 to your computer and use it in GitHub Desktop.
Automatically generate commit messages based on diffs using GPT-3
This file contains hidden or 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
// 1. npm init | |
// 2. npm install -save openai simple-git | |
// 3. Grab an API key from OpenAI: https://beta.openai.com/account/api-keys | |
// 4. Replace FOLDER_TO_CHECK with the root path of your git-enabled project | |
// | |
// Eventually the goal of this is to have a command line utility that lets users | |
// generates the commit message and commit immediately. | |
const { Configuration, OpenAIApi } = require("openai"); | |
const simpleGit = require('simple-git'); | |
const configuration = new Configuration({ | |
apiKey: 'API_KEY', | |
}); | |
const openai = new OpenAIApi(configuration); | |
const git = simpleGit({ baseDir: 'FOLDER_TO_CHECK' }); | |
(async () => { | |
const diff = await git.diff(); | |
if(diff) { | |
const completion = await openai.createCompletion("text-davinci-002", { | |
prompt: `Generate a commit message based on this diff:\n ${diff}`, | |
}); | |
console.log(`--> ${completion.data.choices[0].text}`); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment