Skip to content

Commit 252191d

Browse files
authored
Support MIPROv2 user confirmation in windows (#8485)
* support user confirmation in windows * lint
1 parent 051142e commit 252191d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dspy/teleprompt/mipro_optimizer_v2.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import random
3-
import select
43
import sys
54
import textwrap
65
import time
@@ -395,9 +394,17 @@ def _get_user_confirmation(
395394
# Wait for input with timeout
396395
start_time = time.time()
397396
while time.time() - start_time < 20:
398-
if select.select([sys.stdin], [], [], 0.1)[0]:
399-
user_input = sys.stdin.readline().strip().lower()
400-
return user_input == "y"
397+
if sys.platform == "win32":
398+
import msvcrt
399+
if msvcrt.kbhit():
400+
user_input = msvcrt.getch().decode("utf-8").strip().lower()
401+
print(user_input) # Echo the input
402+
return user_input == "y"
403+
else:
404+
import select
405+
if select.select([sys.stdin], [], [], 0.1)[0]:
406+
user_input = sys.stdin.readline().strip().lower()
407+
return user_input == "y"
401408
time.sleep(0.1)
402409

403410
print("\nNo input received within 20 seconds. Proceeding with execution...")

0 commit comments

Comments
 (0)