MCPcopy
hub / github.com/kvcache-ai/ktransformers / prompt_choice

Function prompt_choice

kt-kernel/python/cli/utils/console.py:124–146  ·  view source on GitHub ↗

Prompt for a choice from a list.

(message: str, choices: list[str], default: Optional[str] = None)

Source from the content-addressed store, hash-verified

122
123
124def prompt_choice(message: str, choices: list[str], default: Optional[str] = None) -> str:
125 """Prompt for a choice from a list."""
126 # Display numbered choices
127 console.print(f"\n[bold]{message}[/bold]")
128 for i, choice in enumerate(choices, 1):
129 console.print(f" [highlight][{i}][/highlight] {choice}")
130
131 while True:
132 response = Prompt.ask(
133 "\n" + t("prompt_select"),
134 console=console,
135 default=str(choices.index(default) + 1) if default else None,
136 )
137 try:
138 idx = int(response) - 1
139 if 0 <= idx < len(choices):
140 return choices[idx]
141 except ValueError:
142 # Check if response matches a choice directly
143 if response in choices:
144 return response
145
146 print_error(f"Please enter a number between 1 and {len(choices)}")
147
148
149def prompt_text(message: str, default: Optional[str] = None) -> str:

Callers

nothing calls this directly

Calls 3

tFunction · 0.90
print_errorFunction · 0.85
printMethod · 0.45

Tested by

no test coverage detected