Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions apps/application/flow/compare/contain_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ def support(self, node_id, fields: List[str], source_value, compare, target_valu
return True

def compare(self, source_value, compare, target_value):
target_value = str(target_value)

if isinstance(source_value, str):
return str(target_value) in source_value
return target_value in source_value
elif isinstance(source_value, list):
return any([str(item) == str(target_value) for item in source_value])
for item in source_value:
if str(item) == target_value:
return True
return False
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为 list 时,性能优化了下。

else:
return str(target_value) in str(source_value)
return target_value in str(source_value)
11 changes: 8 additions & 3 deletions apps/application/flow/compare/not_contain_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ def support(self, node_id, fields: List[str], source_value, compare, target_valu
return True

def compare(self, source_value, compare, target_value):
target_value = str(target_value)

if isinstance(source_value, str):
return str(target_value) not in source_value
return target_value not in source_value
elif isinstance(source_value, list):
return not any([str(item) == str(target_value) for item in source_value])
for item in source_value:
if str(item) == target_value:
return False
return True
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上:为 list 时,性能优化了下。

else:
return str(target_value) not in str(source_value)
return target_value not in str(source_value)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from application.flow.step_node.tool_lib_node.i_tool_lib_node import IToolLibNode
from common.database_model_manage.database_model_manage import DatabaseModelManage
from common.exception.app_exception import AppApiException
from common.utils.common import common_convert_value
from common.utils.logger import maxkb_logger
from common.utils.rsa_util import rsa_long_decrypt
from common.utils.tool_code import ToolExecutor
Expand Down Expand Up @@ -107,25 +108,7 @@ def convert_value(name: str, value, _type, is_required, source, node):
return value
try:
value = node.workflow_manage.generate_prompt(value)
if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value
return common_convert_value(_type, value)
except Exception as e:
raise Exception(
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
Expand Down
21 changes: 2 additions & 19 deletions apps/application/flow/step_node/tool_node/impl/base_tool_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from application.flow.i_step_node import NodeResult
from application.flow.step_node.tool_node.i_tool_node import IToolNode
from common.utils.common import common_convert_value
from common.utils.tool_code import ToolExecutor
from maxkb.const import CONFIG

Expand Down Expand Up @@ -82,25 +83,7 @@ def convert_value(name: str, value, _type, is_required, source, node):
return value
try:
value = node.workflow_manage.generate_prompt(value)
if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value
return common_convert_value(_type, value)
except Exception as e:
raise Exception(
_('Field: {name} Type: {_type} Value: {value} Type error').format(name=name, _type=_type,
Expand Down
29 changes: 29 additions & 0 deletions apps/common/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import hashlib
import io
import json
import mimetypes
import pickle
import random
Expand Down Expand Up @@ -360,3 +361,31 @@ def is_valid_uuid(uuid_string):
return str(uuid_obj) == uuid_string
except ValueError:
return False

def common_convert_value(_type, value):
if value is None:
return None

if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
if isinstance(value, dict):
return value
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 已经是 dict 时,直接 return,否则 json.loads(value) 会报错

v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
if isinstance(value, list):
return value
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 已经是 list 时,直接 return,否则 json.loads(value) 会报错

v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value
22 changes: 2 additions & 20 deletions apps/tools/serializers/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from common.exception.app_exception import AppApiException
from common.field.common import UploadedImageField
from common.result import result
from common.utils.common import get_file_content, generate_uuid, bytes_to_uploaded_file
from common.utils.common import get_file_content, generate_uuid, bytes_to_uploaded_file, common_convert_value
from common.utils.logger import maxkb_logger
from common.utils.rsa_util import rsa_long_decrypt, rsa_long_encrypt
from common.utils.tool_code import ToolExecutor
Expand Down Expand Up @@ -533,25 +533,7 @@ def convert_value(name: str, value: str, _type: str, is_required: bool):
if not is_required and (value is None or (isinstance(value, str) and len(value.strip()) == 0)):
return None
try:
if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value
return common_convert_value(_type, value)
except Exception as e:
raise AppApiException(500, _('Field: {name} Type: {type} Value: {value} Type conversion error').format(
name=name, type=_type, value=value
Expand Down
29 changes: 2 additions & 27 deletions apps/trigger/handler/impl/task/tool_task/base_tool_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import uuid_utils.compat as uuid
from django.db.models import QuerySet
from django.utils.translation import gettext as _

from common.utils.common import common_convert_value
from common.utils.logger import maxkb_logger
from common.utils.rsa_util import rsa_long_decrypt
from common.utils.tool_code import ToolExecutor
Expand Down Expand Up @@ -43,38 +43,13 @@ def get_field_value(value, kwargs):
return get_reference(value.get('value'), kwargs)


def _convert_value(_type, value):
if value is None:
return None

if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value


def get_tool_execute_parameters(input_field_list, parameter_setting, kwargs):
type_map = {f.get("name"): f.get("type") for f in (input_field_list or []) if f.get("name")}

parameters = {}
for key, value in parameter_setting.items():
raw = get_field_value(value, kwargs)
parameters[key] = _convert_value(type_map.get(key), raw)
parameters[key] = common_convert_value(type_map.get(key), raw)
return parameters


Expand Down
31 changes: 2 additions & 29 deletions apps/trigger/handler/impl/task/tool_task/workflow_tool_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
@date:2026/3/27 18:47
@desc:
"""
import json
import time
import traceback

import uuid_utils.compat as uuid
from django.db.models import QuerySet
from django.utils.translation import gettext as _

from application.flow.common import WorkflowMode, Workflow
from application.flow.i_step_node import ToolWorkflowPostHandler, get_tool_workflow_state
from application.serializers.common import ToolExecute
from common.utils.common import common_convert_value
from common.utils.logger import maxkb_logger
from common.utils.tool_code import ToolExecutor
from knowledge.models.knowledge_action import State
Expand Down Expand Up @@ -44,40 +43,14 @@ def get_field_value(value, kwargs):
else:
return get_reference(value.get('value'), kwargs)


def _convert_value(_type, value):
if value is None:
return None

if _type == 'int':
return int(value)
if _type == 'boolean':
if isinstance(value, str) and value.lower() in ('false', '0', '[]', ''):
return False
return bool(value)
if _type == 'float':
return float(value)
if _type == 'dict':
v = json.loads(value)
if isinstance(v, dict):
return v
raise Exception(_('type error'))
if _type == 'array':
v = json.loads(value)
if isinstance(v, list):
return v
raise Exception(_('type error'))
return value


def get_tool_execute_parameters(input_field_list, parameter_setting, kwargs):
type_map = {f.get("name"): f.get("type") for f in (input_field_list or []) if f.get("name")}

parameters = {}
if parameter_setting:
for key, value in parameter_setting.items():
raw = get_field_value(value, kwargs)
parameters[key] = _convert_value(type_map.get(key), raw)
parameters[key] = common_convert_value(type_map.get(key), raw)
return parameters


Expand Down
Loading