Skip to content

Commit

Permalink
Replace set by system environment variable with class attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
diondrapeck committed Jul 22, 2024
1 parent bdb7fa7 commit f9867bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/promptflow-evals/promptflow/evals/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ class Prefixes:

PF_BATCH_TIMEOUT_SEC_DEFAULT = 3600
PF_BATCH_TIMEOUT_SEC = "PF_BATCH_TIMEOUT_SEC"
PF_IS_BATCH_TIMEOUT_SYSTEM_SET = "PF_IS_BATCH_TIMEOUT_SYSTEM_SET"
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

from promptflow._sdk._constants import PF_FLOW_ENTRY_IN_TMP, PF_FLOW_META_LOAD_IN_SUBPROCESS
from promptflow._utils.user_agent_utils import ClientUserAgentUtil
from promptflow.evals._constants import (
PF_BATCH_TIMEOUT_SEC,
PF_BATCH_TIMEOUT_SEC_DEFAULT,
PF_IS_BATCH_TIMEOUT_SYSTEM_SET,
)
from promptflow.evals._constants import PF_BATCH_TIMEOUT_SEC, PF_BATCH_TIMEOUT_SEC_DEFAULT
from promptflow.tracing._integrations._openai_injector import inject_openai_api, recover_openai_api

from ..._user_agent import USER_AGENT
Expand All @@ -21,6 +17,7 @@
class BatchRunContext:
def __init__(self, client):
self.client = client
self._is_timeout_set_by_system = False

def __enter__(self):
if isinstance(self.client, CodeClient):
Expand All @@ -33,9 +30,7 @@ def __enter__(self):

if os.environ.get(PF_BATCH_TIMEOUT_SEC) is None:
os.environ[PF_BATCH_TIMEOUT_SEC] = str(PF_BATCH_TIMEOUT_SEC_DEFAULT)
os.environ[PF_IS_BATCH_TIMEOUT_SYSTEM_SET] = "true"
else:
os.environ[PF_IS_BATCH_TIMEOUT_SYSTEM_SET] = "false"
self._is_timeout_set_by_system = True

# For addressing the issue of asyncio event loop closed on Windows
set_event_loop_policy()
Expand All @@ -48,6 +43,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
os.environ.pop(PF_FLOW_ENTRY_IN_TMP, None)
os.environ.pop(PF_FLOW_META_LOAD_IN_SUBPROCESS, None)

if os.environ.get(PF_IS_BATCH_TIMEOUT_SYSTEM_SET) == "true":
if self._is_timeout_set_by_system:
os.environ.pop(PF_BATCH_TIMEOUT_SEC, None)
os.environ[PF_IS_BATCH_TIMEOUT_SYSTEM_SET] = "false"
self._is_timeout_set_by_system = False

0 comments on commit f9867bc

Please sign in to comment.