Skip to content
Draft
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 @@ -38,6 +38,37 @@ def out_evaluation(self, variable, value):
else:
self.workflow_manage.out_context[variable['fields'][1]] = value

def convert(self, val, target_type):
if not target_type or val is None:
return val

if target_type == 'json_object':
if isinstance(val, dict) or isinstance(val, list):
return val
return json.loads(val)
elif target_type == 'json_string':
if isinstance(val, str):
return val
return json.dumps(val, ensure_ascii=False)
elif target_type == 'string':
if isinstance(val, str):
return val
return str(val)
elif target_type == 'int':
if isinstance(val, int):
return val
return int(val)
elif target_type == 'float':
if isinstance(val, float):
return val
return float(val)
elif target_type == 'boolean':
if isinstance(val, bool):
return val
return bool(val)
else:
return val

def handle(self, variable, evaluation):
result = {
'name': variable['name'],
Expand All @@ -49,44 +80,56 @@ def handle(self, variable, evaluation):
val = variable['value']
else:
val = json.loads(variable['value'])
val = self.convert(val, variable.get('target_type'))
evaluation(variable, val)
result['output_value'] = variable['value'] = val
elif variable['type'] == 'string':
# 变量解析 例如:{{global.xxx}}
val = self.workflow_manage.generate_prompt(variable['value'])
val = self.convert(val, variable.get('target_type'))
evaluation(variable, val)
result['output_value'] = val
else:
val = variable['value']
val = self.convert(val, variable.get('target_type'))
evaluation(variable, val)
result['output_value'] = val
elif variable['source'] == 'null':
val = None
evaluation(variable, val)
result['output_value'] = val
else:
reference = self.get_reference_content(variable['reference'])
reference = self.convert(reference, variable.get('target_type'))
evaluation(variable, reference)
result['output_value'] = reference

result['input_type'] = type(result.get('input_value')).__name__ if result.get('input_value') is not None else 'null'
result['output_type'] = type(result.get('output_value')).__name__ if result.get('output_value') is not None else 'null'
return result

def execute(self, variable_list, **kwargs) -> NodeResult:
#
result_list = []
is_chat = False
contains_chat_variable = False
for variable in variable_list:
if 'fields' not in variable:
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]:
contains_chat_variable = True
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:

if contains_chat_variable:
from application.flow.loop_workflow_manage import LoopWorkflowManage
if isinstance(self.workflow_manage, LoopWorkflowManage):
self.workflow_manage.parentWorkflowManage.get_chat_info().set_chat_variable(
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/execution-detail-card/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@
</h5>
<div class="p-8-12 border-t-dashed lighter">
<div v-for="(f, i) in data.result_list" :key="i" class="mb-8">
<span class="color-secondary">{{ f.name }}:</span> {{ f.input_value }}
<span class="color-secondary">{{ f.name }} ({{ f.input_type }}):</span> {{ f.input_value }}
</div>
</div>
</div>
Expand All @@ -892,7 +892,7 @@
</h5>
<div class="p-8-12 border-t-dashed lighter">
<div v-for="(f, i) in data.result_list" :key="i" class="mb-8">
<span class="color-secondary">{{ f.name }}:</span> {{ f.output_value }}
<span class="color-secondary">{{ f.name }} ({{ f.output_type }}):</span> {{ f.output_value }}
</div>
</div>
</div>
Expand Down
20 changes: 11 additions & 9 deletions ui/src/locales/lang/en-US/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ export default {
label: 'Question Optimization',
text: 'Optimize and improve the current question based on historical chat records to better match knowledge segments',
result: 'Optimized Question Result',
systemDefault: `#Role
systemDefault: `# Role
You are a master of problem optimization, adept at accurately inferring user intentions based on context and optimizing the questions raised by users.

##Skills
###Skill 1: Optimizing Problems
2. Receive user input questions.
3. Carefully analyze the meaning of the problem based on the context.
4. Output optimized problems.
## Skills
### Skill 1: Optimizing Problems
1. Receive user input questions.
2. Carefully analyze the meaning of the problem based on the context.
3. Output optimized problems.

##Limitations:
-Only return the optimized problem without any additional explanation or clarification.
-Ensure that the optimized problem accurately reflects the original problem intent and does not alter the original intention.`,
## Limitations:
- Only return the optimized problem without any additional explanation or clarification.
- Ensure that the optimized problem accurately reflects the original problem intent and does not alter the original intention.`,
},
conditionNode: {
label: 'Conditional Branch',
Expand Down Expand Up @@ -318,6 +318,8 @@ You are a master of problem optimization, adept at accurately inferring user int
label: 'Variable Assign',
text: 'Update the value of the global variable',
assign: 'Set Value',
convertType: 'Convert type',
doNotConvert: 'Do not convert',
},
variableAggregationNode: {
label: 'Variable Aggregation',
Expand Down
8 changes: 5 additions & 3 deletions ui/src/locales/lang/zh-CN/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export default {

## 技能
### 技能 1: 优化问题
2. 接收用户输入的问题。
3. 依据上下文仔细分析问题含义。
4. 输出优化后的问题。
1. 接收用户输入的问题。
2. 依据上下文仔细分析问题含义。
3. 输出优化后的问题。

## 限制:
- 仅返回优化后的问题,不进行额外解释或说明。
Expand Down Expand Up @@ -318,6 +318,8 @@ export default {
label: '变量赋值',
text: '更新全局变量的值',
assign: '赋值',
convertType: '转换类型',
doNotConvert: '不转换',
},
mcpNode: {
label: 'MCP 调用',
Expand Down
8 changes: 5 additions & 3 deletions ui/src/locales/lang/zh-Hant/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ export default {

## 技能
### 技能 1: 優化問題
2. 接收用戶輸入的問題。
3. 依據上下文仔細分析問題含義。
4. 輸出優化後的問題。
1. 接收用戶輸入的問題。
2. 依據上下文仔細分析問題含義。
3. 輸出優化後的問題。

## 限制:
- 僅返回優化後的問題,不進行額外解釋或說明。
Expand Down Expand Up @@ -317,6 +317,8 @@ export default {
label: '變數賦值',
text: '更新全域變數的值',
assign: '賦值',
convertType: '轉換類型',
doNotConvert: '不轉換',
},
variableAggregationNode: {
label: '變量聚合',
Expand Down
8 changes: 7 additions & 1 deletion ui/src/workflow/nodes/variable-assign-node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ class VariableAssignNode extends AppNode {
}
}

class VariableAssignModel extends AppNodeModel {
get_width() {
return 450
}
}

export default {
type: 'variable-assign-node',
model: AppNodeModel,
model: VariableAssignModel,
view: VariableAssignNode
}
35 changes: 29 additions & 6 deletions ui/src/workflow/nodes/variable-assign-node/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<el-select :teleported="false" v-model="item.source" size="small" style="width: 85px">
<el-option :label="$t('workflow.variable.Referencing')" value="referencing" />
<el-option :label="$t('common.custom')" value="custom" />
<el-option label="null" value="null" />
</el-select>
</div>

Expand All @@ -67,6 +68,7 @@
</el-select>

<el-form-item
class="w-full"
v-if="item.type === 'string'"
:prop="'variable_list.' + index + '.value'"
:rules="{
Expand All @@ -76,6 +78,7 @@
}"
>
<el-input
class="w-full"
v-model="item.value"
:placeholder="$t('common.inputPlaceholder')"
show-word-limit
Expand Down Expand Up @@ -120,10 +123,8 @@
<CodemirrorEditor
title="JSON"
v-model="item.value"
:style="{
height: '100px',
width: '155px',
}"
class="w-full"
style="height: 100px"
@submitDialog="(val: string) => (form_data.variable_list[index].value = val)"
/>
</el-form-item>
Expand All @@ -141,15 +142,28 @@
<el-option label="false" :value="false" />
</el-select>
</el-form-item>

<el-select
v-if="item.type === 'string'"
v-model="item.target_type"
style="max-width: 120px; margin-left: 8px"
:placeholder="$t('workflow.nodes.variableAssignNode.convertType')"
>
<el-option v-for="item2 in targetTypeOptions" :key="item2.key" :label="item2.label" :value="item2.key" />
</el-select>
</div>
<el-form-item v-else>
<el-form-item v-else-if="item.source === 'referencing'">
<NodeCascader
ref="nodeCascaderRef2"
:nodeModel="nodeModel"
class="w-full"
style="width: 230px"
:placeholder="$t('workflow.variable.placeholder')"
v-model="item.reference"
/>

<el-select v-model="item.target_type" style="max-width: 120px; margin-left: 8px" :placeholder="$t('workflow.nodes.variableAssignNode.convertType')">
<el-option v-for="item2 in targetTypeOptions" :key="item2.key" :label="item2.label" :value="item2.key" />
</el-select>
</el-form-item>
</el-card>
</template>
Expand All @@ -174,6 +188,15 @@ const workflowMode = inject('workflowMode') as WorkflowMode
const props = defineProps<{ nodeModel: any }>()

const typeOptions = ['string', 'num', 'json', 'bool']
const targetTypeOptions = [
{ label: t('workflow.nodes.variableAssignNode.doNotConvert'), key: '' },
{ label: 'string', key: 'string' },
{ label: 'int', key: 'int' },
{ label: 'float', key: 'float' },
{ label: 'json_object', key: 'json_object' },
{ label: 'json_string', key: 'json_string' },
{ label: 'boolean', key: 'boolean' },
]

const wheel = (e: any) => {
if (e.ctrlKey === true) {
Expand Down
Loading