Skip to content

Commit

Permalink
Make workflow compiler return code string (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrayraykk authored Apr 25, 2024
1 parent 4f1a5d0 commit 4a694c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/agentscope/web/workstation/workflow_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def run(self) -> None:
else:
raise ValueError("Too many predecessors!")

def compile(self, compiled_filename: str) -> None:
def compile(self, compiled_filename: str = "") -> str:
"""Compile DAG to a runnable python code"""

def format_python_code(code: str) -> str:
Expand Down Expand Up @@ -142,9 +142,13 @@ def format_python_code(code: str) -> str:
f"'__main__':\n main()\n"
)

# Write the script to file
with open(compiled_filename, "w", encoding="utf-8") as file:
file.write(format_python_code(script))
formatted_code = format_python_code(script)

if len(compiled_filename) > 0:
# Write the script to file
with open(compiled_filename, "w", encoding="utf-8") as file:
file.write(formatted_code)
return formatted_code

# pylint: disable=R0912
def add_as_node(
Expand Down
1 change: 0 additions & 1 deletion src/agentscope/web/workstation/workflow_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ def __init__(
self.pipeline = self.dep_opts[0]
self.participants = get_all_agents(self.pipeline)
self.participants_var = get_all_agents(self.pipeline, return_var=True)
print(self.participants_var)

def __call__(self, x: dict = None) -> dict:
with msghub(self.participants, announcement=self.announcement):
Expand Down

0 comments on commit 4a694c5

Please sign in to comment.