Apply fixture-kit mode to MMMUVLMMixin (#15615)

This commit is contained in:
lif
2025-12-28 17:22:05 +08:00
committed by GitHub
parent 8fab48952e
commit 5969be2f06
6 changed files with 236 additions and 21 deletions
+23
View File
@@ -6,6 +6,29 @@ from enum import IntEnum
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")
backup = {key: os.environ.get(key) for key in env_vars}
try:
for key, value in env_vars.items():
if value is None:
os.environ.pop(key, None)
else:
os.environ[key] = str(value)
yield
finally:
for key, value in backup.items():
if value is None:
os.environ.pop(key, None)
else:
os.environ[key] = value
class EnvField:
_allow_set_name = True