forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_mode.py
More file actions
37 lines (27 loc) · 1.18 KB
/
auto_mode.py
File metadata and controls
37 lines (27 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Utilities for running examples in automated mode.
When ``EXAMPLES_INTERACTIVE_MODE=auto`` is set, these helpers provide
deterministic inputs and confirmations so examples can run without manual
interaction. The helpers are intentionally lightweight to avoid adding
dependencies to example code.
"""
from __future__ import annotations
import os
def is_auto_mode() -> bool:
"""Return True when examples should bypass interactive prompts."""
return os.environ.get("EXAMPLES_INTERACTIVE_MODE", "").lower() == "auto"
def input_with_fallback(prompt: str, fallback: str) -> str:
"""Return the fallback text in auto mode, otherwise defer to input()."""
if is_auto_mode():
print(f"[auto-input] {prompt.strip()} -> {fallback}")
return fallback
return input(prompt)
def confirm_with_fallback(prompt: str, default: bool = True) -> bool:
"""Return default in auto mode; otherwise ask the user."""
if is_auto_mode():
choice = "yes" if default else "no"
print(f"[auto-confirm] {prompt.strip()} -> {choice}")
return default
answer = input(prompt).strip().lower()
if not answer:
return default
return answer in {"y", "yes"}