Skip to content

Commit b08a2f4

Browse files
perf: Optimize code style
1 parent 36502be commit b08a2f4

11 files changed

Lines changed: 38 additions & 41 deletions

File tree

apps/application/flow/step_node/search_knowledge_node/impl/base_search_knowledge_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727

2828
def get_embedding_id(dataset_id_list):
2929
dataset_list = QuerySet(Knowledge).filter(id__in=dataset_id_list)
30+
if not dataset_list:
31+
raise Exception("知识库设置错误,请重新设置知识库")
3032
if len(set([dataset.embedding_model_id for dataset in dataset_list])) > 1:
3133
raise Exception("关联知识库的向量模型不一致,无法召回分段。")
32-
if len(dataset_list) == 0:
33-
raise Exception("知识库设置错误,请重新设置知识库")
3434
return dataset_list[0].embedding_model_id
3535

3636

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def valid_reference_value(_type, value, name):
8585

8686

8787
def convert_value(name: str, value, _type, is_required, source, node):
88-
if not is_required and (value is None or ((isinstance(value, str) or isinstance(value, list)) and len(value) == 0)):
88+
if not is_required and (value is None or (isinstance(value, (str, list)) and len(value) == 0)):
8989
return None
9090
if source == 'reference':
9191
value = node.workflow_manage.get_reference_field(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def valid_reference_value(_type, value, name):
6161

6262

6363
def convert_value(name: str, value, _type, is_required, source, node):
64-
if not is_required and (value is None or ((isinstance(value, str) or isinstance(value, list)) and len(value) == 0)):
64+
if not is_required and (value is None or (isinstance(value, (str, list)) and len(value) == 0)):
6565
return None
6666
if source == 'reference':
6767
value = node.workflow_manage.get_reference_field(

apps/application/flow/step_node/video_understand_step_node/impl/base_video_understand_node.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,8 @@ def generate_history_ai_message(self, chat_record):
211211
def generate_history_human_message_for_details(self, chat_record):
212212
for data in chat_record.details.values():
213213
if self.node.id == data['node_id'] and 'video_list' in data:
214-
video_list = data['video_list'] or []
215-
# 增加对 None 和空列表的检查
216-
if not video_list or len(video_list) == 0 or data['dialogue_type'] == 'WORKFLOW':
214+
video_list = data['video_list'] or []
215+
if not video_list or data['dialogue_type'] == 'WORKFLOW':
217216
return HumanMessage(content=chat_record.problem_text)
218217
file_id_list = []
219218
url_list = []
@@ -242,8 +241,8 @@ def generate_history_human_message(self, chat_record, video_model):
242241

243242
for data in chat_record.details.values():
244243
if self.node.id == data['node_id'] and 'video_list' in data:
245-
video_list = data['video_list'] or []
246-
if video_list is None or len(video_list) == 0 or data['dialogue_type'] == 'WORKFLOW':
244+
video_list = data['video_list'] or []
245+
if not video_list or data['dialogue_type'] == 'WORKFLOW':
247246
return HumanMessage(content=chat_record.problem_text)
248247
file_id_list = []
249248
url_list = []

apps/application/serializers/application_chat_record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def reset_chat_record(chat_record, show_source, show_exec):
170170
'padding_problem_text': chat_record.details.get('problem_padding').get(
171171
'padding_problem_text') if 'problem_padding' in chat_record.details else None,
172172
**(show_source_dict if show_source else {}),
173-
**(show_exec_dict if show_exec else show_exec_dict)
173+
**show_exec_dict
174174
}
175175

176176
def page(self, current_page: int, page_size: int, with_valid=True, show_source=None, show_exec=None):

apps/chat/mcp/tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def _get_chat_id(self):
6464
}).open()
6565

6666
def call_tool(self, params):
67-
name = params["name"]
6867
args = params.get("arguments", {})
69-
# print(params)
7068

7169
payload = {
7270
'message': args.get('message'),

apps/chat/serializers/chat.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ def get_chat_record(chat_info, chat_record_id):
385385
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id, chat_id=chat_info.chat_id).first()
386386
if chat_record is None:
387387
raise ChatException(500, _("Conversation record does not exist"))
388-
389388
return chat_record
390389
chat_record = QuerySet(ChatRecord).filter(id=chat_record_id).first()
391390
return chat_record

apps/models_provider/impl/xinference_model_provider/model/reranker.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
from models_provider.base_model_provider import MaxKBBaseModel
1616

17+
RESTfulClient = None
18+
try:
19+
from xinference.client import RESTfulClient
20+
except ImportError:
21+
try:
22+
from xinference_client import RESTfulClient
23+
except ImportError as e:
24+
pass
1725

1826
class XInferenceReranker(MaxKBBaseModel, BaseDocumentCompressor):
1927
server_url: Optional[str]
@@ -31,21 +39,14 @@ def new_instance(model_type, model_name, model_credential: Dict[str, object], **
3139

3240
def compress_documents(self, documents: Sequence[Document], query: str, callbacks: Optional[Callbacks] = None) -> \
3341
Sequence[Document]:
34-
if documents is None or len(documents) == 0:
42+
if not documents:
3543
return []
36-
client: Any
37-
if documents is None or len(documents) == 0:
38-
return []
39-
try:
40-
from xinference.client import RESTfulClient
41-
except ImportError:
42-
try:
43-
from xinference_client import RESTfulClient
44-
except ImportError as e:
45-
raise ImportError(
46-
"Could not import RESTfulClient from xinference. Please install it"
47-
" with `pip install xinference` or `pip install xinference_client`."
48-
) from e
44+
45+
if RESTfulClient is None:
46+
raise ImportError(
47+
"Could not import RESTfulClient from xinference. Please install it"
48+
" with `pip install xinference` or `pip install xinference_client`."
49+
) from e
4950

5051
client = RESTfulClient(self.server_url, self.api_key)
5152
model: RESTfulRerankModelHandle = client.get_model(self.model_uid)

ui/src/locales/lang/en-US/workflow.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ export default {
215215
systemDefault: `#Role
216216
You are a master of problem optimization, adept at accurately inferring user intentions based on context and optimizing the questions raised by users.
217217
218-
##Skills
219-
###Skill 1: Optimizing Problems
220-
2. Receive user input questions.
221-
3. Carefully analyze the meaning of the problem based on the context.
222-
4. Output optimized problems.
218+
## Skills
219+
### Skill 1: Optimizing Problems
220+
1. Receive user input questions.
221+
2. Carefully analyze the meaning of the problem based on the context.
222+
3. Output optimized problems.
223223
224-
##Limitations:
225-
-Only return the optimized problem without any additional explanation or clarification.
226-
-Ensure that the optimized problem accurately reflects the original problem intent and does not alter the original intention.`,
224+
## Limitations:
225+
- Only return the optimized problem without any additional explanation or clarification.
226+
- Ensure that the optimized problem accurately reflects the original problem intent and does not alter the original intention.`,
227227
},
228228
conditionNode: {
229229
label: 'Conditional Branch',

ui/src/locales/lang/zh-CN/workflow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ export default {
217217
218218
## 技能
219219
### 技能 1: 优化问题
220-
2. 接收用户输入的问题。
221-
3. 依据上下文仔细分析问题含义。
222-
4. 输出优化后的问题。
220+
1. 接收用户输入的问题。
221+
2. 依据上下文仔细分析问题含义。
222+
3. 输出优化后的问题。
223223
224224
## 限制:
225225
- 仅返回优化后的问题,不进行额外解释或说明。

0 commit comments

Comments
 (0)