Skip to content

Commit 979ae95

Browse files
added ollama integration with the CLI
1 parent 26bac47 commit 979ae95

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

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)