modelscope / agentscope

Start building LLM-empowered multi-agent applications in an easier way.
https://doc.agentscope.io/
Apache License 2.0
5.15k stars 313 forks source link

[优化改进]:WhileLoopPipeline的 #409

Open Jou0us opened 2 months ago

Jou0us commented 2 months ago

def whilelooppipeline( loop_body_operators: Operators, conditionfunc: Callable[[int, Any], bool] = lambda , __: False, x: Optional[dict] = None, ) -> dict: """Functional version of WhileLoopPipeline.

Args:
    loop_body_operators (`Operators`): Operators executed as the body of
        the loop.
    condition_func (`Callable[[int, Any], bool]`, optional): A function
        that determines whether to continue executing the loop body based
        on the current loop number and output of the loop_body_operator,
        defaults to `lambda _,__: False`
    x (`Optional[dict]`, defaults to `None`):
        The input dictionary.

Returns:
    `dict`: the output dictionary.
"""
i = 0
while condition_func(i, x):
    # loop body
    x = _operators(loop_body_operators, x)
    # check condition
    i += 1
return x  # type: ignore[return-value]

这里的i感觉没什么意义,对于外面函数的定义还有影响,不看源码的话,会导致函数的定义失败的状态 文档也没有说明

DavdGao commented 2 months ago

Thanks for your attention. For whilelooppipeline, we are considering to abandon this feature for the difficulity to write a lambda function. Currently, we think directly coding a while loop is more simple and user-friendly.