Skip to content

Commit 5243435

Browse files
committed
Added AI Commit Blueprint to generate concise commit messages based on git diffs, updated documentation, and included a demo app with Streamlit for user interaction and commit message generation.
1 parent 97c69c9 commit 5243435

File tree

14 files changed

+713
-32
lines changed

14 files changed

+713
-32
lines changed

README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,80 @@
99
</picture>
1010
</p>
1111

12-
This blueprint guides you to ...
12+
# AI Commit
13+
14+
This blueprint guides you to easily generate AI-powered git commit messages based on your code changes. It uses local LLMs via Jan AI or Ollama to analyze git diffs and suggest concise, relevant commit messages.
1315

1416
📘 To explore this project further and discover other Blueprints, visit the [**Blueprints Hub**](https://developer-hub.mozilla.ai/).
1517

16-
👉 📖 For more detailed guidance on using this project, please visit our [**Docs here**](https://mozilla-ai.github.io/Blueprint-template/)
18+
👉 📖 For more detailed guidance on using this project, please visit our [**Docs here**](https://mozilla-ai.github.io/ai-commit/)
1719

1820
### Built with
21+
1922
- Python 3.10+
20-
- Open-Source Tool 1
21-
- Open-Source Tool 2
22-
- ...
23+
- [Jan AI](https://jan.ai) for a user-friendly local AI experience
24+
- Open-source LLMs via [Ollama](https://ollama.ai) as an alternative
25+
- fzf for terminal UI
2326

2427
## Quick-start
2528

29+
1. Make sure you have Git, Python 3.10+, and pip installed
30+
2. Install the package:
31+
```bash
32+
pip install ai-commit
33+
```
34+
3. Choose one of the following local inference options:
35+
36+
**Option 1: Jan AI (Default)**
37+
38+
- Install [Jan AI](https://jan.ai) and download a model (like Llama 3.1) through its interface
39+
- Start the Jan AI application and ensure it's running
40+
41+
**Option 2: Ollama**
42+
43+
- Install [Ollama](https://ollama.ai) and pull a model:
44+
45+
```bash
46+
ollama pull llama3.1
47+
```
48+
49+
4. Make changes to your git repo and run:
50+
51+
```bash
52+
ai-commit
53+
```
54+
55+
For Ollama, use:
56+
57+
```bash
58+
ai-commit --ollama
59+
```
2660

2761
## How it Works
2862

63+
1. The tool extracts your git diff (staged changes, or unstaged if no staged changes)
64+
2. Sends the diff to an AI model with a prompt to generate concise commit messages
65+
3. Presents you with message suggestions in a terminal UI using fzf
66+
4. After selecting a message, commits your changes with the selected message
2967

3068
## Pre-requisites
3169

3270
- **System requirements**:
71+
3372
- OS: Windows, macOS, or Linux
3473
- Python 3.10 or higher
35-
- Minimum RAM:
36-
- Disk space:
74+
- Git
75+
- fzf (for terminal UI)
76+
- Jan AI or Ollama for local inference
3777

3878
- **Dependencies**:
3979
- Dependencies listed in `pyproject.toml`
4080

41-
4281
## Troubleshooting
4382

83+
- If you get `fzf: command not found`, install fzf: [fzf installation guide](https://github.com/junegunn/fzf#installation)
84+
- For Jan AI issues, ensure the Jan AI application is running
85+
- For Ollama issues, ensure the Ollama service is running and your model is pulled
4486

4587
## License
4688

demo/app.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,54 @@
1+
"""Demo application for AI Commit Blueprint."""
2+
13
import streamlit as st
4+
from blueprint.commit_generator import generate_commit_messages
5+
6+
# Set page config
7+
st.set_page_config(
8+
page_title="AI Commit Message Generator",
9+
page_icon="✅",
10+
layout="wide",
11+
)
12+
13+
# Add title and description
14+
st.title("AI Commit Message Generator")
15+
st.subheader("Generate commit messages with AI")
16+
17+
# Add sidebar with options
18+
st.sidebar.title("Settings")
19+
service_type = st.sidebar.radio("Select AI Service", ["ollama", "groq"])
20+
max_chars = st.sidebar.slider("Max Characters", 20, 150, 75)
21+
ollama_model = st.sidebar.text_input("Ollama Model", "llama3.1")
22+
groq_model = st.sidebar.text_input("Groq Model", "llama-3.1-70b-versatile")
23+
24+
# Main content
25+
git_diff = st.text_area("Paste your git diff here:", height=300)
226

3-
from blueprint.hello import hello
27+
# Generate button
28+
if st.button("Generate Commit Messages"):
29+
if git_diff:
30+
with st.spinner("Generating commit messages..."):
31+
try:
32+
commit_messages = generate_commit_messages(
33+
diff=git_diff,
34+
max_chars=max_chars,
35+
service_type=service_type,
36+
ollama_model=ollama_model,
37+
groq_model=groq_model,
38+
)
439

5-
st.title("Blueprint Demo")
40+
# Display results
41+
st.success("Generated Commit Messages:")
42+
for i, message in enumerate(commit_messages, 1):
43+
st.markdown(f"**Option {i}:** {message}")
644

7-
st.write(hello())
45+
# Add a copy button for each message
46+
if st.button(f"Use Message {i}", key=f"use_{i}"):
47+
st.code(message)
48+
st.info(
49+
"Copy the message above and use it in your git commit command"
50+
)
51+
except Exception as e:
52+
st.error(f"Error generating commit messages: {e}")
53+
else:
54+
st.warning("Please paste a git diff first.")

demo/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ stopRunningProcess() {
2020

2121
trap stopRunningProcess EXIT TERM
2222

23-
streamlit run ${HOME}/document-to-podcast/demo/app.py &
23+
# Add streamlit to dependencies for the demo
24+
pip install streamlit
25+
26+
streamlit run ${HOME}/blueprint/demo/app.py &
2427
APP_ID=${!}
2528

2629
wait ${APP_ID}

docs/api.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
# API Reference
22

3-
"::: blueprint.hello"
3+
## AI Service Module
4+
5+
::: blueprint.ai_service
6+
7+
## Commit Generator Module
8+
9+
::: blueprint.commit_generator
10+
11+
## CLI Module
12+
13+
::: blueprint.cli

docs/customization.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,38 @@ This Blueprint is designed to be flexible and easily adaptable to your specific
66

77
## 🧠 **Changing the Model**
88

9+
You can customize the AI models used by AI Commit:
910

11+
### Jan AI Models (Default)
1012

11-
## 📝 **Modifying the system Prompt**
13+
Set your preferred Jan AI model using the environment variable:
1214

15+
```bash
16+
export JAN_MODEL="llama 3.1" # or any other model you've downloaded
17+
```
1318

19+
### Ollama Models
1420

15-
## 💡 Other Customization Ideas
21+
Set your preferred Ollama model using the environment variable:
22+
23+
```bash
24+
export OLLAMA_MODEL="llama3.1" # or any other model you've pulled
25+
```
26+
27+
## 📝 **Modifying the System Prompt**
1628

17-
- other ideas..
29+
You can customize the prompt sent to the AI models by modifying the `generate_commit_messages` function in the `commit_generator.py` file. This allows you to:
30+
31+
- Change the number of commit messages generated
32+
- Adjust the style or format of the messages
33+
- Add specific guidelines for your team's commit message standards
34+
35+
## 💡 Other Customization Ideas
1836

37+
- Add support for additional AI providers
38+
- Implement commit message templates
39+
- Add integration with commit hooks
40+
- Create organization-specific formatting rules
1941

2042
## 🤝 **Contributing to the Blueprint**
2143

docs/getting-started.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,96 @@
1+
# Getting Started with AI Commit
2+
13
Get started with this Blueprint using one of the options below:
24

35
---
46

5-
### **Option 1:**
7+
## Installation
8+
9+
### Prerequisites
10+
11+
Before you begin, make sure you have:
12+
13+
1. **Python 3.10 or higher** installed
14+
2. **Git** installed and configured
15+
3. **fzf** installed for the terminal UI (see [installation guide](https://github.com/junegunn/fzf#installation))
16+
4. Either:
17+
- **Jan AI** installed for local inference ([install guide](https://jan.ai/))
18+
- Or **Ollama** as an alternative local inference option ([install guide](https://ollama.ai/download))
19+
20+
### Install from PyPI
21+
22+
The easiest way to install AI Commit is via pip:
23+
24+
```bash
25+
pip install ai-commit
26+
```
27+
28+
### Install from Source
29+
30+
Alternatively, you can install from source:
31+
32+
```bash
33+
git clone https://github.com/mozilla-ai/ai-commit.git
34+
cd ai-commit
35+
pip install -e .
36+
```
37+
38+
## Setup
39+
40+
### For Inference with Jan AI (Default)
41+
42+
1. Install and launch Jan AI from [jan.ai](https://jan.ai/)
43+
2. Download a model (like llama 3.1) through the Jan AI interface
44+
3. Ensure the Jan AI application is running
45+
4. (Optional) Set a custom model:
46+
```bash
47+
export JAN_MODEL="your-preferred-model"
48+
```
49+
50+
### For Inference with Ollama
51+
52+
1. Start the Ollama service
53+
2. Pull a model (we recommend llama3.1):
54+
```bash
55+
ollama pull llama3.1
56+
```
57+
3. (Optional) Set a custom model:
58+
```bash
59+
export OLLAMA_MODEL="your-preferred-model"
60+
```
61+
62+
## Usage
63+
64+
### Basic Usage
65+
66+
1. Make changes to your files in a git repository
67+
2. Run:
68+
```bash
69+
ai-commit
70+
```
71+
3. Select one of the generated commit messages using the arrow keys or number keys
72+
4. Press Enter to commit with the selected message, or Esc to cancel
73+
74+
### Advanced Options
75+
76+
```bash
77+
# Use Ollama instead of Jan AI
78+
ai-commit --ollama
79+
80+
# Show performance analytics
81+
ai-commit --analytics
82+
83+
# Use vim-style navigation in fzf
84+
ai-commit --vim
85+
86+
# Use number selection for messages
87+
ai-commit --num
688

89+
# Set the maximum characters for commit messages
90+
ai-commit --max_chars 100
91+
```
792

93+
## What's Next?
894

9-
### **Option 2:**
95+
- See the [Step-by-Step Guide](step-by-step-guide.md) to understand how AI Commit works
96+
- Learn about [customization options](customization.md) to tailor it to your needs

docs/index.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,37 @@ Blueprints are customizable workflows that help developers build AI applications
55
These docs are your companion to mastering this Blueprint.
66

77
### Built with
8+
89
- Python 3.10+
910
- Tool 1
1011
- Tool 2
1112

12-
1313
---
1414

1515
### 🚀 **Get Started Quickly**
16+
1617
#### _Start building the Blueprint in minutes:_
18+
1719
- **[Getting Started](getting-started.md):** Quick setup and installation instructions.
1820

1921
### 🔍 **Understand the System**
22+
2023
#### _Dive deeper into how the Blueprint works:_
24+
2125
- **[Step-by-Step Guide](step-by-step-guide.md):** A detailed breakdown of the system’s design and workflow.
2226
- **[API Reference](api.md):** Explore the technical details of the core modules.
2327

2428
### 🎨 **Make It Yours**
29+
2530
#### _Customize the Blueprint to fit your needs:_
31+
2632
- **[Customization Guide](customization.md):** Tailor project parameters to fit your needs
2733

2834
### 🌟 **Join the Community**
35+
2936
#### _Help shape the future of Blueprints:_
30-
- **[Future Features & Contributions](future-features-contributions.md):** Learn about exciting upcoming features and how to contribute to the project.
3137

38+
- **[Future Features & Contributions](future-features-contributions.md):** Learn about exciting upcoming features and how to contribute to the project.
3239

3340
Have more questions? Reach out to us on Discord and we'll see how we can help:
3441

0 commit comments

Comments
 (0)