Skip to content

Commit 063dc6f

Browse files
Merge remote-tracking branch 'upstream/v2' into PR/fix-1
2 parents ffb3e08 + 943e515 commit 063dc6f

37 files changed

Lines changed: 272 additions & 175 deletions

File tree

.github/workflows/build-and-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
inputs:
88
dockerImageTag:
99
description: 'Image Tag'
10-
default: 'v2.9.0-dev'
10+
default: 'v2.10.0-dev'
1111
required: true
1212
dockerImageTagWithLatest:
1313
description: '是否发布latest tag(正式发版时选择,测试版本切勿选择)'

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def get_history_message(history_chat_record, dialogue_number, dialogue_type, run
383383
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
384384
for message in history_message:
385385
if isinstance(message.content, str):
386-
message.content = re.sub('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
386+
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
387387
return history_message
388388

389389
def generate_prompt_question(self, prompt):

apps/application/flow/step_node/application_node/impl/base_application_node.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,14 @@ def reset_application_node_dict(application_node_dict, runtime_node_id, node_dat
132132
application_node = application_node_dict[key]
133133
if application_node.get('runtime_node_id') == runtime_node_id:
134134
content: str = application_node.get('content')
135-
match = re.search('<form_rander>.*?</form_rander>', content)
135+
match = re.search(r'<form_rander>.*?<\/form_rander>', content, flags=re.DOTALL)
136136
if match:
137137
form_setting_str = match.group().replace('<form_rander>', '').replace('</form_rander>', '')
138138
form_setting = json.loads(form_setting_str)
139139
form_setting['is_submit'] = True
140140
form_setting['form_data'] = node_data
141141
value = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
142-
res = re.sub('<form_rander>.*?</form_rander>',
143-
'${value}', content)
142+
res = re.sub(r'<form_rander>.*?<\/form_rander>', '${value}', content, flags=re.DOTALL)
144143
application_node['content'] = res.replace('${value}', value)
145144
except Exception as e:
146145
maxkb_logger.warning(f'reset_application_node_dict error: {e}', exc_info=True)

apps/application/flow/step_node/intent_node/impl/base_intent_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_history_message(history_chat_record, dialogue_number):
133133

134134
for message in history_message:
135135
if isinstance(message.content, str):
136-
message.content = re.sub('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
136+
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
137137
return history_message
138138

139139
def build_system_prompt(self) -> str:

apps/application/flow/step_node/loop_node/impl/base_loop_node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ def loop(workflow_manage_new_instance, node: INode, generate_loop):
216216
def get_tokens(loop_node_data):
217217
message_tokens = 0
218218
answer_tokens = 0
219-
for details in loop_node_data:
220-
message_tokens += sum([row.get('message_tokens') for row in details.values() if
219+
for details in (loop_node_data or {}):
220+
message_tokens += sum([row.get('message_tokens') or 0 for row in details.values() if
221221
'message_tokens' in row and row.get('message_tokens') is not None])
222-
answer_tokens += sum([row.get('answer_tokens') for row in details.values() if
222+
answer_tokens += sum([row.get('answer_tokens') or 0 for row in details.values() if
223223
'answer_tokens' in row and row.get('answer_tokens') is not None])
224224
return {'message_tokens': message_tokens, 'answer_tokens': answer_tokens}
225225

apps/application/flow/step_node/parameter_extraction_node/impl/base_parameter_extraction_node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,24 @@ def generate_content(input_variable, variable_list):
6262
return value
6363

6464

65-
def json_loads(response, expected_fields):
65+
def json_loads(response, variable_list):
6666
if not response or not isinstance(response, str):
67-
return {field: None for field in expected_fields}
67+
return generate_example(variable_list)
6868

6969
cleaned = response.strip()
7070

7171
extraction_strategies = [
7272
lambda: json.loads(cleaned),
7373
lambda: json.loads(re.search(r'```(?:json)?\s*(\{.*?\})\s*```', cleaned, re.DOTALL).group(1)),
74-
lambda: json.loads(re.search(r'(\{[\s\S]*\})', cleaned).group(1)),
74+
lambda: json.loads(re.search(r'(\{.*\})', cleaned, flags=re.DOTALL).group(1)),
7575
]
7676
for strategy in extraction_strategies:
7777
try:
7878
result = strategy()
7979
return result
8080
except:
8181
continue
82-
return generate_example(expected_fields)
82+
return generate_example(variable_list)
8383

8484

8585
class BaseParameterExtractionNode(IParameterExtractionNode):

apps/application/flow/step_node/question_node/impl/base_question_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_history_message(history_chat_record, dialogue_number):
130130
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
131131
for message in history_message:
132132
if isinstance(message.content, str):
133-
message.content = re.sub('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
133+
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
134134
return history_message
135135

136136
def generate_prompt_question(self, prompt):

apps/application/flow/step_node/tool_lib_node/impl/base_tool_lib_node.py

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,24 @@ def get_field_value(debug_field_list, name, is_required):
5858

5959

6060
def valid_reference_value(_type, value, name):
61-
try:
62-
if _type == 'int':
63-
instance_type = int | float
64-
elif _type == 'boolean':
65-
instance_type = bool
66-
elif _type == 'float':
67-
instance_type = float | int
68-
elif _type == 'dict':
69-
value = json.loads(value) if isinstance(value, str) else value
70-
instance_type = dict
71-
elif _type == 'array':
72-
value = json.loads(value) if isinstance(value, str) else value
73-
instance_type = list
74-
elif _type == 'string':
75-
instance_type = str
76-
else:
77-
raise Exception(_(
78-
'Field: {name} Type: {_type} Value: {value} Unsupported types'
79-
).format(name=name, _type=_type, value=value))
80-
except:
61+
if _type == 'int':
62+
instance_type = int | float
63+
elif _type == 'boolean':
64+
instance_type = bool
65+
elif _type == 'float':
66+
instance_type = float | int
67+
elif _type == 'dict':
68+
value = json.loads(value) if isinstance(value, str) else value
69+
instance_type = dict
70+
elif _type == 'array':
71+
value = json.loads(value) if isinstance(value, str) else value
72+
instance_type = list
73+
elif _type == 'string':
74+
instance_type = str
75+
else:
76+
maxkb_logger.error(_(
77+
'Field: {name} Type: {_type} Value: {value} Unsupported this type'
78+
).format(name=name, _type=_type, value=value))
8179
return value
8280
if not isinstance(value, instance_type):
8381
raise Exception(_(

apps/application/flow/step_node/tool_node/impl/base_tool_node.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from application.flow.i_step_node import NodeResult
1616
from application.flow.step_node.tool_node.i_tool_node import IToolNode
1717
from common.utils.common import common_convert_value
18+
from common.utils.logger import maxkb_logger
1819
from common.utils.tool_code import ToolExecutor
1920
from maxkb.const import CONFIG
2021

@@ -33,26 +34,24 @@ def write_context(step_variable: Dict, global_variable: Dict, node, workflow):
3334

3435

3536
def valid_reference_value(_type, value, name):
36-
try:
37-
if _type == 'int':
38-
instance_type = int | float
39-
elif _type == 'boolean':
40-
instance_type = bool
41-
elif _type == 'float':
42-
instance_type = float | int
43-
elif _type == 'dict':
44-
value = json.loads(value) if isinstance(value, str) else value
45-
instance_type = dict
46-
elif _type == 'array':
47-
value = json.loads(value) if isinstance(value, str) else value
48-
instance_type = list
49-
elif _type == 'string':
50-
instance_type = str
51-
else:
52-
raise Exception(_(
53-
'Field: {name} Type: {_type} Value: {value} Unsupported types'
54-
).format(name=name, _type=_type, value=value))
55-
except:
37+
if _type == 'int':
38+
instance_type = int | float
39+
elif _type == 'boolean':
40+
instance_type = bool
41+
elif _type == 'float':
42+
instance_type = float | int
43+
elif _type == 'dict':
44+
value = json.loads(value) if isinstance(value, str) else value
45+
instance_type = dict
46+
elif _type == 'array':
47+
value = json.loads(value) if isinstance(value, str) else value
48+
instance_type = list
49+
elif _type == 'string':
50+
instance_type = str
51+
else:
52+
maxkb_logger.error(_(
53+
'Field: {name} Type: {_type} Value: {value} Unsupported this type'
54+
).format(name=name, _type=_type, value=value))
5655
return value
5756
if not isinstance(value, instance_type):
5857
raise Exception(_(

apps/application/flow/workflow_manage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def run_block(self, language='zh'):
236236
@return: 结果
237237
"""
238238
try:
239+
self.params['stream'] = True
239240
self.run_chain_async(None, None, language)
240241
while self.is_run():
241242
pass

0 commit comments

Comments
 (0)