Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of timed-out user input #1873

Open
brunolnetto opened this issue May 18, 2024 · 2 comments
Open

Implementation of timed-out user input #1873

brunolnetto opened this issue May 18, 2024 · 2 comments

Comments

@brunolnetto
Copy link

I tried implementing (I prototyped with Gemini) a code snippet for timeout user input. Prompt complains ModuleNotFoundError: No module named 'prompt_toolkit.timeout'. Does it exist?

from prompt_toolkit import prompt
from prompt_toolkit.timeout import Timeout  # For timeout handling

def get_input_with_timeout(prompt_message: str, timeout: float):
  """Gets user input with a timeout using prompt_toolkit (potential interrupt).

  Args:
      prompt_message: The message to display for user input.
      timeout: The timeout duration in seconds.

  Returns:
      The user input as a string or None if timed out.
  """
  try:
    return prompt(prompt_message, timeout=timeout)
  except Timeout:
    return None
  except KeyboardInterrupt:
    # Handle keyboard interrupt (optional)
    pass

# Example usage (assuming prompt_toolkit is installed)
timeout_value = 5  # Set timeout in seconds
user_input = get_input_with_timeout("Enter something within 5 seconds: ", timeout_value)

if user_input:
  print(f"You entered: {user_input}")
else:
  print("Timeout reached. No input received.")
@joouha
Copy link
Contributor

joouha commented May 28, 2024

No. It appears your LLM has been "hallucinating".

@brunolnetto
Copy link
Author

How do you recommend to implement such feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants