Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fc5b607
perf: system prompt double-generating
wangliang181230 Mar 23, 2026
ec3d5fa
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 24, 2026
b09d0ca
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 25, 2026
134ed9a
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 25, 2026
75f239d
fix: Fix some minor problem
wangliang181230 Mar 25, 2026
b9a02b1
fix
wangliang181230 Mar 25, 2026
27fc513
小调整。
wangliang181230 Mar 25, 2026
afacd7f
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 26, 2026
46218ef
文件处理,使用 with ... as file 语法,避免文件未关闭。
wangliang181230 Mar 26, 2026
2e8dced
修正错误字符串
wangliang181230 Mar 26, 2026
b3e7b65
fix bugs: invalid regex escape sequences, and resource leaks
wangliang181230 Mar 26, 2026
078bda5
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 26, 2026
ad2aff2
fix bugs: invalid regex escape sequences, and resource leaks
wangliang181230 Mar 26, 2026
fbbdb70
撤回对正则的修正。
wangliang181230 Mar 26, 2026
1a72ba2
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 27, 2026
66ccc3a
operation
wangliang181230 Mar 27, 2026
8b94350
小调整
wangliang181230 Mar 27, 2026
418ac71
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 27, 2026
d4527de
小调整
wangliang181230 Mar 27, 2026
2817aee
Merge remote-tracking branch 'upstream/v2' into perf
wangliang181230 Mar 27, 2026
2feaa9a
小调整
wangliang181230 Mar 27, 2026
5ae0a84
revert
wangliang181230 Mar 27, 2026
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
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def execute(self, message_list: List[BaseMessage],
mcp_output_enable=True,
**kwargs):
chat_model = get_model_instance_by_model_workspace_id(model_id, workspace_id,
**model_params_setting) if model_id is not None else None
**(model_params_setting or {})) if model_id is not None else None
if stream:
return self.execute_stream(message_list, chat_id, problem_text, post_response_handler, chat_model,
paragraph_list,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def handle_variables(self, tool_params):
tool_params[k] = self.workflow_manage.generate_prompt(tool_params[k])
if type(v) == dict:
self.handle_variables(v)
if (type(v) == list) and (type(v[0]) == str):
if (type(v) == list) and len(v) > 0 and (type(v[0]) == str):
tool_params[k] = self.get_reference_content(v)
return tool_params

Expand All @@ -479,7 +479,7 @@ def generate_prompt_question(self, prompt):

def generate_message_list(self, system: str, prompt: str, history_message):
if system is not None and len(system) > 0:
return [SystemMessage(self.workflow_manage.generate_prompt(system)), *history_message,
return [SystemMessage(system), *history_message,
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.

此方法调用前,已经执行过,无需重复执行。

HumanMessage(self.workflow_manage.generate_prompt(prompt))]
else:
return [*history_message, HumanMessage(self.workflow_manage.generate_prompt(prompt))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def generate_prompt_question(self, prompt):

def generate_message_list(self, system: str, prompt: str, history_message):
if system is not None and len(system) > 0:
return [SystemMessage(self.workflow_manage.generate_prompt(system)), *history_message,
return [SystemMessage(system), *history_message,
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.

此方法调用前,已经执行过,无需重复执行。

HumanMessage(self.workflow_manage.generate_prompt(prompt))]
else:
return [*history_message, HumanMessage(self.workflow_manage.generate_prompt(prompt))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def execute(self, tool_lib_id, input_field_list, **kwargs) -> NodeResult:
def tool_exec_record(self, tool_lib, all_params):
task_record_id = uuid.uuid7()
start_time = time.time()
filtered_args = all_params
Copy link
Copy Markdown
Contributor Author

@wangliang181230 wangliang181230 Mar 25, 2026

Choose a reason for hiding this comment

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

except 代码段中在用。

try:
# 过滤掉 tool_init_params 中的参数
tool_init_params = json.loads(rsa_long_decrypt(tool_lib.init_params)) if tool_lib.init_params else {}
Expand All @@ -258,8 +259,6 @@ def tool_exec_record(self, tool_lib, all_params):
k: v for k, v in all_params.items()
if k not in tool_init_params
}
else:
filtered_args = all_params
ToolRecord(
id=task_record_id,
workspace_id=tool_lib.workspace_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class BaseVariableAggregationNode(IVariableAggregation):

def save_context(self, details, workflow_manage):
for key, value in details.get('result').items():
self.context['key'] = value
self.context[key] = value
self.context['result'] = details.get('result')
self.context['strategy'] = details.get('strategy')
self.context['group_list'] = details.get('group_list')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,23 @@ def execute(self, variable_list, **kwargs) -> NodeResult:
result_list = []
is_chat = False
for variable in variable_list:
if 'fields' not in variable:
if not variable.get('fields'):
continue

if 'global' == variable['fields'][0]:
result = self.handle(variable, self.global_evaluation)
result_list.append(result)
if 'chat' == variable['fields'][0]:
elif 'chat' == variable['fields'][0]:
result = self.handle(variable, self.chat_evaluation)
result_list.append(result)
is_chat = True
if 'loop' == variable['fields'][0]:
elif 'loop' == variable['fields'][0]:
result = self.handle(variable, self.loop_evaluation)
result_list.append(result)
if 'output' == variable['fields'][0]:
elif 'output' == variable['fields'][0]:
result = self.handle(variable, self.out_evaluation)
result_list.append(result)

if is_chat:
from application.flow.loop_workflow_manage import LoopWorkflowManage
if isinstance(self.workflow_manage, LoopWorkflowManage):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
jsonpath_expr_cache = MemCache('parse_path', {
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'OPTIONS': {
'MAX_ENTRIES': 1000, # 最多缓存 500 个条目
'MAX_ENTRIES': 1000, # 最多缓存 1000 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
},
})
Expand Down
3 changes: 1 addition & 2 deletions apps/application/serializers/application_chat_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def is_valid(self, *, raise_exception=False):
def list(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id'))
order_by = 'create_time' if self.data.get('order_asc') is None or self.data.get(
'order_asc') else '-create_time'
return [ChatRecordSerializerModel(chat_record).data for chat_record in
Expand Down Expand Up @@ -169,7 +168,7 @@ def reset_chat_record(chat_record, show_source, show_exec):
'padding_problem_text': chat_record.details.get('problem_padding').get(
'padding_problem_text') if 'problem_padding' in chat_record.details else None,
**(show_source_dict if show_source else {}),
**(show_exec_dict if show_exec else show_exec_dict)
**(show_exec_dict if show_exec else {})
}

def page(self, current_page: int, page_size: int, with_valid=True, show_source=None, show_exec=None):
Expand Down
8 changes: 4 additions & 4 deletions apps/chat/serializers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ def get_chat_record(chat_info, chat_record_id):
str(chat_record.id) == str(chat_record_id)]
if chat_record_list is not None and len(chat_record_list):
return chat_record_list[-1]
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id, chat_id=chat_info.chat_id).first()
if chat_record is None:
if not is_valid_uuid(chat_record_id):
raise ChatException(500, _("Conversation record does not exist"))
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id, chat_id=chat_info.chat_id).first()
if chat_record is None:
if not is_valid_uuid(chat_record_id):
raise ChatException(500, _("Conversation record does not exist"))
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.

chat_info 判断不为空才执行,否则肯定会报空指针异常。

chat_record = QuerySet(ChatRecord).filter(id=chat_record_id).first()
return chat_record

Expand Down
5 changes: 2 additions & 3 deletions apps/chat/serializers/chat_embed_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def get_embed(self, with_valid=True, params=None):
if with_valid:
self.is_valid(raise_exception=True)
index_path = os.path.join(PROJECT_DIR, 'apps', "chat", 'template', 'embed.js')
file = open(index_path, "r", encoding='utf-8')
content = file.read()
file.close()
with open(index_path, "r", encoding='utf-8') as file:
content = file.read()
application_access_token = QuerySet(ApplicationAccessToken).filter(
access_token=self.data.get('token')).first()
is_draggable = 'false'
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/serializers/chat_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def vote(self, instance: Dict, with_valid=True):
chat_record_details_model.vote_status = VoteChoices.STAR
chat_record_details_model.vote_reason = vote_reason
chat_record_details_model.vote_other_content = vote_other_content

if vote_status == VoteChoices.TRAMPLE:
elif vote_status == VoteChoices.TRAMPLE:
# 点踩
chat_record_details_model.vote_status = VoteChoices.TRAMPLE
chat_record_details_model.vote_reason = vote_reason
Expand Down
81 changes: 40 additions & 41 deletions apps/common/handle/impl/common_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,46 +86,45 @@ def handle_images(deps, archive: ZipFile) -> []:


def xlsx_embed_cells_images(buffer) -> {}:
archive = ZipFile(buffer)
# 解析cellImage.xml文件
deps = get_dependents(archive, get_rels_path("xl/cellimages.xml"))
image_rel = handle_images(deps=deps, archive=archive)
# 工作表及其中图片ID
sheet_list = {}
for item in archive.namelist():
if not item.startswith('xl/worksheets/sheet'):
continue
key = item.split('/')[-1].split('.')[0].split('sheet')[-1]
sheet_list[key] = parse_element_sheet_xml(fromstring(archive.read(item)))
cell_images_xml = parse_element(fromstring(archive.read("xl/cellimages.xml")))
cell_images_rel = {}
for image in image_rel:
cell_images_rel[image.embed] = image
for cnv, embed in cell_images_xml.items():
cell_images_xml[cnv] = cell_images_rel.get(embed)
result = {}
for key, img in cell_images_xml.items():
all_cells = [
cell
for _sheet_id, sheet in sheet_list.items()
if sheet is not None
for cell in sheet or []
]
with ZipFile(buffer) as archive:
# 解析cellImage.xml文件
deps = get_dependents(archive, get_rels_path("xl/cellimages.xml"))
image_rel = handle_images(deps=deps, archive=archive)
# 工作表及其中图片ID
sheet_list = {}
for item in archive.namelist():
if not item.startswith('xl/worksheets/sheet'):
continue
key = item.split('/')[-1].split('.')[0].split('sheet')[-1]
sheet_list[key] = parse_element_sheet_xml(fromstring(archive.read(item)))
cell_images_xml = parse_element(fromstring(archive.read("xl/cellimages.xml")))
cell_images_rel = {}
for image in image_rel:
cell_images_rel[image.embed] = image
for cnv, embed in cell_images_xml.items():
cell_images_xml[cnv] = cell_images_rel.get(embed)
result = {}
for key, img in cell_images_xml.items():
all_cells = [
cell
for _sheet_id, sheet in sheet_list.items()
if sheet is not None
for cell in sheet or []
]

image_excel_id_list = [
cell for cell in all_cells
if isinstance(cell, str) and key in cell
]
# print(key, img)
if img is None:
continue
if len(image_excel_id_list) > 0:
image_excel_id = image_excel_id_list[-1]
f = archive.open(img.target)
img_byte = io.BytesIO()
im = PILImage.open(f).convert('RGB')
im.save(img_byte, format='JPEG')
image = File(id=uuid.uuid7(), file_name=img.path, meta={'debug': False, 'content': img_byte.getvalue()})
result['=' + image_excel_id] = image
archive.close()
image_excel_id_list = [
cell for cell in all_cells
if isinstance(cell, str) and key in cell
]
# print(key, img)
if img is None:
continue
if len(image_excel_id_list) > 0:
image_excel_id = image_excel_id_list[-1]
with archive.open(img.target) as f:
img_byte = io.BytesIO()
im = PILImage.open(f).convert('RGB')
im.save(img_byte, format='JPEG')
image = File(id=uuid.uuid7(), file_name=img.path, meta={'debug': False, 'content': img_byte.getvalue()})
result['=' + image_excel_id] = image
return result
14 changes: 11 additions & 3 deletions apps/common/handle/impl/text/pdf_split_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_bu
# 获取临时文件的路径
temp_file_path = temp_file.name

pdf_document = fitz.open(temp_file_path)
pdf_document = None
try:
pdf_document = fitz.open(temp_file_path)
if type(limit) is str:
limit = int(limit)
if type(with_filter) is str:
Expand Down Expand Up @@ -79,7 +80,8 @@ def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_bu
'content': []
}
finally:
pdf_document.close()
if pdf_document is not None:
pdf_document.close()
# 处理完后可以删除临时文件
os.remove(temp_file_path)

Expand Down Expand Up @@ -331,9 +333,15 @@ def get_content(self, file, save_image):
# 获取临时文件的路径
temp_file_path = temp_file.name

pdf_document = fitz.open(temp_file_path)
pdf_document = None
try:
pdf_document = fitz.open(temp_file_path)
return self.handle_pdf_content(file, pdf_document)
except BaseException as e:
traceback.print_exception(e)
return f'{e}'
finally:
if pdf_document is not None:
pdf_document.close()
# 处理完后可以删除临时文件
os.remove(temp_file_path)
4 changes: 2 additions & 2 deletions apps/common/handle/impl/text/zip_split_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def get_image_list(result_list: list, zip_files: List[str]):
if not zip_files.__contains__(image_path):
continue
if image_path.startswith('oss/file/') or image_path.startswith('oss/image/'):
image_id = image_path.replace('oss/file/', '').replace('oss/file/', '')
image_id = image_path.replace('oss/file/', '').replace('oss/image/', '')
if is_valid_uuid(image_id):
image_file_list.append({'source_file': image_path,
'image_id': image_id})
Expand Down Expand Up @@ -115,7 +115,7 @@ def get_image_list_by_content(name: str, content: str, zip_files: List[str]):
if not zip_files.__contains__(image_path):
continue
if image_path.startswith('oss/file/') or image_path.startswith('oss/image/'):
image_id = image_path.replace('oss/file/', '').replace('oss/file/', '')
image_id = image_path.replace('oss/file/', '').replace('oss/image/', '')
if is_valid_uuid(image_id):
image_file_list.append({'source_file': image_path,
'image_id': image_id})
Expand Down
11 changes: 5 additions & 6 deletions apps/knowledge/serializers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ def get_embedding_model_id_by_knowledge_id_list(knowledge_id_list: List):

def zip_dir(zip_path, output=None):
output = output or os.path.basename(zip_path) + '.zip'
zip = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(zip_path):
relative_root = '' if root == zip_path else root.replace(zip_path, '') + os.sep
for filename in files:
zip.write(os.path.join(root, filename), relative_root + filename)
zip.close()
with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as zip:
for root, dirs, files in os.walk(zip_path):
relative_root = '' if root == zip_path else root.replace(zip_path, '') + os.sep
for filename in files:
zip.write(os.path.join(root, filename), relative_root + filename)


def is_valid_uuid(s):
Expand Down
32 changes: 14 additions & 18 deletions apps/knowledge/serializers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,17 @@ def export(self, with_valid=True):
self.is_valid(raise_exception=True)
language = get_language()
if self.data.get('type') == 'csv':
file = open(
with open(
os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'csv_template_{to_locale(language)}.csv'),
"rb")
content = file.read()
file.close()
"rb") as file:
content = file.read()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename="csv_template.csv"'})
elif self.data.get('type') == 'excel':
file = open(os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'excel_template_{to_locale(language)}.xlsx'), "rb")
content = file.read()
file.close()
with open(os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'excel_template_{to_locale(language)}.xlsx'), "rb") as file:
content = file.read()
return HttpResponse(content, status=200, headers={'Content-Type': 'application/vnd.ms-excel',
'Content-Disposition': 'attachment; filename="excel_template.xlsx"'})
else:
Expand All @@ -251,20 +249,18 @@ def table_export(self, with_valid=True):
self.is_valid(raise_exception=True)
language = get_language()
if self.data.get('type') == 'csv':
file = open(
with open(
os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'table_template_{to_locale(language)}.csv'),
"rb")
content = file.read()
file.close()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/cxv',
"rb") as file:
content = file.read()
return HttpResponse(content, status=200, headers={'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename="csv_template.csv"'})
elif self.data.get('type') == 'excel':
file = open(os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'table_template_{to_locale(language)}.xlsx'),
"rb")
content = file.read()
file.close()
with open(os.path.join(PROJECT_DIR, "apps", "knowledge", 'template',
f'table_template_{to_locale(language)}.xlsx'),
"rb") as file:
content = file.read()
return HttpResponse(content, status=200, headers={'Content-Type': 'application/vnd.ms-excel',
'Content-Disposition': 'attachment; filename="excel_template.xlsx"'})
else:
Expand Down
1 change: 0 additions & 1 deletion apps/knowledge/serializers/paragraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def edit(self, instance: Dict):
return self.one(), instance, self.data.get('knowledge_id')

def get_problem_list(self):
ProblemParagraphMapping(ProblemParagraphMapping)
problem_paragraph_mapping = QuerySet(ProblemParagraphMapping).filter(
paragraph_id=self.data.get("paragraph_id"))
if len(problem_paragraph_mapping) > 0:
Expand Down
5 changes: 2 additions & 3 deletions apps/maxkb/urls/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def pro():


def get_index_html(index_path):
file = open(index_path, "r", encoding='utf-8')
content = file.read()
file.close()
with open(index_path, "r", encoding='utf-8') as file:
content = file.read()
return content


Expand Down
Loading
Loading