-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(agents-api): Minor refactors
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Aug 18, 2024
1 parent
6cd98ae
commit 49ddd62
Showing
4 changed files
with
42 additions
and
35 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
39 changes: 26 additions & 13 deletions
39
agents-api/agents_api/activities/task_steps/if_else_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
import logging | ||
|
||
from beartype import beartype | ||
from simpleeval import simple_eval | ||
from temporalio import activity | ||
|
||
from ...autogen.openapi_model import ( | ||
IfElseWorkflowStep, | ||
) | ||
from ...autogen.openapi_model import IfElseWorkflowStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
from ...env import testing | ||
|
||
|
||
@activity.defn | ||
@beartype | ||
async def if_else_step(context: StepContext[IfElseWorkflowStep]) -> dict: | ||
raise NotImplementedError() | ||
# context_data: dict = context.model_dump() | ||
async def if_else_step(context: StepContext) -> StepOutcome: | ||
# NOTE: This activity is only for logging, so we just evaluate the expression | ||
# Hence, it's a local activity and SHOULD NOT fail | ||
try: | ||
assert isinstance(context.current_step, IfElseWorkflowStep) | ||
|
||
expr: str = context.current_step.if_ | ||
output = simple_eval(expr, names=context.model_dump()) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
except Exception as e: | ||
logging.error(f"Error in if_else_step: {e}") | ||
return StepOutcome(output=None) | ||
|
||
|
||
# next_workflow = ( | ||
# context.current_step.then | ||
# if simple_eval(context.current_step.if_, names=context_data) | ||
# else context.current_step.else_ | ||
# ) | ||
# Note: This is here just for clarity. We could have just imported if_else_step directly | ||
# They do the same thing, so we dont need to mock the if_else_step function | ||
mock_if_else_step = if_else_step | ||
|
||
# return {"goto_workflow": next_workflow} | ||
if_else_step = activity.defn(name="if_else_step")(if_else_step if not testing else mock_if_else_step) |
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