git-aicommit 7.6.0 → 8.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/README.md CHANGED
@@ -36,13 +36,13 @@ touch $HOME/.git-aicommitrc
36
36
  // $HOME/.git-aicommitrc
37
37
  export default {
38
38
  openAiKey: process.env.OPENAI_API_KEY,
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,
39
+ baseURL: process.env.OPENAI_BASE_URL || null,
40
+ defaultHeaders: null,
41
+ defaultQuery: null,
43
42
  autocommit: true,
44
43
  openCommitTextEditor: false,
45
44
  language: 'english',
45
+ projectInstruction: null,
46
46
  systemMessagePromptTemplate: '' +
47
47
  'You are expert software developer, your job is to write clear and concise Git commit messages. ' +
48
48
  'Your responsibility is to ensure that these messages accurately describe the changes made in each commit,' +
@@ -50,19 +50,39 @@ export default {
50
50
  'Write 1-2 sentences. Output only the commit message without comments or other text.',
51
51
  humanPromptTemplate: '' +
52
52
  'Read the following git diff for a multiple files and ' +
53
- 'write 1-2 sentences commit message in {language}' +
54
- 'without mentioning lines or files.' +
55
- 'If the reason behind the changed can be deducted from the changed, provide this reason:\n' +
53
+ 'write 1-2 sentences commit message in {language} ' +
54
+ 'without mentioning lines or files. ' +
55
+ 'If the reason behind the changed can be deducted from the changed, provide this reason.\n' +
56
+ 'Current branch: {branch}\n' +
57
+ '{projectInstruction}\n' +
58
+ '{customInstruction}\n' +
59
+ 'Git diff:\n' +
56
60
  '{diff}',
57
61
  excludeFromDiff: [
58
62
  '*.lock', '*.lockb', '*-lock.json', '*-lock.yaml'
59
63
  ],
60
64
  diffFilter: 'ACMRTUXB',
61
65
  modelName: "gpt-4.1-mini",
62
- temperature: 0.0,
63
- maxTokens: 2000,
66
+ completionPromptParams: {
67
+ maxTokens: 2000,
68
+ },
64
69
  }
70
+ ```
71
+
72
+ ### Prompt Template Variables
73
+
74
+ The `humanPromptTemplate` supports the following variables:
75
+
76
+ - `{diff}` - The git diff of staged changes
77
+ - `{language}` - The language for the commit message (default: 'english')
78
+ - `{branch}` - Current git branch name
79
+ - `{projectInstruction}` - Project-level instructions (configurable via config file)
80
+ - `{customInstruction}` - Custom instruction passed via command line
81
+
82
+ Example usage with custom instruction:
65
83
 
84
+ ```bash
85
+ git-aicommit added fix for issue #123
66
86
  ```
67
87
 
68
88
  ### Command line arguments
@@ -86,4 +106,27 @@ alias gai="git add --all && git-aicommit && git push"
86
106
  gai
87
107
  ```
88
108
 
109
+ ## Azure OpenAI Integration
110
+
111
+ To use Azure OpenAI instead of the official OpenAI API, set the following environment variables:
112
+
113
+ ```bash
114
+ export OPENAI_API_KEY="your-azure-api-key"
115
+ export OPENAI_BASE_URL="https://<your-instance>.openai.azure.com/openai/deployments/<your-deployment>"
116
+ export OPENAI_DEFAULT_HEADERS='{"api-key": "your-azure-api-key"}'
117
+ export OPENAI_DEFAULT_QUERY='{"api-version": "2024-02-15-preview"}'
118
+ ```
119
+
120
+ Or add them to your config file:
121
+
122
+ ```js
123
+ // $HOME/.git-aicommitrc
124
+ export default {
125
+ openAiKey: process.env.AZURE_OPENAI_API_KEY,
126
+ baseURL: process.env.AZURE_OPENAI_BASE_URL,
127
+ defaultHeaders: { 'api-key': process.env.AZURE_OPENAI_API_KEY },
128
+ defaultQuery: { 'api-version': '2024-02-15-preview' },
129
+ }
130
+ ```
131
+
89
132
  It's that simple!
package/autocommit.js CHANGED
@@ -11,10 +11,15 @@ const config = rc(
11
11
  {
12
12
  ...defaultConfig,
13
13
  openAiKey: process.env.OPENAI_API_KEY,
14
- azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY
14
+ baseURL: process.env.OPENAI_BASE_URL,
15
+ defaultHeaders: process.env.OPENAI_DEFAULT_HEADERS ? JSON.parse(process.env.OPENAI_DEFAULT_HEADERS) : null,
16
+ defaultQuery: process.env.OPENAI_DEFAULT_QUERY ? JSON.parse(process.env.OPENAI_DEFAULT_QUERY) : null,
15
17
  },
16
18
  );
17
19
 
20
+ // Parse command-line arguments (everything after the script name)
21
+ const customInstruction = process.argv.slice(2).join(' ');
22
+
18
23
  try {
19
24
  execSync(
20
25
  'git rev-parse --is-inside-work-tree',
@@ -25,16 +30,11 @@ try {
25
30
  process.exit(1);
26
31
  }
27
32
 
28
- if (!config.openAiKey && !config.azureOpenAiKey) {
29
- console.error("Please set OPENAI_API_KEY or AZURE_OPENAI_API_KEY");
30
- process.exit(1);
31
- }
33
+ // Get current git branch name
34
+ const branch = execSync('git rev-parse --abbrev-ref HEAD', {encoding: 'utf8'}).trim();
32
35
 
33
- // if any settings related to AZURE are set, if there are items that are not set, will error.
34
- if (config.azureOpenAiKey && !(
35
- config.azureOpenAiInstanceName && config.azureOpenAiDeploymentName && config.azureOpenAiVersion
36
- )){
37
- console.error("Please set AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_INSTANCE_NAME, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_VERSION when Azure OpenAI Service.");
36
+ if (!config.openAiKey) {
37
+ console.error("Please set OPENAI_API_KEY");
38
38
  process.exit(1);
39
39
  }
40
40
 
@@ -57,9 +57,9 @@ if (!diff) {
57
57
 
58
58
  const openai = new OpenAI({
59
59
  apiKey: config.openAiKey,
60
- baseURL: config.azureOpenAiKey ? `https://${config.azureOpenAiInstanceName}.openai.azure.com/openai/deployments/${config.azureOpenAiDeploymentName}` : 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
60
+ baseURL: config.baseURL || undefined,
61
+ defaultHeaders: config.defaultHeaders || undefined,
62
+ defaultQuery: config.defaultQuery || undefined,
63
63
  });
64
64
 
65
65
  async function getChatCompletion(messages) {
@@ -73,7 +73,14 @@ async function getChatCompletion(messages) {
73
73
  }
74
74
 
75
75
  const systemMessage = { role: "system", content: config.systemMessagePromptTemplate };
76
- const userMessage = { role: "user", content: config.humanPromptTemplate.replace("{diff}", diff).replace("{language}", config.language) };
76
+ const userPrompt = config.humanPromptTemplate
77
+ .replace("{diff}", diff)
78
+ .replace("{language}", config.language)
79
+ .replace("{branch}", branch)
80
+ .replace("{projectInstruction}", config.projectInstruction || '')
81
+ .replace("{customInstruction}", customInstruction || '');
82
+
83
+ const userMessage = { role: "user", content: userPrompt };
77
84
 
78
85
  const tokenCount = await calculateMaxTokens({
79
86
  prompt: diff,
package/config.js CHANGED
@@ -1,12 +1,12 @@
1
1
  export default {
2
2
  openAiKey: process.env.OPENAI_API_KEY,
3
- azureOpenAiKey: process.env.AZURE_OPENAI_API_KEY,
4
- azureOpenAiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
5
- azureOpenAiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
6
- azureOpenAiVersion: process.env.AZURE_OPENAI_API_VERSION,
3
+ baseURL: process.env.OPENAI_BASE_URL || null,
4
+ defaultHeaders: null,
5
+ defaultQuery: null,
7
6
  autocommit: true,
8
7
  openCommitTextEditor: false,
9
8
  language: 'english',
9
+ projectInstruction: null,
10
10
  systemMessagePromptTemplate: '' +
11
11
  'You are expert software developer, your job is to write clear and concise Git commit messages. ' +
12
12
  'Your responsibility is to ensure that these messages accurately describe the changes made in each commit,' +
@@ -14,14 +14,20 @@ export default {
14
14
  'Write 1-2 sentences. Output only the commit message without comments or other text.',
15
15
  humanPromptTemplate: '' +
16
16
  'Read the following git diff for a multiple files and ' +
17
- 'write 1-2 sentences commit message in {language}' +
18
- 'without mentioning lines or files.' +
19
- 'If the reason behind the changed can be deducted from the changed, provide this reason:\n' +
17
+ 'write 1-2 sentences commit message in {language} ' +
18
+ 'without mentioning lines or files. ' +
19
+ 'If the reason behind the changed can be deducted from the changed, provide this reason.\n' +
20
+ 'Current branch: {branch}\n' +
21
+ '{projectInstruction}\n' +
22
+ '{customInstruction}\n' +
23
+ 'Git diff:\n' +
20
24
  '{diff}',
21
25
  excludeFromDiff: [
22
26
  '*.lock', '*.lockb', '*-lock.json', '*-lock.yaml'
23
27
  ],
24
28
  diffFilter: 'ACMRTUXB',
25
29
  modelName: "gpt-4.1-mini",
26
- maxTokens: 2000,
30
+ completionPromptParams: {
31
+ maxTokens: 2000,
32
+ },
27
33
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "git-aicommit",
3
- "version": "7.6.0",
4
- "description": "Generates auto commit messages with OpenAI GPT3 model",
3
+ "version": "8.0.3",
4
+ "description": "Generates auto commit messages with OpenAI models",
5
5
  "main": "autocommit.js",
6
- "repository": "https://github.com/shanginn/autocommit",
6
+ "repository": "https://github.com/shanginn/git-aicommit",
7
7
  "author": "shanginn@gmail.com",
8
8
  "license": "MIT",
9
9
  "type": "module",