Skip to content

Commit ea6774b

Browse files
authored
Merge pull request #62 from vinyas-bharadwaj/main
Added ollama integration for the CLI
2 parents c7b54fd + 3980ebf commit ea6774b

3 files changed

Lines changed: 29 additions & 11 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
@@ -12,6 +12,7 @@ import (
1212
"github.com/dfanso/commit-msg/internal/gemini"
1313
"github.com/dfanso/commit-msg/internal/git"
1414
"github.com/dfanso/commit-msg/internal/grok"
15+
"github.com/dfanso/commit-msg/internal/ollama"
1516
"github.com/dfanso/commit-msg/internal/stats"
1617
"github.com/dfanso/commit-msg/pkg/types"
1718
"github.com/pterm/pterm"
@@ -106,6 +107,17 @@ func CreateCommitMsg () {
106107

107108
case "Claude":
108109
commitMsg, err = claude.GenerateCommitMessage(config, changes, apiKey)
110+
case "Ollama":
111+
url := os.Getenv("OLLAMA_URL")
112+
if url == "" {
113+
url = "http://localhost:11434/api/generate"
114+
}
115+
model := os.Getenv("OLLAMA_MODEL")
116+
if model == "" {
117+
model = "llama3:latest"
118+
}
119+
commitMsg, err = ollama.GenerateCommitMessage(config, changes, url, model)
120+
109121

110122
default:
111123
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{

0 commit comments

Comments
 (0)