Skip to content

Commit 18f786f

Browse files
authored
Merge branch 'DFanso:main' into main
2 parents 6145d22 + ea6774b commit 18f786f

4 files changed

Lines changed: 31 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can use **Google Gemini**, **Grok**, **Claude**, **ChatGPT**, or **Ollama**
4949
| `CLAUDE_API_KEY` | Your API key | Required if using Claude |
5050
| `OPENAI_API_KEY` | Your API key | Required if using ChatGPT |
5151
| `OLLAMA_URL` | URL (optional) | Ollama server URL (default: http://localhost:11434/api/generate) |
52-
| `OLLAMA_MODEL` | Model name (optional) | Ollama model to use (default: qwen2:0.5b) |
52+
| `OLLAMA_MODEL` | Model name (optional) | Ollama model to use (default: llama3) |
5353

5454
---
5555

cmd/cli/createMsg.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/dfanso/commit-msg/internal/gemini"
1212
"github.com/dfanso/commit-msg/internal/git"
1313
"github.com/dfanso/commit-msg/internal/grok"
14+
"github.com/dfanso/commit-msg/internal/ollama"
1415
"github.com/dfanso/commit-msg/internal/stats"
1516
"github.com/dfanso/commit-msg/pkg/types"
1617
"github.com/pterm/pterm"
@@ -119,6 +120,17 @@ func CreateCommitMsg () {
119120

120121
case "Claude":
121122
commitMsg, err = claude.GenerateCommitMessage(config, changes, apiKey)
123+
case "Ollama":
124+
url := os.Getenv("OLLAMA_URL")
125+
if url == "" {
126+
url = "http://localhost:11434/api/generate"
127+
}
128+
model := os.Getenv("OLLAMA_MODEL")
129+
if model == "" {
130+
model = "llama3:latest"
131+
}
132+
commitMsg, err = ollama.GenerateCommitMessage(config, changes, url, model)
133+
122134

123135
default:
124136
commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey)

cmd/cli/llmSetup.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func SetupLLM() error {
1313

14-
providers := []string{"OpenAI", "Claude", "Gemini", "Grok"}
14+
providers := []string{"OpenAI", "Claude", "Gemini", "Grok", "Ollama"}
1515
prompt := promptui.Select{
1616
Label: "Select LLM",
1717
Items: providers,
@@ -22,15 +22,21 @@ func SetupLLM() error {
2222
return fmt.Errorf("prompt failed")
2323
}
2424

25-
apiKeyPrompt := promptui.Prompt{
26-
Label: "Enter API Key",
27-
Mask: '*',
28-
29-
}
30-
31-
apiKey, err := apiKeyPrompt.Run()
32-
if err != nil {
33-
return fmt.Errorf("failed to read API Key: %w", err)
25+
var apiKey string
26+
27+
// Skip API key prompt for Ollama (local LLM)
28+
if model != "Ollama" {
29+
apiKeyPrompt := promptui.Prompt{
30+
Label: "Enter API Key",
31+
Mask: '*',
32+
}
33+
34+
apiKey, err = apiKeyPrompt.Run()
35+
if err != nil {
36+
return fmt.Errorf("failed to read API Key: %w", err)
37+
}
38+
} else {
39+
apiKey = "" // No API key needed for Ollama
3440
}
3541

3642
LLMConfig := store.LLMProvider{

cmd/cli/store/store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func DefaultLLMKey() (*LLMProvider, error) {
172172
return nil, err
173173
}
174174
} else {
175-
return nil, errors.New("config file is empty, Please add atlead one LLM Key")
175+
return nil, errors.New("config file is empty, Please add at least one LLM Key")
176176
}
177177

178178

@@ -214,7 +214,7 @@ func ListSavedModels() (*Config, error){
214214
return nil, err
215215
}
216216
} else {
217-
return nil, errors.New("config file is empty, Please add atlead one LLM Key")
217+
return nil, errors.New("config file is empty, Please add at least one LLM Key")
218218
}
219219

220220

0 commit comments

Comments
 (0)