feat: 工作流开始节点添加上下文,会话id参数 #1094
This commit is contained in:
parent
3e3b77e34d
commit
f07f5ae804
@ -16,9 +16,6 @@ from application.flow.i_step_node import INode, NodeResult
|
||||
class IStarNode(INode):
|
||||
type = 'start-node'
|
||||
|
||||
def get_node_params_serializer_class(self) -> Type[serializers.Serializer] | None:
|
||||
return None
|
||||
|
||||
def _run(self):
|
||||
return self.execute(**self.flow_params_serializer.data)
|
||||
|
||||
|
||||
@ -15,11 +15,16 @@ from application.flow.step_node.start_node.i_start_node import IStarNode
|
||||
|
||||
class BaseStartStepNode(IStarNode):
|
||||
def execute(self, question, **kwargs) -> NodeResult:
|
||||
history_chat_record = self.flow_params_serializer.data.get('history_chat_record', [])
|
||||
history_context = [{'question': chat_record.problem_text, 'answer': chat_record.answer_text} for chat_record in
|
||||
history_chat_record]
|
||||
chat_id = self.flow_params_serializer.data.get('chat_id')
|
||||
"""
|
||||
开始节点 初始化全局变量
|
||||
"""
|
||||
return NodeResult({'question': question},
|
||||
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time()})
|
||||
{'time': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'start_time': time.time(),
|
||||
'history_context': history_context, 'chat_id': str(chat_id)})
|
||||
|
||||
def get_details(self, index: int, **kwargs):
|
||||
global_fields = []
|
||||
|
||||
@ -2,25 +2,18 @@
|
||||
<NodeContainer :nodeModel="nodeModel">
|
||||
<h5 class="title-decoration-1 mb-8">全局变量</h5>
|
||||
<div
|
||||
v-for="item in nodeModel.properties.config.globalFields"
|
||||
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
|
||||
@mouseenter="showicon = true"
|
||||
@mouseleave="showicon = false"
|
||||
>
|
||||
<span>当前时间 {time}</span>
|
||||
<span>{{ item.label }} {{ '{' + item.value + '}' }}</span>
|
||||
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
|
||||
<el-button link @click="copyClick(globeLabel)" style="padding: 0">
|
||||
<AppIcon iconName="app-copy"></AppIcon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<div v-for="(item, index) in inputFieldList" :key="index"
|
||||
class="flex-between border-r-4 p-8-12 mb-8 layout-bg lighter"
|
||||
@mouseenter="showicon = true"
|
||||
@mouseleave="showicon = false"
|
||||
>
|
||||
<span>{{ item.name }} {{ '{' + item.variable + '}' }}</span>
|
||||
<el-tooltip effect="dark" content="复制参数" placement="top" v-if="showicon === true">
|
||||
<el-button link @click="copyClick('{{' + '全局变量.' + item.variable + '}}')" style="padding: 0">
|
||||
<el-button
|
||||
link
|
||||
@click="copyClick('{{' + '全局变量.' + item.value + '}}')"
|
||||
style="padding: 0"
|
||||
>
|
||||
<AppIcon iconName="app-copy"></AppIcon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
@ -28,42 +21,36 @@
|
||||
</NodeContainer>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { set } from 'lodash'
|
||||
import { cloneDeep, set } from 'lodash'
|
||||
import NodeContainer from '@/workflow/common/NodeContainer.vue'
|
||||
import { copyClick } from '@/utils/clipboard'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
|
||||
const props = defineProps<{ nodeModel: any }>()
|
||||
|
||||
const globeLabel = '{{全局变量.time}}'
|
||||
|
||||
const showicon = ref(false)
|
||||
|
||||
const globalFields = [
|
||||
{ label: '当前时间', value: 'time' },
|
||||
{ label: '历史聊天记录', value: 'history_context' },
|
||||
{ label: '对话id', value: 'chat_id' }
|
||||
]
|
||||
const inputFieldList = ref<any[]>([])
|
||||
|
||||
function handleRefreshFieldList(data: any[]) {
|
||||
props.nodeModel.graphModel.nodes
|
||||
const getRefreshFieldList = () => {
|
||||
return props.nodeModel.graphModel.nodes
|
||||
.filter((v: any) => v.id === 'base-node')
|
||||
.map((v: any) => {
|
||||
// eslint-disable-next-line vue/no-mutating-props
|
||||
props.nodeModel.properties.config.globalFields = [
|
||||
{
|
||||
label: '当前时间',
|
||||
value: 'time'
|
||||
}, ...v.properties.input_field_list.map((i: any) => {
|
||||
return { label: i.name, value: i.variable }
|
||||
})
|
||||
]
|
||||
inputFieldList.value = v.properties.input_field_list
|
||||
})
|
||||
.map((v: any) => cloneDeep(v.properties.input_field_list))
|
||||
.reduce((x: any, y: any) => [...x, ...y], [])
|
||||
.map((i: any) => ({ label: i.name, value: i.variable }))
|
||||
}
|
||||
|
||||
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', (data: any) => {
|
||||
handleRefreshFieldList(data)
|
||||
})
|
||||
const refreshFieldList = () => {
|
||||
const refreshFieldList = getRefreshFieldList()
|
||||
set(props.nodeModel.properties.config, 'globalFields', [...globalFields, ...refreshFieldList])
|
||||
}
|
||||
props.nodeModel.graphModel.eventCenter.on('refreshFieldList', refreshFieldList)
|
||||
|
||||
onMounted(() => {
|
||||
handleRefreshFieldList([])
|
||||
refreshFieldList()
|
||||
})
|
||||
</script>
|
||||
<style lang="scss" scoped></style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user