Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions cmd/obol/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func modelCommand(cfg *config.Config) *cli.Command {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "provider",
Usage: "Provider name (anthropic, openai)",
Usage: "Provider name (e.g. anthropic, openai, zai, deepseek)",
},
&cli.StringFlag{
Name: "api-key",
Expand All @@ -38,7 +38,7 @@ func modelCommand(cfg *config.Config) *cli.Command {
// Interactive mode if flags not provided
if provider == "" || apiKey == "" {
var err error
provider, apiKey, err = promptModelConfig()
provider, apiKey, err = promptModelConfig(cfg)
if err != nil {
return err
}
Expand All @@ -64,7 +64,7 @@ func modelCommand(cfg *config.Config) *cli.Command {

fmt.Println("Global llmspy providers:")
fmt.Println()
fmt.Printf(" %-12s %-8s %-10s %s\n", "PROVIDER", "ENABLED", "API KEY", "ENV VAR")
fmt.Printf(" %-20s %-8s %-10s %s\n", "PROVIDER", "ENABLED", "API KEY", "ENV VAR")
for _, name := range providers {
s := status[name]
key := "n/a"
Expand All @@ -75,8 +75,12 @@ func modelCommand(cfg *config.Config) *cli.Command {
key = "missing"
}
}
fmt.Printf(" %-12s %-8t %-10s %s\n", name, s.Enabled, key, s.EnvVar)
fmt.Printf(" %-20s %-8t %-10s %s\n", name, s.Enabled, key, s.EnvVar)
}

// Show hint about available providers
fmt.Println()
fmt.Println("Run 'obol model setup' to configure a provider.")
return nil
},
},
Expand All @@ -85,38 +89,42 @@ func modelCommand(cfg *config.Config) *cli.Command {
}

// promptModelConfig interactively asks the user for provider and API key.
func promptModelConfig() (string, string, error) {
// It queries the running llmspy pod for available providers.
func promptModelConfig(cfg *config.Config) (string, string, error) {
providers, err := model.GetAvailableProviders(cfg)
if err != nil {
return "", "", fmt.Errorf("failed to discover providers: %w", err)
}
if len(providers) == 0 {
return "", "", fmt.Errorf("no cloud providers found in llmspy")
}

reader := bufio.NewReader(os.Stdin)

fmt.Println("Select a provider:")
fmt.Println(" [1] Anthropic")
fmt.Println(" [2] OpenAI")
fmt.Print("\nChoice [1]: ")
fmt.Println("Available providers:")
for i, p := range providers {
fmt.Printf(" [%d] %s (%s)\n", i+1, p.Name, p.ID)
}
fmt.Printf("\nChoice [1]: ")

line, _ := reader.ReadString('\n')
choice := strings.TrimSpace(line)
if choice == "" {
choice = "1"
}

var provider, display string
switch choice {
case "1":
provider = "anthropic"
display = "Anthropic"
case "2":
provider = "openai"
display = "OpenAI"
default:
return "", "", fmt.Errorf("unknown choice: %s", choice)
idx := 0
if _, err := fmt.Sscanf(choice, "%d", &idx); err != nil || idx < 1 || idx > len(providers) {
return "", "", fmt.Errorf("invalid choice: %s", choice)
}
selected := providers[idx-1]

fmt.Printf("\n%s API key: ", display)
fmt.Printf("\n%s API key (%s): ", selected.Name, selected.EnvVar)
apiKey, _ := reader.ReadString('\n')
apiKey = strings.TrimSpace(apiKey)
if apiKey == "" {
return "", "", fmt.Errorf("API key is required")
}

return provider, apiKey, nil
return selected.ID, apiKey, nil
}
Loading
Loading