Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: log loading #47

Merged
merged 6 commits into from
Jun 21, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ permissions:
checks: write
pull-requests: write
packages: write
statuses: write
issues: write

concurrency:
group: build
Expand Down Expand Up @@ -70,6 +72,9 @@ jobs:
make ci
echo "🎉 Builds completed" >> "$GITHUB_STEP_SUMMARY"

# Test
- uses: robherley/go-test-action@v0

- name: Upload artefacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
with:
Expand Down
13 changes: 11 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var defaultConfig = Config{
DefaultSort: "Size",
Columns: []string{"Name", "Size", "Quant", "Family", "Modified", "ID"},
OllamaAPIKey: "",
OllamaAPIURL: os.Getenv("OLLAMA_HOST"),
OllamaAPIURL: getAPIUrl(),
LMStudioFilePaths: "",
LogLevel: "info",
LogFilePath: os.Getenv("HOME") + "/.config/gollama/gollama.log",
Expand All @@ -39,9 +39,18 @@ var defaultConfig = Config{
DockerContainer: "",
}

func getAPIUrl() string {
apiUrl := os.Getenv("OLLAMA_API_URL")
if apiUrl == "" {
apiUrl = "https://localhost:11434"
}
return apiUrl
}

func LoadConfig() (Config, error) {
// Initialize loggers with desired parameters.
if err := logging.Init("debug", "gollama.log"); err != nil {
logFilePath := os.Getenv("HOME") + "/.config/gollama/gollama.log"
if err := logging.Init("debug", logFilePath); err != nil {
fmt.Println("Failed to initialize loggers:", err)
os.Exit(1)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ go 1.22.4

require (
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.4
github.com/charmbracelet/bubbletea v0.26.5
github.com/charmbracelet/lipgloss v0.11.0
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/ollama/ollama v0.1.44
github.com/ollama/ollama v0.1.45
github.com/rs/zerolog v1.33.0
golang.org/x/term v0.21.0
)
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.26.4 h1:2gDkkzLZaTjMl/dQBpNVtnvcCxsh/FCkimep7FC9c40=
github.com/charmbracelet/bubbletea v0.26.4/go.mod h1:P+r+RRA5qtI1DOHNFn0otoNwB4rn+zNAzSj/EXz6xU0=
github.com/charmbracelet/bubbletea v0.26.5 h1:90pqTPElAReb/qQUgSMUresTkfwVr0Wx+zczeHHOgxk=
github.com/charmbracelet/bubbletea v0.26.5/go.mod h1:dz8CWPlfCCGLFbBlTY4N7bjLiyOGDJEnd2Muu7pOWhk=
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/ZqwWWYTG4g=
Expand Down Expand Up @@ -53,6 +55,8 @@ github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
github.com/ollama/ollama v0.1.44 h1:3Htzf/mn0nNn1oBOm3rdnbSfX6dOTpOW0YRnxYTsqbo=
github.com/ollama/ollama v0.1.44/go.mod h1:TvVa25PEZI6M0bosiW1sa2XJGq3Xw/OPlpUAkMEntTU=
github.com/ollama/ollama v0.1.45 h1:kwXM83GKToTnueX5zJHqRvwLy1/zzYw8C0sO60wOKqA=
github.com/ollama/ollama v0.1.45/go.mod h1:TvVa25PEZI6M0bosiW1sa2XJGq3Xw/OPlpUAkMEntTU=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
2 changes: 1 addition & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
ErrorLogger zerolog.Logger
)

func Init(logLevel, logFilePath string) error {
func Init(logLevel string, logFilePath string) error {
// Set default log file path if none is provided
if logFilePath == "" {
homeDir, err := os.UserHomeDir()
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ func main() {
ctx := context.Background()
httpClient := &http.Client{}
url, err := url.Parse(cfg.OllamaAPIURL)

if err != nil {
message := fmt.Sprintf("Error parsing API URL: %v", err)
logging.ErrorLogger.Println(message)
fmt.Println(message)
os.Exit(1)
}

client := api.NewClient(url, httpClient)

resp, err := client.List(ctx)
Expand Down
2 changes: 1 addition & 1 deletion operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func runModel(model string, cfg *config.Config) tea.Cmd {
// if config is set to run in docker container, run the mode using runDocker
if cfg.DockerContainer != "" && cfg.DockerContainer != "false" {
if cfg.DockerContainer != "" && strings.ToLower(cfg.DockerContainer) != "false" {
return runDocker(cfg.DockerContainer, model)
}

Expand Down
26 changes: 18 additions & 8 deletions operations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"os"
"testing"

"github.com/sammcj/gollama/config"
Expand All @@ -13,38 +14,47 @@ func TestRunModel(t *testing.T) {
cfg *config.Config
expectDocker bool
expectError bool
skipInCI bool // Skip this test in CI
}{
{
name: "Run with Docker",
model: "test-model",
cfg: &config.Config{DockerContainer: "test-container"},
expectDocker: true,
expectError: false,
skipInCI: true,
},
{
name: "Run without Docker",
model: "test-model",
cfg: &config.Config{DockerContainer: ""},
expectDocker: false,
expectError: false,
skipInCI: true,
},
{
name: "Run with Docker set to false",
model: "test-model",
cfg: &config.Config{DockerContainer: "false"},
expectDocker: false,
expectError: false,
skipInCI: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := runModel(tt.model, tt.cfg)
if (cmd == nil) != tt.expectError {
t.Errorf("runModel() error = %v, expectError %v", cmd == nil, tt.expectError)
return
}
// Further assertions can be added based on how you want to validate the `tea.Cmd` returned
})
if tt.skipInCI && os.Getenv("CI") != "" || os.Getenv("GITHUB_ACTIONS") != "" {
t.Skip("Skipping test in CI environment")
} else {
t.Run(tt.name, func(t *testing.T) {
cmd := runModel(tt.model, tt.cfg)
if (cmd == nil) != tt.expectError {
t.Errorf("runModel() error = %v, expectError %v", cmd == nil, tt.expectError)
t.Logf("cmd: %v", cmd)
return
}
// Further assertions can be added based on how you want to validate the `tea.Cmd` returned
})
}
}
}
Loading