Skip to content

Commit f07f5ae

Browse files
committed
feat: 工作流开始节点添加上下文,会话id参数 #1094
1 parent 3e3b77e commit f07f5ae

File tree

3 files changed

+30
-41
lines changed

3 files changed

+30
-41
lines changed

apps/application/flow/step_node/start_node/i_start_node.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
class IStarNode(INode):
1717
type = 'start-node'
1818

19-
def get_node_params_serializer_class(self) -> Type[serializers.Serializer] | None:
20-
return None
21-
2219
def _run(self):
2320
return self.execute(**self.flow_params_serializer.data)
2421

apps/application/flow/step_node/start_node/impl/base_start_node.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515

1616
class BaseStartStepNode(IStarNode):
1717
def execute(self, question, **kwargs) -> NodeResult:
18+
history_chat_record = self.flow_params_serializer.data.get('history_chat_record', [])
19+
history_context = [{'question': chat_record.problem_text, 'answer': chat_record.answer_text} for chat_record in
20+
history_chat_record]
21+
chat_id = self.flow_params_serializer.data.get('chat_id')
1822
"""
1923
开始节点 初始化全局变量
2024
"""
2125
return NodeResult({'question': question},
22-
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time()})
26+
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
27+
'history_context': history_context, 'chat_id': str(chat_id)})
2328

2429
def get_details(self, index: int, **kwargs):
2530
global_fields = []

ui/src/workflow/nodes/start-node/index.vue

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,55 @@
22
<NodeContainer :nodeModel="nodeModel">
33
<h5 class="title-decoration-1 mb-8">全局变量</h5>
44
<div
5+
v-for="item in nodeModel.properties.config.globalFields"
56
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
67
@mouseenter="showicon = true"
78
@mouseleave="showicon = false"
89
>
9-
<span>当前时间 {time}</span>
10+
<span>{{ item.label }} {{ '{' + item.value + '}' }}</span>
1011
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
11-
<el-button link @click="copyClick(globeLabel)" style="padding: 0">
12-
<AppIcon iconName="app-copy"></AppIcon>
13-
</el-button>
14-
</el-tooltip>
15-
</div>
16-
<div v-for="(item, index) in inputFieldList" :key="index"
17-
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
18-
@mouseenter="showicon = true"
19-
@mouseleave="showicon = false"
20-
>
21-
<span>{{ item.name }} {{ '{' + item.variable + '}' }}</span>
22-
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
23-
<el-button link @click="copyClick('{{' + '全局变量.' + item.variable + '}}')" style="padding: 0">
12+
<el-button
13+
link
14+
@click="copyClick('{{' + '全局变量.' + item.value + '}}')"
15+
style="padding: 0"
16+
>
2417
<AppIcon iconName="app-copy"></AppIcon>
2518
</el-button>
2619
</el-tooltip>
2720
</div>
2821
</NodeContainer>
2922
</template>
3023
<script setup lang="ts">
31-
import { set } from 'lodash'
24+
import { cloneDeep, set } from 'lodash'
3225
import NodeContainer from '@/workflow/common/NodeContainer.vue'
3326
import { copyClick } from '@/utils/clipboard'
3427
import { ref, computed, onMounted } from 'vue'
3528
3629
const props = defineProps<{ nodeModel: any }>()
3730
38-
const globeLabel = '{{全局变量.time}}'
39-
4031
const showicon = ref(false)
41-
32+
const globalFields = [
33+
{ label: '当前时间', value: 'time' },
34+
{ label: '历史聊天记录', value: 'history_context' },
35+
{ label: '对话id', value: 'chat_id' }
36+
]
4237
const inputFieldList = ref<any[]>([])
4338
44-
function handleRefreshFieldList(data: any[]) {
45-
props.nodeModel.graphModel.nodes
39+
const getRefreshFieldList = () => {
40+
return props.nodeModel.graphModel.nodes
4641
.filter((v: any) => v.id === 'base-node')
47-
.map((v: any) => {
48-
// eslint-disable-next-line vue/no-mutating-props
49-
props.nodeModel.properties.config.globalFields = [
50-
{
51-
label: '当前时间',
52-
value: 'time'
53-
}, ...v.properties.input_field_list.map((i: any) => {
54-
return { label: i.name, value: i.variable }
55-
})
56-
]
57-
inputFieldList.value = v.properties.input_field_list
58-
})
42+
.map((v: any) => cloneDeep(v.properties.input_field_list))
43+
.reduce((x: any, y: any) => [...x, ...y], [])
44+
.map((i: any) => ({ label: i.name, value: i.variable }))
5945
}
60-
61-
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', (data: any) => {
62-
handleRefreshFieldList(data)
63-
})
46+
const refreshFieldList = () => {
47+
const refreshFieldList = getRefreshFieldList()
48+
set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList])
49+
}
50+
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', refreshFieldList)
6451
6552
onMounted(() => {
66-
handleRefreshFieldList([])
53+
refreshFieldList()
6754
})
6855
</script>
6956
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)