-
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.
Merge pull request #460 from julep-ai/f/workflow-tests
feat: Add test for evaluate step
- Loading branch information
Showing
197 changed files
with
6,532 additions
and
1,412 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
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import logging | ||
from typing import TextIO | ||
|
||
logger = logging.getLogger(__name__) | ||
h = logging.StreamHandler() | ||
fmt = logging.Formatter("[%(asctime)s/%(levelname)s] - %(message)s") | ||
logger: logging.Logger = logging.getLogger(__name__) | ||
h: logging.StreamHandler[TextIO] = logging.StreamHandler() | ||
fmt: logging.Formatter = logging.Formatter("[%(asctime)s/%(levelname)s] - %(message)s") | ||
h.setFormatter(fmt) | ||
logger.addHandler(h) |
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
27 changes: 16 additions & 11 deletions
27
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
42 changes: 29 additions & 13 deletions
42
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,40 @@ | ||
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()) | ||
output: bool = bool(output) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
# next_workflow = ( | ||
# context.definition.then | ||
# if simple_eval(context.definition.if_, names=context_data) | ||
# else context.definition.else_ | ||
# ) | ||
except BaseException as e: | ||
logging.error(f"Error in if_else_step: {e}") | ||
return StepOutcome(error=str(e)) | ||
|
||
# return {"goto_workflow": next_workflow} | ||
|
||
# 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 | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from beartype import beartype | ||
from simpleeval import simple_eval | ||
from temporalio import activity | ||
|
||
from ...autogen.openapi_model import LogStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
from ...env import testing | ||
|
||
|
||
@beartype | ||
async def log_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, LogStep) | ||
|
||
expr: str = context.current_step.log | ||
output = simple_eval(expr, names=context.model_dump()) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
except BaseException as e: | ||
logging.error(f"Error in log_step: {e}") | ||
return StepOutcome(error=str(e)) | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported log_step directly | ||
# They do the same thing, so we dont need to mock the log_step function | ||
mock_log_step = log_step | ||
|
||
log_step = activity.defn(name="log_step")(log_step if not testing else mock_log_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
37 changes: 37 additions & 0 deletions
37
agents-api/agents_api/activities/task_steps/return_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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
|
||
from temporalio import activity | ||
|
||
from ...activities.task_steps.utils import simple_eval_dict | ||
from ...autogen.openapi_model import ReturnStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
from ...env import testing | ||
|
||
|
||
async def return_step(context: StepContext) -> StepOutcome: | ||
# NOTE: This activity is only for returning immediately, so we just evaluate the expression | ||
# Hence, it's a local activity and SHOULD NOT fail | ||
try: | ||
assert isinstance(context.current_step, ReturnStep) | ||
|
||
exprs: dict[str, str] = context.current_step.return_ | ||
output = simple_eval_dict(exprs, values=context.model_dump()) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
except BaseException as e: | ||
logging.error(f"Error in log_step: {e}") | ||
return StepOutcome(error=str(e)) | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported return_step directly | ||
# They do the same thing, so we dont need to mock the return_step function | ||
mock_return_step = return_step | ||
|
||
return_step = activity.defn(name="return_step")( | ||
return_step if not testing else mock_return_step | ||
) |
48 changes: 48 additions & 0 deletions
48
agents-api/agents_api/activities/task_steps/switch_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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
|
||
from beartype import beartype | ||
from simpleeval import simple_eval | ||
from temporalio import activity | ||
|
||
from ...autogen.openapi_model import SwitchStep | ||
from ...common.protocol.tasks import ( | ||
StepContext, | ||
StepOutcome, | ||
) | ||
from ...env import testing | ||
|
||
|
||
@beartype | ||
async def switch_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, SwitchStep) | ||
|
||
# Assume that none of the cases evaluate to truthy | ||
output: int = -1 | ||
|
||
cases: list[str] = [c.case for c in context.current_step.switch] | ||
|
||
for i, case in enumerate(cases): | ||
result = simple_eval(case, names=context.model_dump()) | ||
|
||
if result: | ||
output = i | ||
break | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
except BaseException as e: | ||
logging.error(f"Error in switch_step: {e}") | ||
return StepOutcome(error=str(e)) | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported switch_step directly | ||
# They do the same thing, so we dont need to mock the switch_step function | ||
mock_switch_step = switch_step | ||
|
||
switch_step = activity.defn(name="switch_step")( | ||
switch_step if not testing else mock_switch_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
25 changes: 25 additions & 0 deletions
25
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from temporalio import activity | ||
|
||
from ...activities.task_steps.utils import simple_eval_dict | ||
from ...autogen.openapi_model import WaitForInputStep | ||
from ...common.protocol.tasks import StepContext, StepOutcome | ||
from ...env import testing | ||
|
||
|
||
async def wait_for_input_step(context: StepContext) -> StepOutcome: | ||
assert isinstance(context.current_step, WaitForInputStep) | ||
|
||
exprs = context.current_step.wait_for_input | ||
output = simple_eval_dict(exprs, values=context.model_dump()) | ||
|
||
result = StepOutcome(output=output) | ||
return result | ||
|
||
|
||
# Note: This is here just for clarity. We could have just imported wait_for_input_step directly | ||
# They do the same thing, so we dont need to mock the wait_for_input_step function | ||
mock_wait_for_input_step = wait_for_input_step | ||
|
||
wait_for_input_step = activity.defn(name="wait_for_input_step")( | ||
wait_for_input_step if not testing else mock_wait_for_input_step | ||
) |
Oops, something went wrong.