Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
D-W- committed Apr 29, 2024
1 parent b6d6830 commit d93e7a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/promptflow-core/promptflow/executor/_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ def __init__(
self._message_format = MessageFormatType.BASIC
self._multimedia_processor = BasicMultimediaProcessor()

def _get_func_name(self):
@classmethod
def _get_func_name(cls, func: Callable):
try:
original_func = getattr(self._func, "__original_function")
original_func = getattr(func, "__original_function")
if isinstance(original_func, partial):
original_func = original_func.func
return original_func.__qualname__
except AttributeError:
return self._func.__qualname__
return func.__qualname__

@contextlib.contextmanager
def _exec_line_context(self, run_id, line_number):
Expand Down Expand Up @@ -158,7 +159,7 @@ def _exec_line(
error_type_and_message = f"({e.__class__.__name__}) {e}"
ex = ScriptExecutionError(
message_format="Execution failure in '{func_name}': {error_type_and_message}",
func_name=self._get_func_name(),
func_name=self._func_name,
error_type_and_message=error_type_and_message,
error=e,
)
Expand Down Expand Up @@ -460,6 +461,7 @@ def _initialize_function(self):
else:
self._func = func
self._func_async = sync_to_async(func)
self._func_name = self._get_func_name(func=func)
return func

def _initialize_aggr_function(self, flow_obj: object):
Expand Down
6 changes: 6 additions & 0 deletions src/promptflow-core/tests/core/e2etests/test_eager_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,9 @@ def test_aggregation_error(self):
aggr_result = executor._exec_aggregation(inputs=[line_result.output])
# exec aggregation won't fail with error
assert aggr_result.metrics == {}

def test_get_function_name(self):
expected_names = ["ClassEntry.__call__", "func_entry", "func_entry_async"]
for (entry, _, _), expected_name in zip(function_entries, expected_names):
executor = FlowExecutor.create(entry, {})
assert executor._func_name == expected_name

0 comments on commit d93e7a9

Please sign in to comment.