Skip to content

Commit

Permalink
fix: prompt text order
Browse files Browse the repository at this point in the history
  • Loading branch information
zaidfadhil committed Oct 10, 2024
1 parent bed237c commit a6b5833
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ To generate a commit message:
kemit
```

If there are no staged changes, the application will output "Nothing to commit". Otherwise, it will generate and print a commit message based on the staged diff.
If there are no staged changes, the application will output "Nothing to commit." Otherwise, it will generate and print a commit message based on the staged diff.

## Uninstall

Expand Down
3 changes: 1 addition & 2 deletions engine/ollama.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func (ollama *ollamaEngine) request(diff, style string) (string, error) {
defer resp.Body.Close()

var res map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
if err = json.NewDecoder(resp.Body).Decode(&res); err != nil {
return "", err
}

Expand Down
38 changes: 25 additions & 13 deletions engine/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,39 @@ package engine
import "fmt"

var basePrePrompt = `
- Your task is to create clean and comprehensive git commit message.
- Convert 'git diff --staged' command it into a git commit message.
- Use the present tense.
- Lines limit to 50 characters.
- Message should be one paragraph.
- Message should be very clear and short.
- Skip "Update X file" or "Update" at the beginning of the message and go straight to the point.
- Respond using JSON.
- JSON scheme {"commit_message": string}
*** WHAT TO DO ***
1. Your task is to create clean and comprehensive git commit message.
2. Convert 'git diff --staged' command it into a git commit message.
3. Use the present tense.
4. Lines limit to 50 characters.
5. Message should be one paragraph.
6. Message should be very clear and short.
7. Skip "Update X file" or "Update" at the beginning of the message and go straight to the point.
8. Respond using JSON.
9. JSON scheme {"commit_message": string}
`

var conventionalCommitPrompt = `
- Use Conventional commit.
- Conventional commit keywords: fix, feat, build, chore, ci, docs, style, refactor, perf, test.
- Do not preface the commit with anything.
*** Conventional Commit ***
1. Use Conventional commit.
2. Conventional commit keywords: fix, feat, build, chore, ci, docs, style, refactor, perf, test.
- feat: new feature
- fix: bug fix
- build: changes that affect the build system or external dependencies
- ci: changes to our CI configuration files and scripts
- chore: other changes that don't modify src or test files
- docs: documentation only changes
- style: changes that do not affect the meaning of the code (white-space, formatting, etc)
- refactor: code change that neither fixes a bug nor adds feature
- perf: code change that improves performance
- test: adding missing tests or correcting existing tests
3. Do not preface the commit with anything.
`

func createPrompt(diff, style string) string {
if style == "conventional-commit" {
basePrePrompt = basePrePrompt + conventionalCommitPrompt
}

return fmt.Sprintf("%s\n%s", basePrePrompt, diff)
return fmt.Sprintf("git diff: ```%s``` \n %s", diff, basePrePrompt)
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func run(cfg *config.Config) {
}

if diff == "" {
fmt.Println("Nothing to commit")
fmt.Println("Nothing to commit.")
} else {
// TODO: move this to the enigne pkg
ollama := engine.NewOllama(cfg.OllamaHost, cfg.OllamaModel)
Expand Down

0 comments on commit a6b5833

Please sign in to comment.