git-aicommit 7.0.1 → 7.1.0
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/README.md +13 -10
- package/autocommit.js +21 -14
- package/config.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,30 +36,33 @@ touch $HOME/.git-aicommitrc
|
|
|
36
36
|
// $HOME/.git-aicommitrc
|
|
37
37
|
export default {
|
|
38
38
|
openAiKey: process.env.OPENAI_API_KEY,
|
|
39
|
-
|
|
39
|
+
azureOpenAiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
40
|
+
azureOpenAiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
|
|
41
|
+
azureOpenAiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
42
|
+
azureOpenAiVersion: process.env.AZURE_OPENAI_API_VERSION,
|
|
40
43
|
autocommit: true,
|
|
41
44
|
openCommitTextEditor: false,
|
|
42
45
|
language: 'english',
|
|
43
46
|
systemMessagePromptTemplate: '' +
|
|
44
|
-
'You are expert
|
|
47
|
+
'You are expert software developer, your job is to write clear and concise Git commit messages. ' +
|
|
45
48
|
'Your responsibility is to ensure that these messages accurately describe the changes made in each commit,' +
|
|
46
49
|
'follow established guidelines. Provide a clear history of changes to the codebase.' +
|
|
47
50
|
'Write 1-2 sentences. Output only the commit message without comments or other text.',
|
|
48
51
|
humanPromptTemplate: '' +
|
|
49
52
|
'Read the following git diff for a multiple files and ' +
|
|
50
53
|
'write 1-2 sentences commit message in {language}' +
|
|
51
|
-
'without mentioning lines or files
|
|
54
|
+
'without mentioning lines or files.' +
|
|
55
|
+
'If the reason behind the changed can be deducted from the changed, provide this reason:\n' +
|
|
52
56
|
'{diff}',
|
|
53
57
|
excludeFromDiff: [
|
|
54
|
-
'*.lock', '*.lockb'
|
|
58
|
+
'*.lock', '*.lockb', '*-lock.json', '*-lock.yaml'
|
|
55
59
|
],
|
|
56
60
|
diffFilter: 'ACMRTUXB',
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
maxTokens: 1000,
|
|
61
|
-
}
|
|
61
|
+
modelName: "gpt-4.1-mini",
|
|
62
|
+
temperature: 0.0,
|
|
63
|
+
maxTokens: 2000,
|
|
62
64
|
}
|
|
65
|
+
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
### Command line arguments
|
|
@@ -77,7 +80,7 @@ git-aicommit
|
|
|
77
80
|
Or make an alias:
|
|
78
81
|
|
|
79
82
|
```bash
|
|
80
|
-
alias gai=
|
|
83
|
+
alias gai="git add --all && git-aicommit && git push"
|
|
81
84
|
|
|
82
85
|
## And run it:
|
|
83
86
|
gai
|
package/autocommit.js
CHANGED
|
@@ -58,12 +58,13 @@ if (!diff) {
|
|
|
58
58
|
const openai = new OpenAI({
|
|
59
59
|
apiKey: config.openAiKey,
|
|
60
60
|
baseURL: config.azureOpenAiKey ? `https://${config.azureOpenAiInstanceName}.openai.azure.com/openai/deployments/${config.azureOpenAiDeploymentName}` : undefined,
|
|
61
|
-
defaultHeaders: config.azureOpenAiKey ? { 'api-key': config.azureOpenAiKey } : undefined
|
|
61
|
+
defaultHeaders: config.azureOpenAiKey ? { 'api-key': config.azureOpenAiKey } : undefined,
|
|
62
|
+
defaultQuery: config.azureOpenAiKey ? { 'api-version': config.azureOpenAiVersion } : undefined, // defaultQuery for api-version as per OpenAI SDK v4+ for Azure
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
async function getChatCompletion(messages) {
|
|
65
66
|
const response = await openai.chat.completions.create({
|
|
66
|
-
model: config.modelName || 'gpt-
|
|
67
|
+
model: config.modelName || 'gpt-4.1-mini',
|
|
67
68
|
messages: messages,
|
|
68
69
|
temperature: config.temperature,
|
|
69
70
|
max_tokens: config.maxTokens,
|
|
@@ -75,24 +76,21 @@ async function getChatCompletion(messages) {
|
|
|
75
76
|
const systemMessage = { role: "system", content: config.systemMessagePromptTemplate };
|
|
76
77
|
const userMessage = { role: "user", content: config.humanPromptTemplate.replace("{diff}", diff).replace("{language}", config.language) };
|
|
77
78
|
|
|
78
|
-
const chatMessages = [systemMessage, userMessage];
|
|
79
|
-
|
|
80
79
|
const tokenCount = await calculateMaxTokens({
|
|
81
80
|
prompt: diff,
|
|
82
|
-
modelName: config.modelName || 'gpt-
|
|
81
|
+
modelName: config.modelName || 'gpt-4.1-mini'
|
|
83
82
|
});
|
|
84
83
|
|
|
85
|
-
const contextSize = getModelContextSize(config.modelName || 'gpt-
|
|
84
|
+
const contextSize = getModelContextSize(config.modelName || 'gpt-4.1-mini');
|
|
86
85
|
|
|
87
86
|
if (tokenCount > contextSize) {
|
|
88
|
-
console.log('Diff is too long. Please lower the amount of changes in the commit or switch to a model with
|
|
89
|
-
|
|
87
|
+
console.log('Diff is too long for the current model context. Please lower the amount of changes in the commit or switch to a model with a larger context window.');
|
|
90
88
|
process.exit(1);
|
|
91
89
|
}
|
|
92
90
|
|
|
93
91
|
const messages = [
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
systemMessage,
|
|
93
|
+
userMessage
|
|
96
94
|
];
|
|
97
95
|
|
|
98
96
|
const commitMessage = await getChatCompletion(messages);
|
|
@@ -101,10 +99,19 @@ if (!config.autocommit) {
|
|
|
101
99
|
console.log(`Autocommit is disabled. Here is the message:\n ${commitMessage}`);
|
|
102
100
|
} else {
|
|
103
101
|
console.log(`Committing with following message:\n ${commitMessage}`);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
try {
|
|
103
|
+
execSync(
|
|
104
|
+
'git commit -F -',
|
|
105
|
+
{
|
|
106
|
+
input: commitMessage,
|
|
107
|
+
encoding: 'utf8',
|
|
108
|
+
stdio: 'inherit'
|
|
109
|
+
}
|
|
110
|
+
);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("Failed to commit.", error);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
108
115
|
}
|
|
109
116
|
|
|
110
117
|
if (config.openCommitTextEditor) {
|
package/config.js
CHANGED