Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ninghu committed Jun 17, 2024
1 parent 25915a3 commit 7b9ae75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
25 changes: 12 additions & 13 deletions src/promptflow-evals/promptflow/evals/evaluate/_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from promptflow._sdk._telemetry import ActivityType, log_activity
from promptflow._sdk._telemetry.telemetry import get_telemetry_logger
from promptflow.client import PFClient
from promptflow.exceptions import ErrorTarget, PromptflowException

from .._constants import CONTENT_SAFETY_DEFECT_RATE_THRESHOLD_DEFAULT, EvaluationMetrics, Prefixes
from .._user_agent import USER_AGENT
Expand Down Expand Up @@ -350,19 +349,19 @@ def evaluate(
**kwargs,
)
except Exception as e:
if isinstance(e, PromptflowException) and e.target == ErrorTarget.BATCH:
bootstrap_error = (
"An attempt has been made to start a new process before the\n "
"current process has finished its bootstrapping phase."
# Handle multiprocess bootstrap error
bootstrap_error = (
"An attempt has been made to start a new process before the\n "
"current process has finished its bootstrapping phase."
)
if bootstrap_error in str(e):
error_message = (
"The evaluation failed due to an error during multiprocess bootstrapping."
"Please ensure the evaluate API is properly guarded with the '__main__' block:\n\n"
" if __name__ == '__main__':\n"
" evaluate(...)"
)
if bootstrap_error in e.message:
error_message = (
"Process creation failed during evaluation. Please ensure the "
"evaluate API is properly guarded with the '__main__' block:\n\n"
" if __name__ == '__main__':\n"
" evaluate(...)"
)
raise RuntimeError(error_message)
raise RuntimeError(error_message)

raise e

Expand Down
11 changes: 4 additions & 7 deletions src/promptflow-evals/tests/evals/unittests/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from promptflow.evals.evaluate._evaluate import _apply_target_to_data, _rename_columns_conditionally
from promptflow.evals.evaluate._utils import _apply_column_mapping
from promptflow.evals.evaluators import F1ScoreEvaluator, GroundednessEvaluator
from promptflow.exceptions import ErrorTarget, PromptflowException


def _get_file(name):
Expand Down Expand Up @@ -386,13 +385,11 @@ def test_evaluate_with_errors(self):

@patch("promptflow.evals.evaluate._evaluate._evaluate")
def test_evaluate_main_entry_guard(self, mock_evaluate, evaluate_test_data_jsonl_file):
mock_evaluate.side_effect = PromptflowException(
message_format=(
"An attempt has been made to start a new process before the\n "
"current process has finished its bootstrapping phase."
),
target=ErrorTarget.BATCH,
err_msg = (
"An attempt has been made to start a new process before the\n "
"current process has finished its bootstrapping phase."
)
mock_evaluate.side_effect = RuntimeError(err_msg)

with pytest.raises(RuntimeError) as exc_info:
evaluate(
Expand Down

0 comments on commit 7b9ae75

Please sign in to comment.