VariantConst
280 字
1 分钟
aicommit2 生成 commit message

自动写 commit message 的开源应用有很多,原理是把 git diff 的内容作为 prompt 提交给 llm 生成。在一众只支持 OpenAI API 等可数个模型的项目中,我找到了 aicommit2,它支持自定义模型接口,因此可以魔改成其他任意的 API 提供商。

官方演示效果如下

Aicommit2_demo.gif

本文章以 deepseek-chat 为例,其接口完全兼容 OpenAI 的格式,同时国内可用、价格便宜。

预先要求#

  1. 首先前往 DeepSeek 开放平台-API keys 生成 sk- 开头的 API key。

  2. 安装 node v18+:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
    nvm install 18
    nvm use 18

配置 aicommit2#

npm install -g aicommit2
aicommit2 config set OPENAI_KEY=<deepseek api key>
aicommit2 config set OPENAI_MODEL=deepseek-chat
aicommit2 config set OPENAI_URL=https://api.deepseek.com

使用#

可以先 stage 文件,再使用 aicommit2,例如

git add <files...>
aicommit2

更简单的方式是二合一

aicommit2 --all # or -a

如果对输出内容不满意,可以自定义模型调用时的 prompt

aicommit2 config set prompt=<自定义prompt>

例如我自己用的 prompt 是

aicommit2 config set prompt="Generate a short commit message according to the given git diff information. Should be about 10 words. Do not list change for each file, give a general summary in one single sentence."
aicommit2 生成 commit message
https://blog.variantconst.com/posts/aicommit2-deepseek/
作者
VariantConst
发布于
2024-06-28
许可协议
CC BY-NC-SA 4.0