10 "charm.land/catwalk/pkg/catwalk"
11 "charm.land/lipgloss/v2/tree"
12 "github.com/charmbracelet/crush/internal/config"
13 "github.com/mattn/go-isatty"
14 "github.com/spf13/cobra"
17var modelsCmd = &cobra.Command{
19 Short: "List all available models from configured providers",
20 Long: `List all available models from configured providers. Shows provider name and model IDs.`,
21 Example: `# List all available models
26 Args: cobra.ArbitraryArgs,
27 RunE: func(cmd *cobra.Command, args []string) error {
28 cwd, err := ResolveCwd(cmd)
33 dataDir, _ := cmd.Flags().GetString("data-dir")
34 debug, _ := cmd.Flags().GetBool("debug")
36 cfg, err := config.Init(cwd, dataDir, debug)
41 if !cfg.Config().IsConfigured() {
42 return fmt.Errorf("no providers configured - please run 'crush' to set up a provider interactively")
45 term := strings.ToLower(strings.Join(args, " "))
46 filter := func(p config.ProviderConfig, m catwalk.Model) bool {
47 for _, s := range []string{p.ID, p.Name, m.ID, m.Name} {
48 if term == "" || strings.Contains(strings.ToLower(s), term) {
55 var providerIDs []string
56 providerModels := make(map[string][]string)
58 for providerID, provider := range cfg.Config().Providers.Seq2() {
63 for _, model := range provider.Models {
64 if !filter(provider, model) {
67 providerModels[providerID] = append(providerModels[providerID], model.ID)
73 slices.Sort(providerModels[providerID])
74 providerIDs = append(providerIDs, providerID)
76 sort.Strings(providerIDs)
78 if len(providerIDs) == 0 && len(args) == 0 {
79 return fmt.Errorf("no enabled providers found")
81 if len(providerIDs) == 0 {
82 return fmt.Errorf("no enabled providers found matching %q", term)
85 if !isatty.IsTerminal(os.Stdout.Fd()) {
86 for _, providerID := range providerIDs {
87 for _, modelID := range providerModels[providerID] {
88 fmt.Println(providerID + "/" + modelID)
95 for _, providerID := range providerIDs {
96 providerNode := tree.Root(providerID)
97 for _, modelID := range providerModels[providerID] {
98 providerNode.Child(modelID)
100 t.Child(providerNode)
109 rootCmd.AddCommand(modelsCmd)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list