Skip to content

Commit

Permalink
fix: Updated system prompt for GitCommitGPT-4 to improve commit messa…
Browse files Browse the repository at this point in the history
…ge content.
  • Loading branch information
nguyenvanduocit committed Mar 15, 2023
1 parent 22a7ed1 commit 08a74bb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ AI-Commit is a command line tool that uses OpenAI's language generation capabili

## Prerequisites

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.
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.

```
export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
```

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:

```
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."
```

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

Expand Down
21 changes: 14 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import (
"time"
)

var messages = []*Message{
{
Role: "system",
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.`,
},
}
var messages []*Message

func main() {
// prepare the arguments
Expand All @@ -26,6 +21,18 @@ func main() {
os.Exit(1)
}

systemPrompt := os.Getenv("AI_COMMIT_SYSTEM_PROMPT")
if systemPrompt == "" {
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.`
}

messages = []*Message{
{
Role: "system",
Content: systemPrompt,
},
}

client := NewGptClient(apiKey)

// prepare the diff
Expand Down Expand Up @@ -68,7 +75,7 @@ func main() {

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

for {
Expand Down

0 comments on commit 08a74bb

Please sign in to comment.