Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.

Commit 5361569

Browse files
caarlos0mwayCopilot
authored
fix: show model picker if -m doesn't yield a valid model (#542)
* fix: show model picker if -m doesn't yield a valid model Co-authored-by: Matt Way <mway@users.noreply.github.com> * Update main.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Matt Way <mway@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2b240f4 commit 5361569

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

main.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -778,12 +778,24 @@ func isNoArgs() bool {
778778
}
779779

780780
func askInfo() error {
781+
var foundModel bool
781782
apis := make([]huh.Option[string], 0, len(config.APIs))
782783
opts := map[string][]huh.Option[string]{}
783784
for _, api := range config.APIs {
784785
apis = append(apis, huh.NewOption(api.Name, api.Name))
785-
for model := range api.Models {
786-
opts[api.Name] = append(opts[api.Name], huh.NewOption(model, model))
786+
for name, model := range api.Models {
787+
opts[api.Name] = append(opts[api.Name], huh.NewOption(name, name))
788+
789+
// checks if this is the model we intend to use if not using
790+
// `--ask-model`:
791+
if !config.AskModel &&
792+
(config.API == "" || config.API == api.Name) &&
793+
(config.Model == name || slices.Contains(model.Aliases, config.Model)) {
794+
// if it is, adjusts api and model so its cheaper later on.
795+
config.API = api.Name
796+
config.Model = name
797+
foundModel = true
798+
}
787799
}
788800
}
789801

@@ -792,6 +804,7 @@ func askInfo() error {
792804
if err == nil && found != nil && found.Model != nil && found.API != nil {
793805
config.Model = *found.Model
794806
config.API = *found.API
807+
foundModel = true
795808
}
796809
}
797810

@@ -812,12 +825,18 @@ func askInfo() error {
812825
}, &config.API).
813826
Value(&config.Model),
814827
).WithHideFunc(func() bool {
815-
return !config.AskModel
828+
// AskModel is true if the user is passing a flag to ask;
829+
// FoundModel is true if a model is found for whatever config the
830+
// user has (either --api/--model or default-api and
831+
// default-model in settings).
832+
// So, it'll only hide this if the user didn't run with
833+
// `--ask-model` AND the configuration yields a valid model.
834+
return !config.AskModel && foundModel
816835
}),
817836
huh.NewGroup(
818837
huh.NewText().
819838
TitleFunc(func() string {
820-
return fmt.Sprintf("Enter a prompt for %s:", config.Model)
839+
return fmt.Sprintf("Enter a prompt for %s/%s:", config.API, config.Model)
821840
}, &config.Model).
822841
Value(&config.Prefix),
823842
).WithHideFunc(func() bool {

0 commit comments

Comments
 (0)