autocommit/README.md

168 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AutoCommit
> 一个智能的 Git 提交助手,使用 LLM 自动生成规范的提交消息并提交暂存的文件。
## ✨ 特性
- **智能生成**:使用大语言模型自动分析代码变更,生成专业、规范的提交消息
- **🔧 高度可配置**:支持多种 LLM 提供商OpenAI 兼容 API
- **🎯 规范遵循**:自动生成符合 [Conventional Commits](https://www.conventionalcommits.org/) 规范的消息
- **⚡ 快速便捷**:一键生成并提交,提升开发效率
- **🔍 安全检查**:内置配置检查和连接测试
- **🎨 美观界面**:使用 Rich 库提供美观的命令行界面
- **🔄 异步支持**:支持异步操作,响应快速
---
## 📦 安装
```bash
git clone <repository-url>
cd autocommit
pip install -e .
```
---
## 🚀 快速开始
### 1. 配置(推荐交互式)
```bash
# 交互式配置向导
autocommit config interactive
# 或直接设置
autocommit config set --api-key "sk-your-api-key" --model "qwen3-14b"
```
### 2. 测试连接
```bash
autocommit check
```
### 3. 使用 AutoCommit
```bash
# 1. 先将文件添加到暂存区
git add .
# 2. 使用 AutoCommit 生成提交消息并提交
autocommit
# 3. 或者仅生成消息,不自动提交(预览模式)
autocommit --dry-run
```
---
## 📖 详细使用说明
### 基本使用流程
```bash
# 完整工作流示例
git add .
autocommit
```
### 命令行选项
```bash
# 显示帮助信息
autocommit --help
# 仅生成消息,不实际提交(预览模式)
autocommit --dry-run
# 指定模型生成
autocommit --model "qwen3-14b"
# 检查工具状态
autocommit check
# 测试消息生成
autocommit check --test
```
---
## ⚙️ 配置管理
```bash
# 显示当前配置
autocommit config show
# 交互式配置向导
autocommit config interactive
# 设置特定配置项
autocommit config set \
--api-key "sk-your-key" \
--base-url "https://your-api-endpoint.com/v1" \
--model "qwen3-14b" \
--timeout 30
# 清除所有配置
autocommit config clear
```
### 配置说明
#### 支持的 LLM 提供商
- OpenAI
- DashScope通义千问
- Ollama
- **其他兼容 OpenAI API 的服务**
#### 配置文件位置
`~/.config/autocommit/config.yaml`
#### 示例配置
```yaml
llm:
api_key: "sk-your-api-key"
base_url: "https://dashscope.aliyuncs.com/compatible-mode/v1"
model: "qwen3-14b"
timeout: 30
max_tokens: 1000
temperature: 0.7
extra_body:
enable_thinking: false
system_prompt: |
你是一个专业开发者,请根据以下 git diff 生成一条符合 Conventional Commits 规范的中文 commit message。
要求50字以内不要解释不要引号只输出 message 本身。
diff:
auto_save: true
```
> 💡 示例代码变更:
> ```python
> def hello_world():
> - print("Hello, World!")
> + print("Hello, OpenAI!")
> ```
> 生成的提交消息:`feat: update greeting message`
---
## 🔧 高级功能
### 自定义提示词
你可以修改系统提示词以适应特定需求:
```bash
autocommit config set --system-prompt "你是一个前端开发者,请根据代码变更生成提交消息,重点描述 UI 变化。"
```
### 异步模式
对于大量文件或复杂的代码库,工具会自动使用异步模式提高性能。
### 多语言支持
通过修改系统提示词,可以支持多种语言的提交消息(如英文、中文、日文等)。