Skip to content

Commit

Permalink
Fix flex flow metrices
Browse files Browse the repository at this point in the history
  • Loading branch information
Lina Tang committed Apr 25, 2024
1 parent 108e067 commit 09bd62a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/promptflow-core/promptflow/executor/_script_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,22 @@ def _exec_aggregation(
output, metrics = None, {}
try:
output = self._aggr_func(**{self._aggr_input_name: inputs})
metrics = output if isinstance(output, dict) else {"metrics": output}
for k, v in metrics.items():
log_metric(k, v)
if isinstance(output, dict):
metrics = output
for k, v in metrics.items():
log_metric(k, v)
else:
logger.warning("The output of aggregation function isn't a dictionary, skip the metrices update.")
except Exception:
pass
error_type_and_message = f"({e.__class__.__name__}) {e}"
e = ScriptExecutionError(
message_format="Execution failure in '{func_name}': {error_type_and_message}",
func_name=self._aggr_func.__name__,
error_type_and_message=error_type_and_message,
)
error = ExceptionPresenter.create(e).to_dict(include_debug_info=True)
logger.warning(f"Failed to execute aggregation function with error: {error}")
logger.warning("The flow will have empty metrics.")
return AggregationResult(output, metrics, {})

async def exec_aggregation_async(
Expand All @@ -219,9 +230,12 @@ async def _exec_aggregation_async(self, inputs):
output = None
try:
output = await self._aggr_func_async(**{self._aggr_input_name: inputs})
metrics = output if isinstance(output, dict) else {"metrics": output}
for k, v in metrics.items():
log_metric(k, v)
if isinstance(output, dict):
metrics = output
for k, v in metrics.items():
log_metric(k, v)
else:
logger.warning("The output of aggregation function isn't a dictionary, skip the metrices update.")
except Exception as e:
error_type_and_message = f"({e.__class__.__name__}) {e}"
e = ScriptExecutionError(
Expand Down

0 comments on commit 09bd62a

Please sign in to comment.