Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@
@desc:
"""
import json
from jsonpath_ng import parse
from jsonpath_ng.ext import parse
from common.cache.mem_cache import MemCache

from application.flow.i_step_node import NodeResult
from application.flow.step_node.variable_splitting_node.i_variable_splitting_node import IVariableSplittingNode

jsonpath_expr_cache = MemCache('parse_path', {
'TIMEOUT': 3600, # 缓存有效期为 1 小时
'OPTIONS': {
'MAX_ENTRIES': 1000, # 最多缓存 500 个条目
'CULL_FREQUENCY': 10, # 达到上限时,删除约 1/10 的缓存
},
})

def parse_and_cache(path):
jsonpath_expr = jsonpath_expr_cache.get(path)
if not jsonpath_expr:
jsonpath_expr = parse(path)
jsonpath_expr_cache.set(path, jsonpath_expr)
return jsonpath_expr

def smart_jsonpath_search(data: dict, path: str):
"""
Expand All @@ -21,7 +36,7 @@ def smart_jsonpath_search(data: dict, path: str):
- 多个匹配: 返回值的列表
- 无匹配: 返回None
"""
jsonpath_expr = parse(path)
jsonpath_expr = parse_and_cache(path)
matches = jsonpath_expr.find(data)

if not matches:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies = [
"websockets==15.0.1",
"pylint==3.3.7",
"cohere==5.17.0",
"jsonpath-ng==1.7.0",
"jsonpath-ng==1.8.0",
]

[tool.uv]
Expand Down
2 changes: 1 addition & 1 deletion ui/src/locales/lang/en-US/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ You are a master of problem optimization, adept at accurately inferring user int
expression: {
label: 'Expression',
placeholder: 'Please enter expression',
tooltip: 'Please use JSON Path expressions to split variables, e.g.: $.store.book',
tooltip: 'Please use JSON Path expressions to split variables, e.g.: $.store.book <a href="https://pypi.org/project/jsonpath-ng/1.8.0/" target="_blank" class="expression_tip">Click for details ➜ pypi.org</a>',
},
},
parameterExtractionNode: {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/locales/lang/zh-CN/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export default {
expression: {
label: '表达式',
placeholder: '请输入表达式',
tooltip: '请使用JSON Path 表达式拆分变量,例如:$.store.book',
tooltip: '请使用 JSON Path 表达式拆分变量,例如:$.store.book <a href="https://pypi.org/project/jsonpath-ng/1.8.0/" target="_blank" class="expression_tip">点击查看详情 ➜ pypi.org</a>',
},
},
parameterExtractionNode: {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/locales/lang/zh-Hant/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export default {
expression: {
label: '表達式',
placeholder: '請輸入表達式',
tooltip: '請使用 JSON Path 表達式拆分變量,例如:$.store.book',
tooltip: '請使用 JSON Path 表達式拆分變量,例如:$.store.book <a href="https://pypi.org/project/jsonpath-ng/1.8.0/" target="_blank" class="expression_tip">點擊查看詳情 ➜ pypi.org</a>',
},
},
parameterExtractionNode: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@
>
<el-tooltip
effect="dark"
:content="
$t('workflow.nodes.variableSplittingNode.expression.tooltip')
"
placement="right"
>
<template #content>
<span v-html="$t('workflow.nodes.variableSplittingNode.expression.tooltip')"></span>
</template>
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
</el-tooltip>
</div>
Expand Down Expand Up @@ -161,4 +161,12 @@ const submit = async (formEl: FormInstance | undefined) => {

defineExpose({ open, close })
</script>
<style lang="scss" scoped></style>
<style lang="scss">
.expression_tip {
color: var(--el-color-primary-light-5);

&:hover {
color: var(--el-color-primary-light-3);
}
}
</style>
Loading