-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(agents-api): Fix map reduce step and activity
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Aug 23, 2024
1 parent
c3d9ce7
commit 2a12e3c
Showing
72 changed files
with
610 additions
and
1,558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
agents-api/agents_api/activities/task_steps/base_evaluate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import Any | ||
|
||
from beartype import beartype | ||
from temporalio import activity | ||
|
||
from ...env import testing | ||
from ..utils import get_evaluator | ||
|
||
|
||
@beartype | ||
async def base_evaluate( | ||
exprs: str | list[str] | dict[str, str], | ||
values: dict[str, Any] = {}, | ||
) -> 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" | ||
|
||
evaluator = get_evaluator(names=values) | ||
|
||
try: | ||
match exprs: | ||
case str(): | ||
return evaluator.eval(exprs) | ||
|
||
case list(): | ||
return [evaluator.eval(expr) for expr in exprs] | ||
|
||
case dict(): | ||
return {k: evaluator.eval(v) for k, v in exprs.items()} | ||
|
||
except BaseException as e: | ||
if activity.in_activity(): | ||
activity.logger.error(f"Error in base_evaluate: {e}") | ||
|
||
raise | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported base_evaluate directly | ||
# They do the same thing, so we dont need to mock the base_evaluate function | ||
mock_base_evaluate = base_evaluate | ||
|
||
base_evaluate = activity.defn(name="base_evaluate")( | ||
base_evaluate if not testing else mock_base_evaluate | ||
) |
29 changes: 18 additions & 11 deletions
29
agents-api/agents_api/activities/task_steps/evaluate_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 11 additions & 6 deletions
17
agents-api/agents_api/activities/task_steps/wait_for_input_step.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Any | ||
|
||
from beartype import beartype | ||
from simpleeval import EvalWithCompoundTypes, SimpleEval | ||
|
||
|
||
@beartype | ||
def get_evaluator(names: dict[str, Any]) -> SimpleEval: | ||
evaluator = EvalWithCompoundTypes(names=names) | ||
return evaluator | ||
|
||
|
||
@beartype | ||
def simple_eval_dict(exprs: dict[str, str], values: dict[str, Any]) -> dict[str, Any]: | ||
evaluator = get_evaluator(names=values) | ||
|
||
return {k: evaluator.eval(v) for k, v in exprs.items()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.