From 3a7077b48affd448730a230e1095592880f90cae Mon Sep 17 00:00:00 2001 From: Manthan Gupta <42516515+manthanguptaa@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:29:40 +0530 Subject: [PATCH] Feat/continue workflow playground (#1552) ## Description 1. Adds ability to continue a workflow run 2. Fixes getting default value of run function param when the type is of FieldInfo class --------- Co-authored-by: Ashpreet Bedi Co-authored-by: Dirk Brand <51947788+dirkbrnd@users.noreply.github.com> --- phi/playground/router.py | 7 ++++++- phi/playground/schemas.py | 1 + phi/workflow/workflow.py | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/phi/playground/router.py b/phi/playground/router.py index 0cf81bdba..5023755bb 100644 --- a/phi/playground/router.py +++ b/phi/playground/router.py @@ -553,8 +553,13 @@ async def run_workflow(workflow_id: str, body: WorkflowRunRequest): if workflow is None: raise HTTPException(status_code=404, detail="Workflow not found") + if body.session_id is not None: + logger.debug(f"Continuing session: {body.session_id}") + else: + logger.debug("Creating new session") + # Create a new instance of this workflow - new_workflow_instance = workflow.deep_copy(update={"workflow_id": workflow_id}) + new_workflow_instance = workflow.deep_copy(update={"workflow_id": workflow_id, "session_id": body.session_id}) new_workflow_instance.user_id = body.user_id # Return based on the response type diff --git a/phi/playground/schemas.py b/phi/playground/schemas.py index 7eb470ea4..660e210a1 100644 --- a/phi/playground/schemas.py +++ b/phi/playground/schemas.py @@ -68,3 +68,4 @@ class WorkflowRenameRequest(BaseModel): class WorkflowRunRequest(BaseModel): input: Dict[str, Any] user_id: Optional[str] = None + session_id: Optional[str] = None diff --git a/phi/workflow/workflow.py b/phi/workflow/workflow.py index 668930813..dccab8dac 100644 --- a/phi/workflow/workflow.py +++ b/phi/workflow/workflow.py @@ -321,7 +321,9 @@ def __init__(self, **data): self._run_parameters = { name: { "name": name, - "default": param.default if param.default is not inspect.Parameter.empty else None, + "default": param.default.default + if hasattr(param.default, "__class__") and param.default.__class__.__name__ == "FieldInfo" + else (param.default if param.default is not inspect.Parameter.empty else None), "annotation": ( param.annotation.__name__ if hasattr(param.annotation, "__name__")