Skip to content

Commit 0669894

Browse files
committed
use "copilot" as default only if it is installed
1 parent 5e51a37 commit 0669894

File tree

5 files changed

+27
-10
lines changed

5 files changed

+27
-10
lines changed

config/default.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ package config
33
import (
44
"github.com/rainu/ask-mai/config/expression"
55
"github.com/rainu/ask-mai/config/llm"
6+
"github.com/rainu/ask-mai/llms"
67
"github.com/tmc/langchaingo/llms/openai"
78
"github.com/wailsapp/wails/v2/pkg/options"
89
"io"
910
"log/slog"
1011
"os"
1112
)
1213

13-
func defaultConfig() *Config {
14-
return &Config{
14+
func defaultConfig() (result *Config) {
15+
result = &Config{
1516
Debug: DebugConfig{
1617
LogLevel: int(slog.LevelError),
1718
PprofAddress: ":6060",
@@ -31,7 +32,6 @@ func defaultConfig() *Config {
3132
PrintVersion: false,
3233
},
3334
LLM: llm.LLMConfig{
34-
Backend: "copilot",
3535
CallOptions: llm.CallOptionsConfig{
3636
Temperature: -1,
3737
TopK: -1,
@@ -94,4 +94,9 @@ func defaultConfig() *Config {
9494
TargetsRaw: []string{PrinterTargetOut},
9595
},
9696
}
97+
if llms.IsCopilotInstalled() {
98+
result.LLM.Backend = "copilot"
99+
}
100+
101+
return
97102
}

config/llm/general.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *LLMConfig) GetUsage(field string) string {
6363
func (c *LLMConfig) Validate() error {
6464
b := c.getBackend()
6565
if b == nil {
66-
return fmt.Errorf("Invalid backend %s", c.Backend)
66+
return fmt.Errorf("Invalid backend '%s'", c.Backend)
6767
}
6868
if ve := b.Validate(); ve != nil {
6969
return ve

controller/build.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ import (
1616
"net/http"
1717
)
1818

19-
func BuildFromConfig(cfg *config.Config, lastState string) (ctrl *Controller, err error) {
19+
func BuildFromConfig(cfg *config.Config, lastState string, buildMode bool) (ctrl *Controller, err error) {
2020
ctrl = &Controller{
2121
appConfig: cfg,
2222
lastState: lastState,
2323
}
2424

25+
if buildMode {
26+
// in build mode the bindings will be generated
27+
return ctrl, nil
28+
}
29+
2530
printer := io.MultiResponsePrinter{}
2631
if cfg.Printer.Format == config.PrinterFormatPlain {
2732
for _, target := range cfg.Printer.Targets {

llms/copilot_helper.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@ package llms
22

33
import cmdchain "github.com/rainu/go-command-chain"
44

5+
var copilotInstalled *bool
6+
57
func IsCopilotInstalled() bool {
6-
err := cmdchain.Builder().
7-
Join("gh", "copilot", "-v").
8-
Finalize().Run()
8+
if copilotInstalled == nil {
9+
err := cmdchain.Builder().
10+
Join("gh", "copilot", "-v").
11+
Finalize().Run()
12+
13+
installed := err == nil
14+
copilotInstalled = &installed
15+
}
916

10-
return err == nil
17+
return *copilotInstalled
1118
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func main() {
6666
}
6767
defer cfg.Printer.Close()
6868

69-
ctrl, err := controller.BuildFromConfig(cfg, os.Getenv(lastStateEnv))
69+
ctrl, err := controller.BuildFromConfig(cfg, os.Getenv(lastStateEnv), buildMode)
7070
if err != nil {
7171
fmt.Fprintln(os.Stderr, err.Error())
7272
os.Exit(2)

0 commit comments

Comments
 (0)