Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ https://github.com/douo/magit-gptcommit/assets/743074/8494b235-aa1a-4404-82e3-0a
# Dependencies

- [magit](https://magit.vc/)
- [llm](https://github.com/ahyatt/llm)
- [llm](https://github.com/ahyatt/llm) or [gptel](https://github.com/karthink/gptel)
- curl

# Setup

> [!NOTE]
> If you are using [gptel](https://github.com/karthink/gptel) as a backend, please check out this branch(Not recommended!): [gptel](https://github.com/douo/magit-gptcommit/tree/gptel)
`magit-gptcommit` requires either [llm](https://github.com/ahyatt/llm) or [gptel](https://github.com/karthink/gptel). One of these two packages needs to be installed and the customizable variable `magit-gptcommit-backend` needs to be correctly configured.


`magit-gptcommit` depends on [llm](https://github.com/ahyatt/llm). Please read the
## llm
Please read the
[documentation](https://github.com/ahyatt/llm?tab=readme-ov-file#setting-up-providers)
of `llm` for more details on how to set up providers. Debug logging for `llm` can be enabled by setting `llm-log` to `t`.

Expand All @@ -30,6 +29,27 @@ For example, to set up the OpenAI provider, first create an [OpenAI API key](htt

**Recommended**: See [below](#using-auth-source-for-api-keys) how to use Emacs `auth-source` to protect API keys for `llm` providers.

## gptel
Please read the
[documentation](https://github.com/karthink/gptel?tab=readme-ov-file#setup)
of gptel for more configuration details and provide the method to
configure OpenAI here.

Procure an [OpenAI API key](https://platform.openai.com/account/api-keys).

Setup a key:

- Recommend: Storing in ~/.authinfo. By default, “api.openai.com” is
used as HOST and “apikey” as USER.

machine api.openai.com login apikey password TOKEN

- Another: Set `gptel-api-key` to the key.

The backend used by `gptel` and model can be configured using `gptel-menu` before invoking magit-gptcommit related methods.

## Common magit-gptcommit setup

Activate `magit-gptcommit-mode` and open a Magit status buffer, the commit message will be automatically generated when changes are staged. You can run `magit-gptcommit-generate` when visiting a Magit status buffer to generate a commit message manually.

Setup example using [use-package](https://github.com/jwiegley/use-package) and [straight](https://github.com/radian-software/straight.el):
Expand All @@ -42,8 +62,13 @@ Setup example using [use-package](https://github.com/jwiegley/use-package) and [
:bind (:map git-commit-mode-map
("C-c C-g" . magit-gptcommit-commit-accept))
:custom
;; --- if using llm ---
(magit-gptcommit-backend 'llm)
(magit-gptcommit-llm-provider (make-llm-openai :key "OPENAI-KEY"))

;; --- if using gptel ---
(magit-gptcommit-backend 'gptel)

:config
;; Enable magit-gptcommit-mode to watch staged changes and generate commit message automatically in magit status buffer
;; This mode is optional, you can also use `magit-gptcommit-generate' to generate commit message manually
Expand All @@ -68,6 +93,7 @@ Setup example using [use-package](https://github.com/jwiegley/use-package) and [

| **Variable** | Description |
|--------------------------------------------|----------------------------------------------------------------------------------------------|
| `magit-gptcommit-backend` | The backend used by `magit-gptcommit`. Should be either `llm` or `gptel` |
| `magit-gptcommit-prompt` | Prompt. |
| `magit-gptcommit-max-token` | Default 4096, magit-gptcommit will truncate excessive characters based on 1 token = 4 chars |
| `magit-gptcommit-determine-max-token` | Whether to use the llm provider max tokens, used only if `magit-gptcommit-max-token` is nil. |
Expand All @@ -82,6 +108,7 @@ Setup example using [use-package](https://github.com/jwiegley/use-package) and [
Setup an `llm` provider for Google Gemini using [use-package](https://github.com/jwiegley/use-package), [straight](https://github.com/radian-software/straight.el), and Emacs `auth-source`, given that there is an `auth-source` secret stored with the host "generativelanguage.googleapis.com" and the user "apikey".

``` emacs-lisp
;; --- if using llm ---
(use-package llm
:straight t
:init
Expand All @@ -96,10 +123,13 @@ Setup an `llm` provider for Google Gemini using [use-package](https://github.com
:custom
(llm-warn-on-nonfree nil))

;; --- if using gptel ---
;; TODO

;; --- magit-gptcommit config ---
(use-package magit-gptcommit
:straight t
:demand t
:after llm
:custom
(magit-gptcommit-llm-provider llm-gemini-provider)
...)
Expand All @@ -124,6 +154,7 @@ machine generativelanguage.googleapis.com login apikey password <api-key>
# Credit

- [llm](https://github.com/ahyatt/llm) Great project.
- [gptel](https://github.com/karthink/gptel) Great project.
- [gptcommit](https://github.com/zurawiki/gptcommit) Very helpful, Prompt modified from this project.
- [magit-todos](https://github.com/alphapapa/magit-todos) This project has been of great help to me in learning magit development.
- [GPT-Commit](https://github.com/ywkim/gpt-commit): Another Emacs pacakge for a similar purpose.
Loading