Skip to content

Commit

Permalink
feat: Check for expr prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Nov 28, 2024
1 parent 50b6b2c commit 0d45e70
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions agents-api/agents_api/activities/task_steps/base_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def __init__(self, error, expression, values):


# Recursive evaluation helper function
def _recursive_evaluate(expr, evaluator: SimpleEval):
def _recursive_evaluate(expr, evaluator: SimpleEval, eval_prompt_prefix: str = "$"):
if isinstance(expr, str):
try:
return evaluator.eval(expr)
result = expr
if expr.startswith(eval_prompt_prefix):
result = evaluator.eval(expr[len(eval_prompt_prefix):].strip())

return result
except Exception as e:
if activity.in_activity():
evaluate_error = EvaluateError(e, expr, evaluator.names)
Expand Down Expand Up @@ -69,6 +73,7 @@ async def base_evaluate(
exprs: Any,
values: dict[str, Any] = {},
extra_lambda_strs: dict[str, str] | None = None,
eval_prompt_prefix: str = "$_",
) -> Any | list[Any] | dict[str, Any]:
input_len = 1 if isinstance(exprs, str) else len(exprs)
assert input_len > 0, "exprs must be a non-empty string, list or dict"
Expand Down Expand Up @@ -100,7 +105,9 @@ async def base_evaluate(
evaluator: SimpleEval = get_evaluator(names=values, extra_functions=extra_lambdas)

# Recursively evaluate the expression
result = _recursive_evaluate(exprs, evaluator)
result = _recursive_evaluate(
exprs, evaluator, eval_prompt_prefix=eval_prompt_prefix
)
return result


Expand Down

0 comments on commit 0d45e70

Please sign in to comment.