aicommits 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.example.env.json +1 -0
- package/README.md +34 -0
- package/aicommit.js +82 -0
- package/package.json +20 -0
- package/screenshot.png +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "OPENAI_API_KEY": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxx" }
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# AI Commit
|
|
2
|
+
|
|
3
|
+
Have AI Commit write your git commit messages for you so you never have to write a commit message again.
|
|
4
|
+
|
|
5
|
+
[](https://twitter.com/nutlope/status/1624646872890589184)
|
|
6
|
+
|
|
7
|
+
## How to install
|
|
8
|
+
|
|
9
|
+
`npm install -g autocommit`
|
|
10
|
+
|
|
11
|
+
**Note:** The process to install this will get vastly simplified when I rewrite this CLI and publish it as an npm package to be run with `npx`.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
This project uses a command line interface tool called zx that's developed by google. In the script, it runs a `git diff` command to grab all the latest changes, sends this to OpenAI's GPT-3, then returns the AI generated commit message. Video coming soon where I rebuild it from scratch to show you how to easily build your own CLI tools powered by AI. Fully privacy friendly as commands only run on your local machine using your OpenAI account.
|
|
16
|
+
|
|
17
|
+
This CLI also supports conventional commits. If you want conventional commits, simply set the `conventionalCommit` variable at the top of the script to `true`.
|
|
18
|
+
|
|
19
|
+
## Remaining tasks
|
|
20
|
+
|
|
21
|
+
Now:
|
|
22
|
+
|
|
23
|
+
- [ ] Rewrite this in node to publish as an npm package
|
|
24
|
+
- [ ] Figure out how to fail gracefully instead of exit 1
|
|
25
|
+
- [ ] Try openai curie And/OR codex
|
|
26
|
+
|
|
27
|
+
After:
|
|
28
|
+
|
|
29
|
+
- [ ] Rewrite in TypeScript
|
|
30
|
+
- [ ] Look into better conventional commit support, look at other CLIs
|
|
31
|
+
- [ ] Try supporting more than 200 lines by grabbing the diff per file
|
|
32
|
+
- [ ] Build landing page
|
|
33
|
+
|
|
34
|
+
# How to run new version
|
package/aicommit.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#!/usr/bin/env zx
|
|
2
|
+
|
|
3
|
+
void (async function () {
|
|
4
|
+
$.verbose = false;
|
|
5
|
+
|
|
6
|
+
// TODO: Figure out how to fail gracefully instead of exit 1
|
|
7
|
+
|
|
8
|
+
let conventionalCommit = false;
|
|
9
|
+
|
|
10
|
+
console.log(chalk.white("▲ ") + chalk.green("Welcome to AICommit!"));
|
|
11
|
+
|
|
12
|
+
let pwd = await $`cd ~ && pwd;`;
|
|
13
|
+
|
|
14
|
+
let { OPENAI_API_KEY } = await fs.readJson(
|
|
15
|
+
`${pwd.stdout.trim()}/ai-commit/.env.json`
|
|
16
|
+
);
|
|
17
|
+
let diff = await $`git diff --cached`;
|
|
18
|
+
|
|
19
|
+
// Accounting for GPT-3's input req of 4k tokens (approx 8k chars)
|
|
20
|
+
if (diff.stdout.length > 8000) {
|
|
21
|
+
console.log("The diff is too large to write a commit message.");
|
|
22
|
+
await $`exit 1`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (diff.stdout.length === 0) {
|
|
26
|
+
console.log(
|
|
27
|
+
"No staged changes found. Make sure there are changes and run `git add .`"
|
|
28
|
+
);
|
|
29
|
+
await $`exit 1`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let prompt = `I want you to act like a git commit message writer. I will input a git diff and your job is to convert it into a useful commit message. ${
|
|
33
|
+
conventionalCommit
|
|
34
|
+
? "Preface the commit with 'feat:' if it is a feature or 'fix:' if it is a bug."
|
|
35
|
+
: "Do not preface the commit with anything."
|
|
36
|
+
} Return a complete sentence and do not repeat yourself: ${diff}`;
|
|
37
|
+
|
|
38
|
+
const payload = {
|
|
39
|
+
model: "text-davinci-003",
|
|
40
|
+
prompt,
|
|
41
|
+
temperature: 0.7,
|
|
42
|
+
top_p: 1,
|
|
43
|
+
frequency_penalty: 0,
|
|
44
|
+
presence_penalty: 0,
|
|
45
|
+
max_tokens: 200,
|
|
46
|
+
stream: false,
|
|
47
|
+
n: 1,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
console.log(
|
|
51
|
+
chalk.white("▲ ") + chalk.gray("Generating your AI commit message...")
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const response = await fetch("https://api.openai.com/v1/completions", {
|
|
55
|
+
headers: {
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
Authorization: `Bearer ${OPENAI_API_KEY ?? ""}`,
|
|
58
|
+
},
|
|
59
|
+
method: "POST",
|
|
60
|
+
body: JSON.stringify(payload),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const json = await response.json();
|
|
64
|
+
const aiCommit = json.choices[0].text;
|
|
65
|
+
let cleanedUpAiCommit = aiCommit.replace(/(\r\n|\n|\r)/gm, "");
|
|
66
|
+
|
|
67
|
+
echo(cleanedUpAiCommit);
|
|
68
|
+
|
|
69
|
+
let confirmationMessage = await question(
|
|
70
|
+
"\nWould you like to use this commit message? " + chalk.yellow("(Y/n) "),
|
|
71
|
+
{
|
|
72
|
+
choices: ["Y", "n"],
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
$.verbose = true;
|
|
77
|
+
echo("\n");
|
|
78
|
+
|
|
79
|
+
if (confirmationMessage !== "n") {
|
|
80
|
+
await $`git commit -m ${cleanedUpAiCommit}`;
|
|
81
|
+
}
|
|
82
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aicommits",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "generates ai commit",
|
|
5
|
+
"main": "aicommit.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"start": "./aicommit.js"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"gpt-commit": "./aicommit.js"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Nutlope/ai-commit.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "hassan",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"homepage": "https://github.com/Nutlope/ai-commit#readme"
|
|
20
|
+
}
|
package/screenshot.png
ADDED
|
Binary file
|