Skip to content

Commit bb23a47

Browse files
add support to specify default model while running the binary
1 parent 0fd143e commit bb23a47

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var (
1818
FileLocation string
1919
HistoryLocation string
2020
PromptText = panes.PromptText
21+
SelectedModel = panes.Selected
2122
)
2223

2324
func init() {
@@ -29,7 +30,7 @@ func init() {
2930
err = os.MkdirAll(filepath.Dir(HistoryLocation), os.ModePerm)
3031
checkNilErr(err)
3132

32-
logFile, _ := os.OpenFile("lazyai.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
33+
logFile, _ := os.OpenFile("lazyai.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o666)
3334
log.SetOutput(logFile)
3435
}
3536

@@ -50,8 +51,17 @@ func setupUI(detachedMode *bool, app *tview.Application) {
5051
}
5152
}
5253

54+
func throwInvalidModelErr() {
55+
fmt.Println("Invalid model used, available models:")
56+
for _, model := range panes.AvailableModels {
57+
fmt.Println(model)
58+
}
59+
os.Exit(0)
60+
}
61+
5362
func main() {
5463
detachedMode := flag.Bool("d", false, "Run in detached mode")
64+
defaultModel := flag.String("m", "gemini-2.0-flash", "Set the default model to use")
5565
defaultPrompt := flag.String("p", "", "Set the default prompt")
5666
helpCommand := flag.Bool("help", false, "Show help commands")
5767
flag.Parse()
@@ -70,6 +80,21 @@ func main() {
7080
PromptText.PromptString = *defaultPrompt
7181
}
7282

83+
// check if we support specified model
84+
validModel := false
85+
for _, v := range panes.AvailableModels {
86+
if v.SelectedModel == *defaultModel {
87+
validModel = true
88+
break
89+
}
90+
}
91+
92+
if !validModel {
93+
throwInvalidModelErr()
94+
}
95+
96+
panes.Selected.SelectedModel = *defaultModel
97+
7398
app := tview.NewApplication().EnableMouse(true)
7499

75100
if !api.CheckCredentials(FileLocation, nil) {
@@ -80,7 +105,7 @@ func main() {
80105
return
81106
}
82107

83-
err := os.WriteFile(FileLocation, []byte(apiInput), 0644)
108+
err := os.WriteFile(FileLocation, []byte(apiInput), 0o644)
84109
checkNilErr(err)
85110

86111
log.Println("Starting clipboard monitoring after credential input.")

panes/modelsPane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var (
1212
Selected *internal.Model
1313
)
1414

15-
var availableModels = map[string]*internal.Model{
15+
var AvailableModels = map[string]*internal.Model{
1616
"Gemini 2.0 Flash": {SelectedModel: "gemini-2.0-flash"},
1717
"Gemini 2.0 Flash-Lite": {SelectedModel: "gemini-2.0-flash-lite"},
1818
"Gemini Pro 1.5": {SelectedModel: "gemini-1.5-pro"},
@@ -24,10 +24,10 @@ func init() {
2424
ModelList.ShowSecondaryText(false).SetTitle(" Models ").SetBorder(true)
2525
Selected = &internal.Model{}
2626

27-
SelectModel(availableModels["Gemini 2.0 Flash"].SelectedModel)
27+
SelectModel(AvailableModels["Gemini 2.0 Flash"].SelectedModel)
2828

2929
// Add models to the list
30-
for key, model := range availableModels {
30+
for key, model := range AvailableModels {
3131
currentModel := model
3232
ModelList.AddItem(key, "", 0, func() {
3333
SelectModel(currentModel.SelectedModel)
@@ -40,7 +40,7 @@ func init() {
4040
case tcell.KeyEnter:
4141
currentItem := ModelList.GetCurrentItem()
4242
mainText, _ := ModelList.GetItemText(currentItem)
43-
SelectModel(availableModels[mainText].SelectedModel)
43+
SelectModel(AvailableModels[mainText].SelectedModel)
4444
}
4545
return event
4646
})

panes/outputPane.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ var (
1818
)
1919

2020
func init() {
21-
var commands string = "\n## Commands:\n\n" +
21+
commands := "\n## Commands:\n\n" +
2222
"- run the application: `lazyAi`\n\n" +
2323
"- run the application in detached mode: `lazyAi -d`\n" +
24-
"- run the application with a default prompt: `lazyAi -p \"your prompt here\"`\n"
24+
"- run the application with a default prompt: `lazyAi -p \"your prompt here\"`\n" +
25+
"- run the application with a default model: `lazyAi -m \"gemini-2.0-flash\"`\n"
2526

2627
helpcmd := true
2728
HelpCommands = MarkdownToTview(commands, &helpcmd)

0 commit comments

Comments
 (0)