fix: Infinite loop increases maximum loop count limit (#4088)
parent
9b00b857bf
commit
4242c776ed
|
|
@ -15,6 +15,10 @@ from application.flow.step_node.loop_node.i_loop_node import ILoopNode
|
||||||
from application.flow.tools import Reasoning
|
from application.flow.tools import Reasoning
|
||||||
from application.models import ChatRecord
|
from application.models import ChatRecord
|
||||||
from common.handle.impl.response.loop_to_response import LoopToResponse
|
from common.handle.impl.response.loop_to_response import LoopToResponse
|
||||||
|
from maxkb.const import CONFIG
|
||||||
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
|
max_loop_count = (CONFIG.get("MAX_LOOP_COUNT") or 1000)
|
||||||
|
|
||||||
|
|
||||||
def _is_interrupt_exec(node, node_variable: Dict, workflow_variable: Dict):
|
def _is_interrupt_exec(node, node_variable: Dict, workflow_variable: Dict):
|
||||||
|
|
@ -127,6 +131,7 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
|
||||||
current_index = node.context.get("current_index") or 0
|
current_index = node.context.get("current_index") or 0
|
||||||
node_params = node.node_params
|
node_params = node.node_params
|
||||||
start_node_id = node_params.get('child_node', {}).get('runtime_node_id')
|
start_node_id = node_params.get('child_node', {}).get('runtime_node_id')
|
||||||
|
loop_type = node_params.get('loop_type')
|
||||||
start_node_data = None
|
start_node_data = None
|
||||||
chat_record = None
|
chat_record = None
|
||||||
child_node = None
|
child_node = None
|
||||||
|
|
@ -138,6 +143,8 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
|
||||||
details=loop_node_data[current_index])
|
details=loop_node_data[current_index])
|
||||||
|
|
||||||
for item, index in generate_loop(current_index):
|
for item, index in generate_loop(current_index):
|
||||||
|
if 0 < max_loop_count <= index - current_index and loop_type == 'LOOP':
|
||||||
|
raise Exception(_('Exceeding the maximum number of cycles'))
|
||||||
"""
|
"""
|
||||||
指定次数循环
|
指定次数循环
|
||||||
@return:
|
@return:
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ ENV MAXKB_VERSION="${DOCKER_IMAGE_TAG} (build at ${BUILD_AT}, commit: ${GITHUB_C
|
||||||
MAXKB_LOCAL_MODEL_HOST=127.0.0.1 \
|
MAXKB_LOCAL_MODEL_HOST=127.0.0.1 \
|
||||||
MAXKB_LOCAL_MODEL_PORT=11636 \
|
MAXKB_LOCAL_MODEL_PORT=11636 \
|
||||||
MAXKB_LOCAL_MODEL_PROTOCOL=http \
|
MAXKB_LOCAL_MODEL_PROTOCOL=http \
|
||||||
|
MAXKB_MAX_LOOP_COUNT=1000 \
|
||||||
PIP_TARGET=/opt/maxkb/python-packages
|
PIP_TARGET=/opt/maxkb/python-packages
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,8 +85,8 @@ export class WorkFlowInstance {
|
||||||
const base_node_list = this.nodes.filter((item) => item.id === WorkflowType.Base)
|
const base_node_list = this.nodes.filter((item) => item.id === WorkflowType.Base)
|
||||||
return base_node_list[0]
|
return base_node_list[0]
|
||||||
}
|
}
|
||||||
extis_break_node() {
|
exist_break_node() {
|
||||||
return this.nodes.some((item) => item.id === WorkflowType.LoopBreakNode)
|
return this.nodes.some((item) => item.type === WorkflowType.LoopBreakNode)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 校验工作流
|
* 校验工作流
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ const validate = () => {
|
||||||
const loop_node = props.nodeModel.graphModel.getNodeModelById(loop_node_id)
|
const loop_node = props.nodeModel.graphModel.getNodeModelById(loop_node_id)
|
||||||
try {
|
try {
|
||||||
workflow.is_loop_valid()
|
workflow.is_loop_valid()
|
||||||
if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.extis_break_node()) {
|
if (loop_node.properties.node_data.loop_type == 'LOOP' && !workflow.exist_break_node()) {
|
||||||
return Promise.reject({
|
return Promise.reject({
|
||||||
node: loop_node,
|
node: loop_node,
|
||||||
errMessage: t('views.applicationWorkflow.validate.loopNodeBreakNodeRequired'),
|
errMessage: t('views.applicationWorkflow.validate.loopNodeBreakNodeRequired'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue