gptel-magitのコミットメッセージを日本語にしたい
以下のコードをコンフィグに入れよう。
(setq gptel-magit-commit-prompt
(concat gptel-magit-prompt-conventional-commits "\n\nコメントは日本語で出力すること"))
説明
gptel-magit はmagitでコミットするときにgptelを介してLLMにコミットメッセージを生成させるパッケージだ。
特に設定もなくインストールするだけで良い感じでコミットメッセージを生成してくれるが、英語だ。これを日本語で生成させようと言うのが本エントリーの目的だ。
gptelにコミットメッセージを作るよう指示するプロンプトは gptel-magit-commit-prompt に設定するが、デフォルトではgptel-magit-prompt-conventional-commitsの内容がセットされている。引用すると以下の通り。
You are an expert at writing Git commits. Your job is to write a short clear commit message that summarizes the changes.
The commit message should be structured as follows:
<type>(<optional scope>): <description>
[optional body]
- Commits MUST be prefixed with a type, which consists of one of the followings words: build, chore, ci, docs, feat, fix, perf, refactor, style, test
- The type feat MUST be used when a commit adds a new feature
- The type fix MUST be used when a commit represents a bug fix
- An optional scope MAY be provided after a type. A scope is a phrase describing a section of the codebase enclosed in parenthesis, e.g., fix(parser):
- A description MUST immediately follow the type/scope prefix. The description is a short description of the code changes, e.g., fix: array parsing issue when multiple spaces were contained in string.
- Try to limit the whole subject line to 60 characters
- Capitalize the subject line
- Do not end the subject line with any punctuation
- A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
- Use the imperative mood in the subject line
- Keep the body short and concise (omit it entirely if not useful)"
"A prompt adapted from Conventional Commits (https://www.conventionalcommits.org/en/v1.0.0/).
これの最後に「コメントは日本語で出力すること」と入れれば日本語でコメントを出力するようになる。それをやっているのが冒頭のsetq文というわけである。