Source code for agentscope.web.workstation.workflow_utils
# -*- coding: utf-8 -*-"""Workflow node utils."""
[docs]defis_callable_expression(s:str)->bool:"""Check a expression whether a callable expression"""try:# Do not detect exp like thisifsin["input","print"]:returnFalseresult=eval(s)returncallable(result)exceptException:returnFalse
[docs]defkwarg_converter(kwargs:dict)->str:"""Convert a kwarg dict to a string."""kwarg_parts=[]forkey,valueinkwargs.items():ifis_callable_expression(value):kwarg_parts.append(f"{key}={value}")else:kwarg_parts.append(f"{key}={repr(value)}")return", ".join(kwarg_parts)
[docs]defdeps_converter(dep_vars:list)->str:"""Convert a dep_vars list to a string."""returnf"[{', '.join(dep_vars)}]"
[docs]defdict_converter(dictionary:dict)->str:"""Convert a dictionary to a string."""result_parts=[]forkey,valueindictionary.items():result_parts.append(f'"{key}": {value}')return"{"+", ".join(result_parts)+"}"