From 3d769e7b92a080fb374f983d5a5fb40a0761bb92 Mon Sep 17 00:00:00 2001 From: GauravJangra9988 Date: Mon, 6 Oct 2025 11:55:36 +0530 Subject: [PATCH 1/3] integrated ollama setup with cli --- cmd/cli/createMsg.go | 8 +----- cmd/cli/llmSetup.go | 62 ++++++++++++++++++++++++++++++------------ cmd/cli/store/store.go | 1 - 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/cmd/cli/createMsg.go b/cmd/cli/createMsg.go index 756e5e1..c3193b9 100644 --- a/cmd/cli/createMsg.go +++ b/cmd/cli/createMsg.go @@ -121,17 +121,11 @@ func CreateCommitMsg () { case "Claude": commitMsg, err = claude.GenerateCommitMessage(config, changes, apiKey) case "Ollama": - url := os.Getenv("OLLAMA_URL") - if url == "" { - url = "http://localhost:11434/api/generate" - } model := os.Getenv("OLLAMA_MODEL") if model == "" { model = "llama3:latest" } - commitMsg, err = ollama.GenerateCommitMessage(config, changes, url, model) - - + commitMsg, err = ollama.GenerateCommitMessage(config, changes, apiKey, model) default: commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey) } diff --git a/cmd/cli/llmSetup.go b/cmd/cli/llmSetup.go index f170c65..1ec5492 100644 --- a/cmd/cli/llmSetup.go +++ b/cmd/cli/llmSetup.go @@ -25,19 +25,30 @@ func SetupLLM() error { var apiKey string // Skip API key prompt for Ollama (local LLM) - if model != "Ollama" { - apiKeyPrompt := promptui.Prompt{ + apiKeyPrompt := promptui.Prompt{ Label: "Enter API Key", Mask: '*', } + + + switch model { + case "Ollama": + urlPrompt := promptui.Prompt{ + Label: "Enter URL", + } + apiKey, err = urlPrompt.Run() + if err != nil { + return fmt.Errorf("failed to read Url: %w", err) + } - apiKey, err = apiKeyPrompt.Run() - if err != nil { + default: + apiKey, err = apiKeyPrompt.Run() + if err != nil { return fmt.Errorf("failed to read API Key: %w", err) } - } else { - apiKey = "" // No API key needed for Ollama - } + + } + LLMConfig := store.LLMProvider{ LLM: model, @@ -68,7 +79,8 @@ func UpdateLLM() error { } models := []string{} - options := []string{"Set Default", "Change API Key", "Delete"} + options1 := []string{"Set Default", "Change API Key", "Delete"} + options2 := []string{"Set Default", "Change URL", "Delete"} for _, p := range SavedModels.LLMProviders { models = append(models, p.LLM) @@ -84,19 +96,33 @@ func UpdateLLM() error { return err } - - prompt = promptui.Select{ + prompt = promptui.Select{ Label: "Select Option", - Items: options, - } + Items: options1, + } + + apiKeyPrompt := promptui.Prompt { + Label: "Enter API Key", + } + + + if model == "Ollama" { + prompt = promptui.Select{ + Label: "Select Option", + Items: options2, + } + + apiKeyPrompt = promptui.Prompt { + Label: "Enter URL", + } + } + + opNo,_,err := prompt.Run() if err != nil { return err } - apiKeyprompt := promptui.Prompt { - Label: "Enter API Key", - } switch opNo { @@ -107,7 +133,7 @@ func UpdateLLM() error { } fmt.Printf("%s set as default", model) case 1: - apiKey, err := apiKeyprompt.Run() + apiKey, err := apiKeyPrompt.Run() if err != nil { return err } @@ -115,7 +141,9 @@ func UpdateLLM() error { if err != nil { return err } - fmt.Printf("%s API Key Updated", model) + event := "API Key" + if model == "Ollama"{event = "URL"} + fmt.Printf("%s %s Updated", model,event) case 2: err := store.DeleteModel(model) if err != nil { diff --git a/cmd/cli/store/store.go b/cmd/cli/store/store.go index 8e1c50f..d60315a 100644 --- a/cmd/cli/store/store.go +++ b/cmd/cli/store/store.go @@ -165,7 +165,6 @@ func DefaultLLMKey() (*LLMProvider, error) { return nil, err } - fmt.Println(len(data)) if len(data) > 2 { err = json.Unmarshal(data, &cfg) if err != nil { From ab8ea293fa0f2f91ed86853fec2c4332e58183bc Mon Sep 17 00:00:00 2001 From: GauravJangra9988 Date: Mon, 6 Oct 2025 14:39:27 +0530 Subject: [PATCH 2/3] integrated ollama setup with cli --- cmd/cli/llmSetup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cli/llmSetup.go b/cmd/cli/llmSetup.go index 1ec5492..545d51c 100644 --- a/cmd/cli/llmSetup.go +++ b/cmd/cli/llmSetup.go @@ -80,7 +80,7 @@ func UpdateLLM() error { models := []string{} options1 := []string{"Set Default", "Change API Key", "Delete"} - options2 := []string{"Set Default", "Change URL", "Delete"} + options2 := []string{"Set Default", "Change URL", "Delete"} //different option for local model for _, p := range SavedModels.LLMProviders { models = append(models, p.LLM) From 8970a7f05490caa6f329c2732f68b9f13cdd3150 Mon Sep 17 00:00:00 2001 From: GauravJangra9988 Date: Mon, 6 Oct 2025 14:44:39 +0530 Subject: [PATCH 3/3] removed getenv for ollama model setup --- cmd/cli/createMsg.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/cli/createMsg.go b/cmd/cli/createMsg.go index c3193b9..25a823a 100644 --- a/cmd/cli/createMsg.go +++ b/cmd/cli/createMsg.go @@ -121,10 +121,8 @@ func CreateCommitMsg () { case "Claude": commitMsg, err = claude.GenerateCommitMessage(config, changes, apiKey) case "Ollama": - model := os.Getenv("OLLAMA_MODEL") - if model == "" { - model = "llama3:latest" - } + model := "llama3:latest" + commitMsg, err = ollama.GenerateCommitMessage(config, changes, apiKey, model) default: commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey)