dify 迭代组件卡住,无法进行迭代,

u3r8eeie  于 2个月前  发布在  其他
关注(0)|答案(8)|浏览(115)

自检

  • 这仅用于提交错误报告,如果您想提问,请访问 Discussions
  • 我已在 search for existing issues 中搜索了现有问题,包括已关闭的问题。
  • 我确认我使用英文提交此报告(我已阅读并同意 Language Policy )。
  • 请务必使用英文提交问题,否则会被关闭。谢谢!:)
  • 请不要修改此模板 :) 并填写所有必填字段。

Dify版本

0.6.11

云或自托管

重现步骤

将一个llm节点放入迭代节点中,输入列表长度约为20,经过几次迭代后,它卡住了,什么都不做...
以下是卡住超过30分钟的任务:

6次迭代已成功完成:

没有其他迭代在处理...并且最后一个节点中没有任何显示:

✔️预期行为

迭代应完成其输入

❌实际行为

卡住,没有原因,没有输出。

lymgl2op

lymgl2op1#

要解决Dify版本0.6.11(云)中迭代组件在处理大约20个项目输入列表的几次迭代后卡住的问题,您可以尝试以下步骤:

  1. 确保正确的输入格式:确保输入列表正确地格式化为数组。迭代节点需要输入为列表格式。
  2. 检查模型推理能力:参数提取和迭代的有效性可能受到模型推理能力的影响的。使用具有更强推理能力的模型并在指令中添加示例可以提高结果。
  3. 调试和预览:完成调试并预览工作流以识别配置中的任何潜在问题。
  4. 流式输出配置:在迭代节点内配置一个直接回复节点,以在每次迭代后实现流式输出。这有助于监控进度并确定它在哪里卡住。
    以下是迭代节点的详细配置示例:
1. Configure the story title (title) and outline (outline) in the **Start Node**.

2. Use a **Jinja-2 Template Node** to convert the story title and outline into complete text.

3. Use a **Parameter Extraction Node** to convert the story text into an array (Array) structure. The parameter to extract is `sections`, and the parameter type is `Array[Object]`.

4. Use the array-formatted story outline as the input for the iteration node and process it within the iteration node using an **LLM Node**.

5. Configure a **Direct Reply Node** inside the iteration node to achieve streaming output after each iteration.

6. Complete debugging and preview.

如果问题仍然存在,请考虑将输入列表拆分为较小的部分并分别处理它们,以确定是否某个特定项目导致了问题1(https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/iteration.md)。

  • 要继续与Dosu交谈,请提及@dosu。*
r8uurelv

r8uurelv2#

three hour passed, and it is still get stucked, would you please add a "timeout" or something like to make components more robust?

cx6n0qe3

cx6n0qe33#

要为Dify 0.6.11(云端)版本的Iteration组件添加"超时"功能,以防止工作流无限期地卡住,您可以利用handleSend函数中现有的超时机制。代码已经包含了一个在1分钟后停止工作流的功能,如果它还没有完成的话。以下是相关代码片段:

const handleSend = async () => {
// ... other code ...

let isEnd = false;
let isTimeout = false;
(async () => {
await sleep(1000 * 60); // 1min timeout
if (!isEnd) {
setRespondingFalse();
onCompleted(getCompletionRes(), taskId, false);
isTimeout = true;
}
})();

if (isWorkflow) {
// ... workflow handling code ...
} else {
// ... non-workflow handling code ...
}
}

这段代码片段已经实现了等待1分钟(1000 * 60毫秒)的功能,然后在工作流未完成的情况下停止它。如果工作流在超时时间内完成,isEnd标志将被设置为true,阻止超时逻辑执行。

此外,workflow_iteration_cycle_manage.py文件中的WorkflowIterationCycleManage类提供了处理迭代状态和异常的机制,这对于管理工作流迭代和确保它们不会无限期地卡住非常有用。以下是如何处理迭代异常的示例:

def _handle_iteration_exception(self, task_id: str, error: str) -> Generator[IterationNodeCompletedStreamResponse, None, None]:
"""
Handle iteration exception
"""
if not self._iteration_state or not self._iteration_state.current_iterations:
return

for node_id, current_iteration in self._iteration_state.current_iterations.items():
    workflow_node_execution: WorkflowNodeExecution = db.session.query(WorkflowNodeExecution).filter(
        WorkflowNodeExecution.id == current_iteration.node_execution_id
    ).first()

    workflow_node_execution.status = WorkflowNodeExecutionStatus.FAILED.value
    workflow_node_execution.error = error
    workflow_node_execution.elapsed_time = time.perf_counter() - current_iteration.started_at

    db.session.commit()
    db.session.close()

    yield IterationNodeCompletedStreamResponse(
        task_id=task_id,
        workflow_run_id=self._task_state.workflow_run_id,
        data=IterationNodeCompletedStreamResponse.Data(
            id=node_id,
            node_id=node_id,
            node_type=NodeType.ITERATION.value,
            title=current_iteration.node_data.title,
            outputs={},
            created_at=int(time.time()),
            extras={},
            inputs=current_iteration.inputs,
            status=WorkflowNodeExecutionStatus.FAILED,
            error=error,
            elapsed_time=time.perf_counter() - current_iteration.started_at,
            total_tokens=current_iteration.total_tokens,
            execution_metadata={
                'total_tokens': current_iteration.total_tokens,
            },
            finished_at=int(time.time()),
            steps=current_iteration.current_index
        )
    )

此函数确保如果迭代遇到错误,它将得到适当的处理并标记为失败,从而防止工作流卡住。

  • 要继续与Dosu交谈,请提及@dosu。*
jq6vz3qz

jq6vz3qz4#

你能提供容器的日志吗?

lp0sw83n

lp0sw83n5#

你能提供容器的日志吗?
不能,我不能。我正在使用云版本。

khbbv19g

khbbv19g6#

你能提供容器的日志吗?
我遇到了同样的问题,工作日志如下:

api_1                    | workflow_run_id
api_1                    |   Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
api_1                    |     For further information visit https://errors.pydantic.dev/2.7/v/string_type
api_1                    | [2024-06-30 08:49:01 +0000] [78] [ERROR] Error handling request /console/api/apps/0320f105-33d6-4ee5-9f20-6a25a96711b2/workflows/draft/iteration/nodes/1719727405937/run
api_1                    | Traceback (most recent call last):
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/gunicorn/workers/base_async.py", line 55, in handle
api_1                    |     self.handle_request(listener_name, req, client, addr)
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/gunicorn/workers/ggevent.py", line 128, in handle_request
api_1                    |     super().handle_request(listener_name, req, sock, addr)
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/gunicorn/workers/base_async.py", line 115, in handle_request
api_1                    |     for item in respiter:
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/werkzeug/wsgi.py", line 256, in __next__
api_1                    |     return self._next()
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/werkzeug/wrappers/response.py", line 32, in _iter_encoded
api_1                    |     for item in iterable:
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/flask/helpers.py", line 113, in generator
api_1                    |     yield from gen
api_1                    |   File "/app/api/libs/helper.py", line 162, in generate
api_1                    |     yield from response
api_1                    |   File "/app/api/core/app/apps/base_app_generate_response_converter.py", line 28, in _generate
api_1                    |     for chunk in cls.convert_stream_full_response(response):
api_1                    |   File "/app/api/core/app/apps/workflow/generate_response_converter.py", line 45, in convert_stream_full_response
api_1                    |     for chunk in stream_response:
api_1                    |   File "/app/api/core/app/apps/workflow/generate_task_pipeline.py", line 159, in _to_stream_response
api_1                    |     yield WorkflowAppStreamResponse(
api_1                    |   File "/app/api/.venv/lib/python3.10/site-packages/pydantic/main.py", line 176, in __init__
api_1                    |     self.__pydantic_validator__.validate_python(data, self_instance=self)
api_1                    | pydantic_core._pydantic_core.ValidationError: 1 validation error for WorkflowAppStreamResponse
api_1                    | workflow_run_id
api_1                    |   Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
api_1                    |     For further information visit https://errors.pydantic.dev/2.7/v/string_type

输入:

迭代:

46qrfjad

46qrfjad7#

在这里也遇到了同样的问题。当实际迭代运行时,迭代只是卡住/超时。当你用迭代中的一个项目进行调试时,它对第一个项目有效,但在第二个项目上卡住。

cigdeys3

cigdeys38#

@takatost@crazywoola 这里是工作流日志,其中迭代节点执行了3/6次,突然出现“读取操作超时”的错误。这种情况可能在第一次、第二次或第三次迭代中发生,具体取决于节点执行所需的时间。看起来像Jina Reader、Firecrawl等工具可能会出现这种情况。

也许解决方案是增加工作流运行时配置环境?

相关问题