-
Notifications
You must be signed in to change notification settings - Fork 917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(agents-api): Fix map reduce step and activity #466
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a mutable default argument (like a dictionary) is not recommended as it can lead to unexpected behavior. Consider using
None
as the default value and initializing the dictionary inside the function.