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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import (

"gopkg.in/yaml.v3"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/config"
)
```

Expand Down
37 changes: 29 additions & 8 deletions cmd/smart-llama/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"flag"
"fmt"
"log"
"log/slog"
Expand All @@ -9,16 +10,31 @@ import (
"os/signal"
"syscall"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/fvigneault/smart-llama/internal/process"
"github.com/fvigneault/smart-llama/internal/proxy"
"github.com/fvigneault/smart-llama/internal/server"
"github.com/smartfrog/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/process"
"github.com/smartfrog/smart-llama/internal/proxy"
"github.com/smartfrog/smart-llama/internal/server"
)

const defaultConfigPath = "config.yaml"

type App struct {
config *config.Config
log *slog.Logger
models map[string]*config.ModelConfig
configPath string
config *config.Config
log *slog.Logger
models map[string]*config.ModelConfig
}

// resolveConfigPath returns the config path based on priority:
// flagValue > envValue > defaultConfigPath
func resolveConfigPath(flagValue, envValue string) string {
if flagValue != "" {
return flagValue
}
if envValue != "" {
return envValue
}
return defaultConfigPath
}

func NewApp() *App {
Expand All @@ -30,7 +46,7 @@ func NewApp() *App {

func (a *App) loadConfig() error {
loader := config.NewLoader()
cfg, err := loader.LoadConfig("config.yaml")
cfg, err := loader.LoadConfig(a.configPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -98,7 +114,12 @@ func (a *App) run() error {
}

func main() {
configFlag := flag.String("config", "", "path to configuration file")
flag.Parse()

app := NewApp()
app.configPath = resolveConfigPath(*configFlag, os.Getenv("SL_CONFIG"))

if err := app.loadConfig(); err != nil {
log.Fatal(err)
}
Expand Down
34 changes: 34 additions & 0 deletions cmd/smart-llama/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,37 @@ func TestNewApp(t *testing.T) {
t.Fatal("NewApp() returned nil")
}
}

func TestResolveConfigPath(t *testing.T) {
t.Run("flag takes priority over env and default", func(t *testing.T) {
got := resolveConfigPath("/from/flag", "/from/env")
want := "/from/flag"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})

t.Run("env takes priority over default when no flag", func(t *testing.T) {
got := resolveConfigPath("", "/from/env")
want := "/from/env"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})

t.Run("returns default when no flag and no env", func(t *testing.T) {
got := resolveConfigPath("", "")
want := defaultConfigPath
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})

t.Run("flag with empty env uses flag", func(t *testing.T) {
got := resolveConfigPath("/custom/path", "")
want := "/custom/path"
if got != want {
t.Errorf("got %q, want %q", got, want)
}
})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/fvigneault/smart-llama
module github.com/smartfrog/smart-llama

go 1.25.0

Expand Down
2 changes: 1 addition & 1 deletion internal/process/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"syscall"
"time"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/config"
)

// Manager manages the llama-server subprocess lifecycle.
Expand Down
2 changes: 1 addition & 1 deletion internal/process/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/config"
)

func TestNewManager(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"net/http"
"sync"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/fvigneault/smart-llama/internal/proxy"
"github.com/smartfrog/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/proxy"
)

// Server manages the HTTP server.
Expand Down
2 changes: 1 addition & 1 deletion internal/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http/httptest"
"testing"

"github.com/fvigneault/smart-llama/internal/config"
"github.com/smartfrog/smart-llama/internal/config"
)

func TestHandleModelsList(t *testing.T) {
Expand Down