Show HN: Cocommit - 一个 Git Commit 的 AI 助手
Cocommit 是一个命令行工具,它与你的 HEAD commit 协同工作,并利用你选择的 LLM 来提高 commit 质量。
License
MIT license 28 stars 1 fork Branches Tags Activity
Cocommit:你的 Git 助手
Cocommit 是一个命令行工具,它与你的 HEAD commit 协同工作,并利用你选择的 LLM 来提高 commit 质量。
一个好的 commit 包含多个要素,但至少应该有一个精心编写的 commit message。Cocommit 分析上一次(HEAD)commit 的 message,并提出改进建议,突出优点和需要改进的地方。
Cocommit v2 目前正在开发中,并将引入许多新功能 - 详见 v2 documentation。
Cocommit 利用 LangChain 作为一个抽象层来访问各种 Large Language Models (LLMs)。
为什么使用 Cocommit?
- 与你选择的 LLM 协同工作
- 为构建定制的 AI 驱动的工具提供了一个简单的基础
- 轻松集成到你的开发工作流程中
- 允许自定义 LLM 体验以适应你的项目需求
目录
Example CLI Session
Session Start
git add .
git commit
cocommit -s bedrock-claude37
Execution Output
Calling with: --model_provider bedrock --model us.anthropic.claude-3-7-sonnet-20250219-v1:0 --region_name us-east-1
Calling LLM....
Done in 9.6 seconds.
About your commit:
This is a good quality commit message that follows most best practices. It has a clear, concise title in imperative mood and a brief explanation of why the change was made.
Strengths:
- Concise first line under 80 characters
- Uses imperative mood correctly ("Add" not "Added")
- Provides context in the description about why the change was made
- Clearly specifies what was changed
- Follows proper structure with title, blank line, and description
Improvements:
- The description could be slightly more specific about which Python versions are now supported
********** Proposed Git Message: ********************
Add Python version classifiers to project metadata
This change lists supported Python versions for better visibility on PyPI.
****************************************************
Fixes:
- Consider specifying which Python versions are now supported in the description for more detail
Amend the commit message? [Y/n]: y
********** Previous Message **********
Add Python version classifiers metadata
Lists supported Python versions for PyPI.
**************************************
Amend ... done!
Installation
要安装 Cocommit,运行:
pip install cocommit
Installing from Source
你也可以从源代码安装 Cocommit,这样可以进行自定义。有关详细信息,请参阅 Contributing Guide。
Handling on-demand Dependencies
当调用特定的 LLM 时,你可能会遇到这样的消息:
cocommit --model llama3-8b-8192 --model_provider groq
Unable to import langchain_groq. Please install with `pip install -U langchain-groq`
要解决这个问题,执行建议的 pip install
命令。由于 Cocommit 支持各种 LLM,因此依赖项仅在需要时才安装。
Usage
Cocommit 通过 LangChain 提供的抽象层与 Large Language Models (LLMs) 交互。这允许你使用任何由 LangChain 的 init_chat_model
function 支持的 LLM 提供商。
Example: Using OpenAI
要使用 OpenAI,将你的 API 密钥设置为 OPENAI_API_KEY
环境变量。或者,你可以使用 --api_key <your key>
选项通过命令行提供密钥:
cocommit --model_provider openai --model gpt-4o
注意:首次运行时,你可能需要通过运行 pip install -U langchain-openai
来安装其他依赖项。
Simplifying OpenAI Usage with Shortcuts
Cocommit 为常见的 LLM 提供商和模型提供了快捷方式,允许你避免手动指定每个参数。
确保你选择的 LLM 提供商已获得授权(例如,OpenAI API 密钥或 AWS 凭证)。
运行:
cocommit -s NAME
例如,如果设置了 OPENAI_API_KEY:
cocommit -s gpt4o
此命令等效于上面的完整 OpenAI GPT-4o 示例。
Example: Using Claude 3.7 on Bedrock
在使用 Amazon Bedrock 之前,请确保:
- Claude 3.7 模型已在你的 AWS 账户(区域:
us-east-1
)中启用。 - 你具有访问该模型的有效凭据(通常在
~/.aws/credentials
中配置或通过环境变量配置;有关详细信息,请参阅 AWS 文档)。
要分析和增强 Git 仓库中最后一条 commit 信息,请运行:
cocommit --model_provider bedrock --model us.anthropic.claude-3-7-sonnet-20250219-v1:0 --region us-east-1
为了简化未来使用的执行,将上述命令保存在 shell 脚本中。
Simplifying Bedrock Claude 3.7 Usage with Shortcuts
如果配置了 AWS 凭证并且在 us-east-1 中启用了 Claude 3.7,请运行:
cocommit -s bedrock-claude37
此命令等效于之前的 Bedrock 示例。
Viewing Available Shortcuts
要查看所有可用的快捷方式,请运行:
cocommit --show-shortcuts
如果缺少你需要的快捷方式,请考虑贡献!有关详细信息,请参阅 Contributing Guide。
Using Other LLMs
Cocommit 利用 LangChain 的 init_chat_model
函数来调用不同的 LLM。命令行参数直接映射到它的参数。
--model
参数对应于init_chat_model
中的model
参数。 它是 LangChain 文档中的第一个位置参数。- 其他命令行参数直接传递给
init_chat_model
(确保在 LangChain 文档需要时使用_
而不是-
)。
推荐用法: 始终明确指定 --model
和 --model_provider
,除非使用快捷方式。
- init_chat_model documentation
- models (某些示例演示了如何使用 init_chat_model 及其必需的参数)
Useful CLI Options
Cocommit 支持调试功能,包括:
- 查看原始 LLM prompt
- 显示原始 LLM 响应
要浏览可用的选项,请运行:
cocommit --help
Contributing
感谢你的贡献!如果你想开始,请查看 contributing guidelines。
License
本项目采用 MIT License 许可。