Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import (
"github.com/spf13/cobra"
)

var (
flagModel string
flagProvider string
)

var chatCmd = &cobra.Command{
Use: "chat <prompt>",
Args: cobra.MinimumNArgs(1),
Expand All @@ -24,6 +29,18 @@ var chatCmd = &cobra.Command{
log.Fatal(err)
}

if flagProvider != "" {
if err := cfg.SetProvider(flagProvider); err != nil {
log.Fatal(err)
}
}

if flagModel != "" {
if err := cfg.SetModel(cfg.AI.Provider, flagModel); err != nil {
log.Fatal(err)
}
}

provider, err := ai.New(cfg)
if err != nil {
log.Fatal(err)
Expand All @@ -44,5 +61,7 @@ var chatCmd = &cobra.Command{
}

func init() {
chatCmd.Flags().StringVarP(&flagModel, "model", "m", "", "AI model to use (e.g. gpt-4o, claude-3-5-sonnet-latest, qwen2.5:8b)")
chatCmd.Flags().StringVarP(&flagProvider, "provider", "p", "", "AI provider to use (e.g. gemini, ollama, groq, openai, anthropic)")
rootCmd.AddCommand(chatCmd)
}
2 changes: 1 addition & 1 deletion cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var setCmd = &cobra.Command{
err = cfg.SetAPIKey(cfg.AI.Provider, value)

case "base_url":
err = cfg.SetBaseURL(cfg.AI.Provider, value)
log.Fatal("base_url cannot be set or changed by the user for any provider")

case "theme":
cfg.SetTheme(value)
Expand Down
10 changes: 1 addition & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@ func (c *Config) SetAPIKey(providerName, apiKey string) error {

// SetBaseURL updates a provider base URL.
func (c *Config) SetBaseURL(providerName, baseURL string) error {
provider, ok := c.Providers[providerName]
if !ok {
return fmt.Errorf("unsupported provider: %s", providerName)
}

provider.BaseURL = baseURL
c.Providers[providerName] = provider

return nil
return fmt.Errorf("base_url cannot be set or changed by the user for any provider")
}

// SetTheme updates the UI theme.
Expand Down
9 changes: 1 addition & 8 deletions internal/providers/anthropic/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package anthropic

import (
"context"
"strings"

"github.com/Nithwin/WindMist/internal/ai"
"github.com/Nithwin/WindMist/internal/config"
Expand All @@ -20,13 +19,7 @@ type Provider struct {

// New creates a new Anthropic provider instance.
func New(cfg config.ProviderConfig) ai.Provider {
baseURL := strings.TrimRight(cfg.BaseURL, "/")
if baseURL == "" {
baseURL = "https://api.anthropic.com/v1"
}
if !strings.HasSuffix(baseURL, "/v1") {
baseURL = baseURL + "/v1"
}
baseURL := "https://api.anthropic.com/v1"

model := cfg.Model
if model == "" {
Expand Down
9 changes: 1 addition & 8 deletions internal/providers/groq/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package groq

import (
"context"
"strings"

"github.com/Nithwin/WindMist/internal/ai"
"github.com/Nithwin/WindMist/internal/config"
Expand All @@ -20,13 +19,7 @@ type Provider struct {

// New creates a new Groq provider instance.
func New(cfg config.ProviderConfig) ai.Provider {
baseURL := strings.TrimRight(cfg.BaseURL, "/")
if baseURL == "" {
baseURL = "https://api.groq.com/openai/v1"
}
if !strings.HasSuffix(baseURL, "/v1") && !strings.HasSuffix(baseURL, "/openai/v1") {
baseURL = baseURL + "/openai/v1"
}
baseURL := "https://api.groq.com/openai/v1"

model := cfg.Model
if model == "" {
Expand Down
9 changes: 1 addition & 8 deletions internal/providers/ollama/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ollama

import (
"context"
"strings"

"github.com/Nithwin/WindMist/internal/ai"
"github.com/Nithwin/WindMist/internal/config"
Expand All @@ -20,13 +19,7 @@ type Provider struct {

// New creates a new Ollama provider instance.
func New(cfg config.ProviderConfig) ai.Provider {
baseURL := strings.TrimRight(cfg.BaseURL, "/")
if baseURL == "" {
baseURL = "http://localhost:11434"
}
if !strings.HasSuffix(baseURL, "/v1") {
baseURL = baseURL + "/v1"
}
baseURL := "http://localhost:11434/v1"

model := cfg.Model
if model == "" {
Expand Down
9 changes: 1 addition & 8 deletions internal/providers/openai/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package openai

import (
"context"
"strings"

"github.com/Nithwin/WindMist/internal/ai"
"github.com/Nithwin/WindMist/internal/config"
Expand All @@ -20,13 +19,7 @@ type Provider struct {

// New creates a new OpenAI provider instance.
func New(cfg config.ProviderConfig) ai.Provider {
baseURL := strings.TrimRight(cfg.BaseURL, "/")
if baseURL == "" {
baseURL = "https://api.openai.com/v1"
}
if !strings.HasSuffix(baseURL, "/v1") {
baseURL = baseURL + "/v1"
}
baseURL := "https://api.openai.com/v1"

model := cfg.Model
if model == "" {
Expand Down
Loading