Spaces:
Sleeping
Sleeping
siddeshwar-kagatikar commited on
Commit ·
4624775
1
Parent(s): 9b3c545
Fail fast on placeholder inference API keys
Browse files- inference.py +21 -1
- tests/test_inference.py +8 -0
inference.py
CHANGED
|
@@ -49,6 +49,26 @@ def log_end(success: bool, steps: int, score: float, rewards: list[float]) -> No
|
|
| 49 |
)
|
| 50 |
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def _supports_reasoning_effort_in_chat_completions(model: str) -> bool:
|
| 53 |
model_name = str(model).strip().lower()
|
| 54 |
if model_name.startswith("gpt-5.4-mini"):
|
|
@@ -157,7 +177,7 @@ def main() -> None:
|
|
| 157 |
api_key = OPENAI_API_KEY or HF_TOKEN
|
| 158 |
if not api_key:
|
| 159 |
raise SystemExit("Set OPENAI_API_KEY or HF_TOKEN before running inference.py.")
|
| 160 |
-
if
|
| 161 |
raise SystemExit("Replace the placeholder with your real OpenAI API key.")
|
| 162 |
|
| 163 |
try:
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
|
| 52 |
+
def _looks_like_placeholder_api_key(value: str) -> bool:
|
| 53 |
+
token = str(value or "").strip().lower()
|
| 54 |
+
if not token:
|
| 55 |
+
return True
|
| 56 |
+
placeholder_markers = [
|
| 57 |
+
"your_openai_api_key",
|
| 58 |
+
"your-key",
|
| 59 |
+
"your_key",
|
| 60 |
+
"your real",
|
| 61 |
+
"real-openai-key",
|
| 62 |
+
"replace-me",
|
| 63 |
+
"changeme",
|
| 64 |
+
"example",
|
| 65 |
+
"<api-key>",
|
| 66 |
+
]
|
| 67 |
+
if token.startswith("your_") or token.startswith("sk-your-"):
|
| 68 |
+
return True
|
| 69 |
+
return any(marker in token for marker in placeholder_markers)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
def _supports_reasoning_effort_in_chat_completions(model: str) -> bool:
|
| 73 |
model_name = str(model).strip().lower()
|
| 74 |
if model_name.startswith("gpt-5.4-mini"):
|
|
|
|
| 177 |
api_key = OPENAI_API_KEY or HF_TOKEN
|
| 178 |
if not api_key:
|
| 179 |
raise SystemExit("Set OPENAI_API_KEY or HF_TOKEN before running inference.py.")
|
| 180 |
+
if _looks_like_placeholder_api_key(api_key):
|
| 181 |
raise SystemExit("Replace the placeholder with your real OpenAI API key.")
|
| 182 |
|
| 183 |
try:
|
tests/test_inference.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from inference import _looks_like_placeholder_api_key
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def test_placeholder_api_key_detection():
|
| 5 |
+
assert _looks_like_placeholder_api_key("your_openai_api_key") is True
|
| 6 |
+
assert _looks_like_placeholder_api_key("sk-your-real-openai-key") is True
|
| 7 |
+
assert _looks_like_placeholder_api_key("replace-me") is True
|
| 8 |
+
assert _looks_like_placeholder_api_key("sk-proj-realistic-looking-token") is False
|