summaryrefslogtreecommitdiff
path: root/internal/cli/llm.go
blob: 04fe9027b365232ee7171746e9234be7342aa95e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cli

import (
	"log/slog"
	"net/http"
	"time"

	"github.com/thepeterstone/claudomator/internal/config"
	"github.com/thepeterstone/claudomator/internal/llm"
)

// buildLocalLLMClient returns an *llm.Client when a local model endpoint is
// configured. Returns nil when LocalModel.Endpoint is empty so callers can
// gate on `if c != nil` to skip registering LocalRunner / using the LLM
// classifier path.
func buildLocalLLMClient(cfg config.LocalModel, logger *slog.Logger) *llm.Client {
	if cfg.Endpoint == "" {
		return nil
	}
	timeout := 60 * time.Second
	if cfg.TimeoutSeconds > 0 {
		timeout = time.Duration(cfg.TimeoutSeconds) * time.Second
	}
	return &llm.Client{
		Endpoint:   cfg.Endpoint,
		Model:      cfg.Model,
		APIKey:     cfg.APIKey,
		HTTPClient: &http.Client{Timeout: timeout},
		Logger:     logger,
	}
}