Skip to content

Commit c48bb04

Browse files
committed
docs 📚 (README): update documentation for AI-generated commit messages
Signed-off-by: Zine Moualhi 🇵🇸 <zmoualhi@outlook.com>
1 parent 33def66 commit c48bb04

File tree

1 file changed

+284
-4
lines changed

1 file changed

+284
-4
lines changed

README.md

Lines changed: 284 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ for selecting the type of change, scope, and description of your commit message.
2828
- Predefined commit types with corresponding emojis.
2929
- Customizable commit types and scopes through a JSON configuration file.
3030
- Supports Git out of the box
31-
- AI generated commit messages using [phind](https://phind.com) without needing API keys or tokens (possibility to use your own ai models will be planned).
31+
- AI generated commit messages using multiple providers:
32+
- **Phind** (default, no API key required)
33+
- **Groq** (fast inference, requires API key)
34+
- **OpenRouter** (access to multiple models, requires API key)
35+
- Intelligent large diff handling with automatic summarization
36+
- No rate limiting issues with smart diff compression
3237

3338
## Install
3439

@@ -109,20 +114,295 @@ To use the check command, add the following to your pre-commit hook in your git
109114
110115
## Draft command
111116
112-
The `draft` command allows you to generate a commit message for staged changes using an AI provider.
117+
The `draft` command allows you to generate a commit message for staged changes using various AI providers.
113118

114119
```sh
115120
goji draft
116121
```
117122

118-
This command connects to an AI provider (e.g., Phind) to generate a commit message based on your staged changes.
123+
This command connects to an AI provider to generate a commit message based on your staged changes.
119124

120-
Options for `draft` command:
125+
### Quick Start
126+
127+
**1. Set up environment variables (if using Groq or OpenRouter):**
128+
129+
```sh
130+
# For Groq
131+
export GROQ_API_KEY="your-groq-api-key"
132+
133+
# For OpenRouter
134+
export OPENROUTER_API_KEY="your-openrouter-api-key"
135+
136+
# For Phind (no setup needed)
137+
```
138+
139+
**2. Generate and commit:**
140+
141+
```sh
142+
git add .
143+
goji draft --commit
144+
```
145+
146+
### Basic Usage
147+
148+
```sh
149+
# Generate a commit message (interactive)
150+
goji draft
151+
152+
# Generate and commit directly
153+
goji draft --commit
154+
155+
# Generate with detailed body
156+
goji draft --body
157+
158+
# Generate and commit with detailed body
159+
goji draft --body --commit
160+
```
161+
162+
### Command Options
121163

122164
- `-c`, `--commit`: Commit the generated message directly.
165+
- `-b`, `--body`: Generate a detailed commit message with body.
123166
- `-t`, `--type`: Override the commit type (e.g., feat, fix, docs).
124167
- `-s`, `--scope`: Override the commit scope (e.g., api, ui, core).
125168

169+
### AI Providers
170+
171+
Goji supports multiple AI providers for generating commit messages. Configure your preferred provider in the `.goji.json` file:
172+
173+
#### 1. Phind (Default - No API Key Required)
174+
175+
Phind is the default provider and doesn't require any API keys.
176+
177+
```json
178+
{
179+
"aiprovider": "phind",
180+
"aichoices": {
181+
"phind": {
182+
"model": "Phind-70B"
183+
}
184+
}
185+
}
186+
```
187+
188+
#### 2. Groq
189+
190+
Fast inference with various models. Requires a Groq API key.
191+
192+
**Setup:**
193+
194+
```sh
195+
export GROQ_API_KEY="your-groq-api-key"
196+
```
197+
198+
**Configuration:**
199+
200+
```json
201+
{
202+
"aiprovider": "groq",
203+
"aichoices": {
204+
"groq": {
205+
"model": "mixtral-8x7b-32768"
206+
}
207+
}
208+
}
209+
```
210+
211+
**Available Models:**
212+
213+
- `mixtral-8x7b-32768` (default)
214+
- `llama2-70b-4096`
215+
- `llama2-13b-chat`
216+
- `gemma-7b-it`
217+
218+
#### 3. OpenRouter
219+
220+
Access to multiple AI models through a single API. Requires an OpenRouter API key.
221+
222+
**Setup:**
223+
224+
```sh
225+
export OPENROUTER_API_KEY="your-openrouter-api-key"
226+
```
227+
228+
**Configuration:**
229+
230+
```json
231+
{
232+
"aiprovider": "openrouter",
233+
"aichoices": {
234+
"openrouter": {
235+
"model": "anthropic/claude-3.5-sonnet"
236+
}
237+
}
238+
}
239+
```
240+
241+
**Available Models:**
242+
243+
- `anthropic/claude-3.5-sonnet` (default)
244+
- `openai/gpt-4o`
245+
- `openai/gpt-4o-mini`
246+
- `meta-llama/llama-3.1-405b-instruct`
247+
- `google/gemini-pro-1.5`
248+
249+
### Large Diff Handling
250+
251+
Goji automatically handles large diffs using intelligent summarization:
252+
253+
- **Small diffs** (<20k chars): Processed normally
254+
- **Large diffs** (>20k chars): Automatically summarized to key changes only
255+
- **Smart compression**: Reduces large diffs by 90%+ while preserving important context
256+
- **No rate limits**: Single API call prevents token limit issues
257+
258+
### Examples
259+
260+
**Basic commit generation:**
261+
262+
```sh
263+
# Stage your changes
264+
git add .
265+
266+
# Generate commit message
267+
goji draft
268+
269+
# Generate and commit directly
270+
goji draft --commit
271+
```
272+
273+
**Detailed commit with body:**
274+
275+
```sh
276+
# Generate detailed commit with body
277+
goji draft --body --commit
278+
```
279+
280+
**Override type and scope:**
281+
282+
```sh
283+
# Force a specific type and scope
284+
goji draft --type feat --scope api --commit
285+
```
286+
287+
**Using different AI providers:**
288+
289+
```sh
290+
# Switch to Groq (requires GROQ_API_KEY)
291+
goji draft --commit
292+
293+
# Switch to OpenRouter (requires OPENROUTER_API_KEY)
294+
goji draft --commit
295+
```
296+
297+
### Configuration
298+
299+
Update your `.goji.json` to configure AI providers:
300+
301+
```json
302+
{
303+
"aiprovider": "groq",
304+
"aichoices": {
305+
"phind": {
306+
"model": "Phind-70B"
307+
},
308+
"groq": {
309+
"model": "mixtral-8x7b-32768"
310+
},
311+
"openrouter": {
312+
"model": "anthropic/claude-3.5-sonnet"
313+
}
314+
}
315+
}
316+
```
317+
318+
### Environment Variables
319+
320+
Goji uses environment variables to authenticate with AI providers. Set these in your shell profile (`.bashrc`, `.zshrc`, etc.) or export them before running commands.
321+
322+
#### Required Environment Variables
323+
324+
| Provider | Environment Variable | Required | Description |
325+
|----------|---------------------|----------|-------------|
326+
| **Phind** | None | ❌ | Works out of the box |
327+
| **Groq** | `GROQ_API_KEY` | ✅ | Get from [Groq Console](https://console.groq.com) |
328+
| **OpenRouter** | `OPENROUTER_API_KEY` | ✅ | Get from [OpenRouter](https://openrouter.ai) |
329+
330+
**For Groq:**
331+
332+
```sh
333+
export GROQ_API_KEY="your-groq-api-key"
334+
```
335+
336+
**For OpenRouter:**
337+
338+
```sh
339+
export OPENROUTER_API_KEY="your-openrouter-api-key"
340+
```
341+
342+
**For Phind:**
343+
344+
```sh
345+
# No environment variables required - works out of the box
346+
```
347+
348+
#### Setting Environment Variables
349+
350+
**Temporary (current session only):**
351+
352+
```sh
353+
export GROQ_API_KEY="your-api-key"
354+
goji draft --commit
355+
```
356+
357+
**Permanent (add to shell profile):**
358+
359+
```sh
360+
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile
361+
echo 'export GROQ_API_KEY="your-api-key"' >> ~/.bashrc
362+
source ~/.bashrc
363+
```
364+
365+
**Using .env files (if supported by your shell):**
366+
367+
```sh
368+
# Create .env file in your project root
369+
echo "GROQ_API_KEY=your-api-key" > .env
370+
```
371+
372+
#### Verifying Environment Variables
373+
374+
Check if your environment variables are set:
375+
376+
```sh
377+
echo $GROQ_API_KEY
378+
echo $OPENROUTER_API_KEY
379+
```
380+
381+
### Troubleshooting
382+
383+
**Rate limiting issues:**
384+
385+
- Goji automatically handles large diffs with smart summarization
386+
- No need to worry about token limits or rate limiting
387+
388+
**API key issues:**
389+
390+
- Ensure your API key is set in the environment
391+
- Check that the provider is correctly configured in `.goji.json`
392+
- Verify environment variables with `echo $VARIABLE_NAME`
393+
394+
**Large diff processing:**
395+
396+
- Goji will show: `🔍 Large diff detected: X chars, using aggressive summarization`
397+
- Summary shows compression: `📊 Summarized to Y chars (Z% reduction)`
398+
399+
**Common environment variable issues:**
400+
401+
- **Variable not found**: Make sure to export the variable in your current shell session
402+
- **Wrong variable name**: Check spelling (GROQ_API_KEY, not GROQ_KEY)
403+
- **Shell restart needed**: Some shells require restarting after adding to profile
404+
- **Case sensitivity**: Environment variable names are case-sensitive
405+
126406
## Customization
127407

128408
By default `goji` comes ready to run out of the box and you can initialize a config file with commands. _For now customization is in the works (?)_

0 commit comments

Comments
 (0)