Flip dumper to disable by default and refactor environment handling (#18878)
This commit is contained in:
@@ -7,11 +7,17 @@ from typing import Any
|
||||
|
||||
|
||||
@contextmanager
|
||||
def temp_set_env(**env_vars: dict[str, Any]):
|
||||
"""Temporarily set non-sglang environment variables, e.g. OPENAI_API_KEY"""
|
||||
for key in env_vars:
|
||||
if key.startswith("SGLANG_") or key.startswith("SGL_"):
|
||||
raise ValueError("temp_set_env should not be used for sglang env vars")
|
||||
def temp_set_env(*, allow_sglang: bool = False, **env_vars: Any):
|
||||
"""Temporarily set environment variables, restoring originals on exit.
|
||||
|
||||
By default, SGLANG_*/SGL_* keys are rejected — use ``Envs`` descriptors
|
||||
for those. Pass ``allow_sglang=True`` only for special env vars that
|
||||
intentionally bypass ``environ.py`` (e.g. ``SGLANG_DUMPER_*``).
|
||||
"""
|
||||
if not allow_sglang:
|
||||
for key in env_vars:
|
||||
if key.startswith("SGLANG_") or key.startswith("SGL_"):
|
||||
raise ValueError("temp_set_env should not be used for sglang env vars")
|
||||
|
||||
backup = {key: os.environ.get(key) for key in env_vars}
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user