Skip to content

Commit 08a74bb

Browse files
fix: Updated system prompt for GitCommitGPT-4 to improve commit message content.
1 parent 22a7ed1 commit 08a74bb

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ AI-Commit is a command line tool that uses OpenAI's language generation capabili
1414

1515
## Prerequisites
1616

17-
To use AI-Commit, you need to obtain an API key from OpenAI and set it as the value of the OPENAI_API_KEY environment variable.
17+
To use AI-Commit, you need to obtain an API key from OpenAI and set it as the value of the `OPENAI_API_KEY` environment variable.
18+
19+
```
20+
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
21+
```
22+
23+
Sometime, the ChatGPT's response is not good (too long, too short, not meaningful). In that case, you can try custom the system prompt by set the `AI_COMMIT_SYSTEM_PROMPT` environment variable:
24+
25+
```
26+
export AI_COMMIT_SYSTEM_PROMPT="You are a GitCommitGPT-4, You will help user to write commit message, commit message should be short (less than 100 chars), clean and meaningful. Only response the message."
27+
```
1828

1929
Note: Using AI-Commit will result in charges from OpenAI for API usage, so be sure to understand their pricing model before use.
2030

main.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import (
1111
"time"
1212
)
1313

14-
var messages = []*Message{
15-
{
16-
Role: "system",
17-
Content: `You are a GitCommitGPT-4, You will help user to write commit message, do not talk anything else the commit message. Your commit message is short, clean and meaningful.`,
18-
},
19-
}
14+
var messages []*Message
2015

2116
func main() {
2217
// prepare the arguments
@@ -26,6 +21,18 @@ func main() {
2621
os.Exit(1)
2722
}
2823

24+
systemPrompt := os.Getenv("AI_COMMIT_SYSTEM_PROMPT")
25+
if systemPrompt == "" {
26+
systemPrompt = `You are a GitCommitGPT-4, You will help user to write commit message, commit message should be short (less than 100 chars), clean and meaningful. Only response the message.`
27+
}
28+
29+
messages = []*Message{
30+
{
31+
Role: "system",
32+
Content: systemPrompt,
33+
},
34+
}
35+
2936
client := NewGptClient(apiKey)
3037

3138
// prepare the diff
@@ -68,7 +75,7 @@ func main() {
6875

6976
messages = append(messages, &Message{
7077
Role: "user",
71-
Content: "Write commit message for this git diff output: \n\n" + diff,
78+
Content: "Write commit message for the following git diff: \n\n```" + diff + "\n\n```",
7279
})
7380

7481
for {

0 commit comments

Comments
 (0)